Index: tmp/org.txm.rcp/src/main/java/org/txm/rcp/p2/plugins/TXMUpdateHandler.java
===================================================================
--- tmp/org.txm.rcp/src/main/java/org/txm/rcp/p2/plugins/TXMUpdateHandler.java	(revision 2814)
+++ tmp/org.txm.rcp/src/main/java/org/txm/rcp/p2/plugins/TXMUpdateHandler.java	(revision 2815)
@@ -47,21 +47,26 @@
 import org.txm.rcp.messages.TXMUIMessages;
 import org.txm.rcp.preferences.RCPPreferences;
 import org.txm.utils.BundleUtils;
+import org.txm.utils.OSDetector;
 import org.txm.utils.logger.Log;
 import org.txm.utils.zip.GZip;
 
 public class TXMUpdateHandler extends UpdateHandler {
-	
+
 	// public static final String UPDATESITE = "http://textometrie.ens-lyon.fr/dist"; //
 	// "file:"+System.getProperty("user.home")+"/TEMP/updates"; // LOCAL TEST ONLY
 	public static final String ID = "org.txm.rcp.p2.plugins.TXMUpdateHandler";
-	
+
 	/**
 	 * Execute the command.
 	 */
 	@Override
 	public Object execute(ExecutionEvent event) {
-		
+
+		if (OSDetector.isFamilyWindows() && !isWindowsAdministratorUser()) {
+			Log.warning("Aborting update. you need to run TXM as administrator to do updates");
+		}
+
 		String key = event.getParameter("org.txm.rcp.parameters.update"); //$NON-NLS-1$
 		if ("true".equals(key)) {
 			String path = BundleUtils.getInstallDirectory();
@@ -80,35 +85,35 @@
 				}
 			}
 		}
-		
+
 		// Hacking p2 profile to be able to update installation directory even if -configuration is set
 		try {
 			ProvisioningUI pui = ProvisioningUI.getDefaultUI();
-			
+
 			String profileId = pui.getProfileId();
 			IProvisioningAgent agent = pui.getSession().getProvisioningAgent();
-			
+
 			if (agent != null) {
 				IProfileRegistry profileRegistry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
-				
-				
+
+
 				if (profileRegistry != null && profileRegistry instanceof SimpleProfileRegistry) {
-					
+
 					SimpleProfileRegistry spr = (SimpleProfileRegistry) profileRegistry;
-					
+
 					IProfile iprofile = profileRegistry.getProfile(profileId);
 					if (iprofile != null && iprofile instanceof Profile) {
 						Profile profile = (Profile) iprofile;
-						
+
 						spr.lockProfile(profile);
-						
+
 						// System.out.println("Profile: "+profile.getClass()+" = "+profile);
 						Iterator<IInstallableUnit> everything = profile.everything();
 						boolean changed = false;
 						while (everything.hasNext()) {
 							IInstallableUnit iu = everything.next();
 							String locked = profile.getInstallableUnitProperty(iu, IProfile.PROP_PROFILE_LOCKED_IU);
-							
+
 							if (locked != null && !("0".equals(locked))) {
 								profile.setInstallableUnitProperty(iu, IProfile.PROP_PROFILE_LOCKED_IU, "0");
 								changed = true;
@@ -117,12 +122,12 @@
 						if (changed) {
 							spr.updateProfile(profile);
 						}
-						
+
 						spr.unlockProfile(profile);
 					}
 				}
 			}
-			
+
 			// this is the default repository
 			URL baseURL = new URL(TBXPreferences.getInstance().getString(TBXPreferences.UPDATESITE) + "/index.html");
 			try {
@@ -133,17 +138,17 @@
 				Log.severe("Update site is not reachable: " + baseURL + ", aborting.");
 				return false;
 			}
-			
+
 			addDefaultUpdateSites(agent);
 			addDefaultPluginSites(agent);
-			
+
 			// add alpha and beta repos if needed
 			// from bundle org.eclipse.equinox.p2.console
-			
+
 			Log.info("Looking for TXM updates...");
 			Object ret = super.execute(event);
 			Log.info("Done.");
-			
+
 			return ret;
 		}
 		catch (Exception e) {
@@ -152,7 +157,38 @@
 		}
 		return null;
 	}
-	
+
+	private boolean isWindowsAdministratorUser() {
+		String path = BundleUtils.getInstallDirectory();// System.getProperty("osgi.instance.area");
+		if (!path.startsWith("C:/Program files/TXM")) {
+			return true; // TXM was not installed in program files no need to test admin user
+		}
+
+		return isAdminCommandTest();
+	}
+
+	public static  boolean isAdminCommandTest() {
+		StringBuilder outputbuilder = new StringBuilder();
+		try {
+			ProcessBuilder builder = new ProcessBuilder(
+					"cmd.exe","/c" ,"net user");
+			builder.redirectErrorStream(true);
+			Process p = builder.start();
+			BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
+			String line;
+			while (true) {
+				line = r.readLine();
+				if (line == null) { break; }
+				outputbuilder.append(line);
+			}
+		} catch (IOException e) {
+			e.printStackTrace();
+			return false;
+		}
+		System.out.println(outputbuilder.toString());
+		return outputbuilder.toString().contains("Administrator");
+	}
+
 	/**
 	 * Return a shell appropriate for parenting dialogs of this handler.
 	 * 
@@ -163,7 +199,7 @@
 		// System.out.println("MY GETSHELL: "+Display.getCurrent().getActiveShell());
 		return new Shell();
 	}
-	
+
 	public static boolean patchGZProfile() {
 		// TODO: is this still useful with TXM 0.7.7 -> yes&no : need to patch when --configuration is set, done by editing the Profile object directly
 		String path = BundleUtils.getInstallDirectory();// System.getProperty("osgi.instance.area");
@@ -175,20 +211,20 @@
 			Log.severe(NLS.bind(TXMUIMessages.switchLanguageColonMalformedUrlColonP0, location));
 			return false;
 		}
-		
+
 		File txmConfigDir = new File(location.getFile());
 		// File txmConfigDir = new File("/home/mdecorde/.txm"); // test only
 		File profileDir = new File(txmConfigDir, "p2/org.eclipse.equinox.p2.engine/profileRegistry/profile.profile");
-		
+
 		Log.fine("Looking for profile in : " + txmConfigDir);
 		// System.out.println(txmConfigDir);
 		// System.out.println(profileDir);
-		
+
 		if (!profileDir.exists()) {
 			Log.severe("p2 profile directory does not exists: " + profileDir);
 			return false;
 		}
-		
+
 		// 1- find profile.gz
 		File gzFile = findNewestGZFile(profileDir);
 		if (gzFile == null) {
@@ -206,10 +242,10 @@
 					Log.severe("Could not delete old profile GZfile: " + gzFile);
 					return false;
 				}
-				
+
 				// File lockFile = new File(profileDir, ".lock");
 				// System.out.println("Delete .lock file: "+lockFile+" "+lockFile.delete());
-				
+
 				// 5- compress new profile
 				GZip.compress(profileXMLFile, gzFile);
 				// 6- clean files
@@ -227,7 +263,7 @@
 			}
 		}
 	}
-	
+
 	public static void addDefaultUpdateSites(IProvisioningAgent agent) {
 		Version v = Activator.getDefault().getBundle().getVersion();
 		String version = "" + v.getMajor() + "." + v.getMinor() + "." + v.getMicro();
@@ -243,7 +279,7 @@
 			Log.severe("Could not add update default repository: " + uriDefault);
 			Log.printStackTrace(e);
 		}
-		
+
 		String updateLevel = RCPPreferences.getInstance().getString(RCPPreferences.UPDATE_LEVEL);
 		boolean alphaMode = false;
 		boolean betaMode = false;
@@ -258,7 +294,7 @@
 			betaMode = true;
 		}
 		Log.fine("Update levels: dev=" + devMode + " alpha=" + alphaMode + " beta=" + betaMode);
-		
+
 		String uriDev = uriBase + "/dev";//$NON-NLS-1$
 		try {
 			URI repoUriDev = new URI(uriDev);
@@ -273,7 +309,7 @@
 			Log.severe("Could not add update DEV repository: " + uriDev);
 			e.printStackTrace();
 		}
-		
+
 		String uriAlpha = uriBase + "/alpha";//$NON-NLS-1$
 		try {
 			URI repoUriAlpha = new URI(uriAlpha);
@@ -288,7 +324,7 @@
 			Log.severe("Could not add update ALPHA repository: " + uriAlpha);
 			e.printStackTrace();
 		}
-		
+
 		String uriBeta = uriBase + "/beta";//$NON-NLS-1$
 		try {
 			URI repoUriBeta = new URI(uriBeta);
@@ -303,12 +339,12 @@
 			Log.severe("Can not add update BETA repository: " + uriBeta);
 		}
 	}
-	
+
 	public static void addDefaultPluginSites(IProvisioningAgent agent) {
 		Version v = Activator.getDefault().getBundle().getVersion();
 		String version = "" + v.getMajor() + "." + v.getMinor() + "." + v.getMicro();
 		String uriBase = TBXPreferences.getInstance().getString(TBXPreferences.UPDATESITE) + "/" + version + "/ext";
-		
+
 		String uriDefault = uriBase + "/stable";
 		try {
 			URI repoUriDefault = new URI(uriDefault);
@@ -320,7 +356,7 @@
 			Log.severe("Could not add update default repository: " + uriDefault);
 			Log.printStackTrace(e);
 		}
-		
+
 		String updateLevel = RCPPreferences.getInstance().getString(RCPPreferences.UPDATE_LEVEL);
 		boolean alphaMode = false;
 		boolean betaMode = false;
@@ -335,7 +371,7 @@
 			betaMode = true;
 		}
 		Log.fine("Update levels: dev=" + devMode + " alpha=" + alphaMode + " beta=" + betaMode);
-		
+
 		String uriDev = uriBase + "/dev";//$NON-NLS-1$
 		try {
 			URI repoUriDev = new URI(uriDev);
@@ -350,7 +386,7 @@
 			Log.severe("Could not add update DEV repository: " + uriDev);
 			e.printStackTrace();
 		}
-		
+
 		String uriAlpha = uriBase + "/alpha";//$NON-NLS-1$
 		try {
 			URI repoUriAlpha = new URI(uriAlpha);
@@ -365,7 +401,7 @@
 			Log.severe("Could not add update ALPHA repository: " + uriAlpha);
 			e.printStackTrace();
 		}
-		
+
 		String uriBeta = uriBase + "/beta";//$NON-NLS-1$
 		try {
 			URI repoUriBeta = new URI(uriBeta);
@@ -379,13 +415,13 @@
 		catch (Exception e) {
 			Log.severe("Can not add update BETA repository: " + uriBeta);
 		}
-		
+
 	}
-	
+
 	public static boolean addURL(IProvisioningAgent agent, URI location) {
 		IMetadataRepositoryManager manager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
 		IArtifactRepositoryManager manager2 = (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME);
-		
+
 		if (manager == null) {
 			System.out.println("No metadata repository manager found");
 			return false;
@@ -394,9 +430,9 @@
 			System.out.println("No artifact repository manager found");
 			return false;
 		}
-		
+
 		Log.fine("Adding update site URL: " + location + "...");
-		
+
 		try {
 			// manager.removeRepository(location)
 			manager.loadRepository(location, null);
@@ -414,7 +450,7 @@
 				return false;
 			}
 		}
-		
+
 		try {
 			// manager.removeRepository(location)
 			manager2.loadRepository(location, null);
@@ -435,11 +471,11 @@
 			}
 		}
 	}
-	
+
 	public static boolean removeURL(IProvisioningAgent agent, URI location) {
 		IMetadataRepositoryManager manager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
 		IArtifactRepositoryManager manager2 = (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME);
-		
+
 		if (manager == null) {
 			Log.severe("No metadata repository manager found");
 			return false;
@@ -448,27 +484,27 @@
 			Log.severe("No artifact repository manager found");
 			return false;
 		}
-		
+
 		manager.removeRepository(location);
 		manager2.removeRepository(location);
-		
+
 		return true;
 	}
-	
+
 	private static void patchProfile(File profileXMLFile) throws IOException {
-		
+
 		File tmpFile = File.createTempFile("tmp", ".profile", profileXMLFile.getParentFile());
-		
+
 		BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(profileXMLFile), "UTF-8"));
 		BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tmpFile), "UTF-8"));
-		
+
 		String line = br.readLine();
 		boolean firstLine = true;
 		while (line != null) {
 			if (!firstLine) {
 				writer.write("\n");
 			}
-			
+
 			String trimedLine = line.trim();
 			if (trimedLine.startsWith("<property name='org.eclipse.equinox.p2.type.lock' value='")) {
 				writer.write("<property name='org.eclipse.equinox.p2.type.lock' value='0'/>");
@@ -481,27 +517,27 @@
 		}
 		writer.close();
 		br.close();
-		
+
 		if (!(profileXMLFile.delete() && tmpFile.renameTo(profileXMLFile))) {
 			throw new IOException("failed to rewrite profile file: " + profileXMLFile);
 		}
 	}
-	
+
 	private static File findNewestGZFile(File profileDir) {
 		File[] files = profileDir.listFiles(new FilenameFilter() {
-			
+
 			@Override
 			public boolean accept(File dir, String name) {
 				return name.toLowerCase().endsWith(".gz");
 			}
 		});
-		
+
 		if (files == null || files.length == 0) return null;
-		
+
 		Arrays.sort(files);
 		return files[files.length - 1];
 	}
-	
+
 	// COPY FROM UpdateHandler class
 	// boolean hasNoRepos = false;
 	// UpdateOperation operation;
@@ -607,7 +643,7 @@
 	// protected String getProgressTaskName() {
 	// return ProvSDKMessages.UpdateHandler_ProgressTaskName;
 	// }
-	
-	
-	
+
+
+
 }
