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 2815)
+++ tmp/org.txm.rcp/src/main/java/org/txm/rcp/p2/plugins/TXMUpdateHandler.java	(revision 2816)
@@ -9,12 +9,15 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.io.OutputStream;
 import java.io.OutputStreamWriter;
+import java.io.PrintStream;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URL;
 import java.util.Arrays;
 import java.util.Iterator;
+import java.util.prefs.Preferences;
 
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.runtime.Assert;
@@ -51,9 +54,13 @@
 import org.txm.utils.logger.Log;
 import org.txm.utils.zip.GZip;
 
+import static java.lang.System.setErr;
+import static java.util.prefs.Preferences.systemRoot;
+
 public class TXMUpdateHandler extends UpdateHandler {
 
-	// public static final String UPDATESITE = "http://textometrie.ens-lyon.fr/dist"; //
+	// 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";
 
@@ -75,18 +82,20 @@
 					File installDirectory = new File(path);
 					Log.fine("Testing install directory rights: " + installDirectory);
 					if (!installDirectory.canWrite() || !installDirectory.canExecute()) {
-						Log.warning(NLS.bind("Warning: you need administrator privileges to fully update TXM (installed in {0}). Some updates might not be fully installed.", installDirectory));
+						Log.warning(NLS.bind(
+								"Warning: you need administrator privileges to fully update TXM (installed in {0}). Some updates might not be fully installed.",
+								installDirectory));
 						return null;
 					}
-				}
-				catch (Exception e) {
+				} catch (Exception e) {
 					// TODO Auto-generated catch block
 					e.printStackTrace();
 				}
 			}
 		}
 
-		// Hacking p2 profile to be able to update installation directory even if -configuration is set
+		// Hacking p2 profile to be able to update installation directory even if
+		// -configuration is set
 		try {
 			ProvisioningUI pui = ProvisioningUI.getDefaultUI();
 
@@ -96,7 +105,6 @@
 			if (agent != null) {
 				IProfileRegistry profileRegistry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
 
-
 				if (profileRegistry != null && profileRegistry instanceof SimpleProfileRegistry) {
 
 					SimpleProfileRegistry spr = (SimpleProfileRegistry) profileRegistry;
@@ -133,8 +141,7 @@
 			try {
 				InputStream s = baseURL.openStream();
 				s.close();
-			}
-			catch (Exception e) {
+			} catch (Exception e) {
 				Log.severe("Update site is not reachable: " + baseURL + ", aborting.");
 				return false;
 			}
@@ -150,8 +157,7 @@
 			Log.info("Done.");
 
 			return ret;
-		}
-		catch (Exception e) {
+		} catch (Exception e) {
 			Log.severe("Could not update TXM: " + e + ".");
 			Log.printStackTrace(e);
 		}
@@ -164,31 +170,36 @@
 			return true; // TXM was not installed in program files no need to test admin user
 		}
 
-		return isAdminCommandTest();
+		return isWindowsAdminCommandTest();
 	}
 
-	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");
-	}
+	private static boolean isWindowsAdminCommandTest()
+    {
+        Preferences preferences = systemRoot();
 
+        synchronized (System.err)
+        {
+            setErr(new PrintStream(new OutputStream() {
+				@Override
+				public void write(int b) throws IOException { }
+			}));
+
+            try
+            {
+                preferences.put("foo", "bar"); // SecurityException on Windows
+                preferences.remove("foo");
+                preferences.flush(); // BackingStoreException on Linux
+                return true;
+            } catch (Exception exception)
+            {
+                return false;
+            } finally
+            {
+                setErr(System.err);
+            }
+        }
+    }
+
 	/**
 	 * Return a shell appropriate for parenting dialogs of this handler.
 	 * 
@@ -201,13 +212,13 @@
 	}
 
 	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
+		// 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");
 		URL location = null;
 		try {
 			location = new URL(path);
-		}
-		catch (MalformedURLException e) {
+		} catch (MalformedURLException e) {
 			Log.severe(NLS.bind(TXMUIMessages.switchLanguageColonMalformedUrlColonP0, location));
 			return false;
 		}
@@ -230,8 +241,7 @@
 		if (gzFile == null) {
 			Log.severe("No profile GZ file found");
 			return false;
-		}
-		else {
+		} else {
 			try {
 				// 2- extract profile from gz profile
 				File profileXMLFile = GZip.uncompress(gzFile, profileDir);
@@ -255,8 +265,7 @@
 				}
 				Log.fine("Profile archive patched: " + gzFile);
 				return true;
-			}
-			catch (IOException e) {
+			} catch (IOException e) {
 				Log.severe("Failed to fix profile file: " + e);
 				Log.printStackTrace(e);
 				return false;
@@ -274,8 +283,7 @@
 			addURL(agent, repoUriDefault);
 			// URI repoKepler = new URI("http://download.eclipse.org/releases/kepler");
 			// addURL(agent, repoKepler);
-		}
-		catch (Exception e) {
+		} catch (Exception e) {
 			Log.severe("Could not add update default repository: " + uriDefault);
 			Log.printStackTrace(e);
 		}
@@ -286,11 +294,9 @@
 		boolean devMode = false;
 		if ("DEV".equals(updateLevel)) {//$NON-NLS-1$
 			devMode = alphaMode = betaMode = true;
-		}
-		else if ("ALPHA".equals(updateLevel)) {//$NON-NLS-1$
+		} else if ("ALPHA".equals(updateLevel)) {//$NON-NLS-1$
 			alphaMode = betaMode = true;
-		}
-		else if ("BETA".equals(updateLevel)) {//$NON-NLS-1$
+		} else if ("BETA".equals(updateLevel)) {//$NON-NLS-1$
 			betaMode = true;
 		}
 		Log.fine("Update levels: dev=" + devMode + " alpha=" + alphaMode + " beta=" + betaMode);
@@ -300,12 +306,10 @@
 			URI repoUriDev = new URI(uriDev);
 			if (devMode) {
 				addURL(agent, repoUriDev);
-			}
-			else {
+			} else {
 				removeURL(agent, repoUriDev);
 			}
-		}
-		catch (Exception e) {
+		} catch (Exception e) {
 			Log.severe("Could not add update DEV repository: " + uriDev);
 			e.printStackTrace();
 		}
@@ -315,12 +319,10 @@
 			URI repoUriAlpha = new URI(uriAlpha);
 			if (alphaMode) {
 				addURL(agent, repoUriAlpha);
-			}
-			else {
+			} else {
 				removeURL(agent, repoUriAlpha);
 			}
-		}
-		catch (Exception e) {
+		} catch (Exception e) {
 			Log.severe("Could not add update ALPHA repository: " + uriAlpha);
 			e.printStackTrace();
 		}
@@ -330,12 +332,10 @@
 			URI repoUriBeta = new URI(uriBeta);
 			if (betaMode) {
 				addURL(agent, repoUriBeta);
-			}
-			else {
+			} else {
 				removeURL(agent, repoUriBeta);
 			}
-		}
-		catch (Exception e) {
+		} catch (Exception e) {
 			Log.severe("Can not add update BETA repository: " + uriBeta);
 		}
 	}
@@ -351,8 +351,7 @@
 			addURL(agent, repoUriDefault);
 			// URI repoKepler = new URI("http://download.eclipse.org/releases/kepler");
 			// addURL(agent, repoKepler);
-		}
-		catch (Exception e) {
+		} catch (Exception e) {
 			Log.severe("Could not add update default repository: " + uriDefault);
 			Log.printStackTrace(e);
 		}
@@ -363,11 +362,9 @@
 		boolean devMode = false;
 		if ("DEV".equals(updateLevel)) {//$NON-NLS-1$
 			devMode = alphaMode = betaMode = true;
-		}
-		else if ("ALPHA".equals(updateLevel)) {//$NON-NLS-1$
+		} else if ("ALPHA".equals(updateLevel)) {//$NON-NLS-1$
 			alphaMode = betaMode = true;
-		}
-		else if ("BETA".equals(updateLevel)) {//$NON-NLS-1$
+		} else if ("BETA".equals(updateLevel)) {//$NON-NLS-1$
 			betaMode = true;
 		}
 		Log.fine("Update levels: dev=" + devMode + " alpha=" + alphaMode + " beta=" + betaMode);
@@ -377,12 +374,10 @@
 			URI repoUriDev = new URI(uriDev);
 			if (devMode) {
 				addURL(agent, repoUriDev);
-			}
-			else {
+			} else {
 				removeURL(agent, repoUriDev);
 			}
-		}
-		catch (Exception e) {
+		} catch (Exception e) {
 			Log.severe("Could not add update DEV repository: " + uriDev);
 			e.printStackTrace();
 		}
@@ -392,12 +387,10 @@
 			URI repoUriAlpha = new URI(uriAlpha);
 			if (alphaMode) {
 				addURL(agent, repoUriAlpha);
-			}
-			else {
+			} else {
 				removeURL(agent, repoUriAlpha);
 			}
-		}
-		catch (Exception e) {
+		} catch (Exception e) {
 			Log.severe("Could not add update ALPHA repository: " + uriAlpha);
 			e.printStackTrace();
 		}
@@ -407,20 +400,20 @@
 			URI repoUriBeta = new URI(uriBeta);
 			if (betaMode) {
 				addURL(agent, repoUriBeta);
-			}
-			else {
+			} else {
 				removeURL(agent, repoUriBeta);
 			}
-		}
-		catch (Exception e) {
+		} 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);
+		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");
@@ -436,15 +429,14 @@
 		try {
 			// manager.removeRepository(location)
 			manager.loadRepository(location, null);
-		}
-		catch (Exception e) {
+		} catch (Exception e) {
 			Log.severe("No repo - create a newmetadata repo");
 			// for convenience create and add a repository here
 			String repositoryName = location + " - metadata";
 			try {
-				manager.createRepository(location, repositoryName, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null);
-			}
-			catch (ProvisionException e2) {
+				manager.createRepository(location, repositoryName, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY,
+						null);
+			} catch (ProvisionException e2) {
 				Log.severe("Error while adding metadata repo: " + location);
 				Log.printStackTrace(e);
 				return false;
@@ -455,16 +447,15 @@
 			// manager.removeRepository(location)
 			manager2.loadRepository(location, null);
 			return true;
-		}
-		catch (Exception e) {
+		} catch (Exception e) {
 			// could not load a repo at that location so create one as a convenience
 			String repositoryName = location + " - artifacts";
 			try {
 				Log.severe("No repo - create a new artifact repo");
-				manager.createRepository(location, repositoryName, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null);
+				manager.createRepository(location, repositoryName, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY,
+						null);
 				return true;
-			}
-			catch (Exception e2) {
+			} catch (Exception e2) {
 				Log.severe("Error while adding artifact repo: " + location);
 				Log.printStackTrace(e);
 				return false;
@@ -473,8 +464,10 @@
 	}
 
 	public static boolean removeURL(IProvisioningAgent agent, URI location) {
-		IMetadataRepositoryManager manager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME);
-		IArtifactRepositoryManager manager2 = (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME);
+		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");
@@ -508,8 +501,7 @@
 			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'/>");
-			}
-			else {
+			} else {
 				writer.write(line);
 			}
 			firstLine = false;
@@ -532,7 +524,8 @@
 			}
 		});
 
-		if (files == null || files.length == 0) return null;
+		if (files == null || files.length == 0)
+			return null;
 
 		Arrays.sort(files);
 		return files[files.length - 1];
@@ -559,12 +552,17 @@
 	//// getProvisioningUI().openUpdateWizard(false, operation, job);
 	//// } else {
 	////
-	//// final RemediationOperation remediationOperation = new RemediationOperation(getProvisioningUI().getSession(), operation.getProfileChangeRequest(),
+	//// final RemediationOperation remediationOperation = new
+	// RemediationOperation(getProvisioningUI().getSession(),
+	// operation.getProfileChangeRequest(),
 	// RemedyConfig.getCheckForUpdateRemedyConfigs());
-	//// ProvisioningJob job2 = new ProvisioningJob(ProvSDKMessages.RemediationOperation_ResolveJobName, getProvisioningUI().getSession()) {
+	//// ProvisioningJob job2 = new
+	// ProvisioningJob(ProvSDKMessages.RemediationOperation_ResolveJobName,
+	// getProvisioningUI().getSession()) {
 	//// @Override
 	//// public IStatus runModal(IProgressMonitor monitor) {
-	//// monitor.beginTask(ProvSDKMessages.RemediationOperation_ResolveJobTask, RemedyConfig.getAllRemedyConfigs().length);
+	//// monitor.beginTask(ProvSDKMessages.RemediationOperation_ResolveJobTask,
+	// RemedyConfig.getAllRemedyConfigs().length);
 	//// return remediationOperation.resolveModal(monitor);
 	//// }
 	//// };
@@ -573,7 +571,8 @@
 	//// if (PlatformUI.isWorkbenchRunning()) {
 	//// PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
 	//// public void run() {
-	//// getProvisioningUI().openUpdateWizard(true, operation, remediationOperation, null);
+	//// getProvisioningUI().openUpdateWizard(true, operation, remediationOperation,
+	// null);
 	//// }
 	//// });
 	//// }
@@ -586,16 +585,21 @@
 	// }
 	//
 	// /**
-	// * Answer a boolean indicating whether the caller should continue to work with the
-	// * specified operation. This method is used when an operation has been resolved, but
+	// * Answer a boolean indicating whether the caller should continue to work with
+	// the
+	// * specified operation. This method is used when an operation has been
+	// resolved, but
 	// * the UI may have further restrictions on continuing with it.
 	// *
 	// * @param operation the operation in question. It must already be resolved.
 	// * @param shell the shell to use for any interaction with the user
-	// * @return <code>true</code> if processing of the operation should continue, <code>false</code> if
-	// * not. It is up to the implementor to report any errors to the user when answering <code>false</code>.
+	// * @return <code>true</code> if processing of the operation should continue,
+	// <code>false</code> if
+	// * not. It is up to the implementor to report any errors to the user when
+	// answering <code>false</code>.
 	// */
-	// public boolean continueWorkingWithOperation(ProfileChangeOperation operation, Shell shell) {
+	// public boolean continueWorkingWithOperation(ProfileChangeOperation operation,
+	// Shell shell) {
 	// //System.out.println("Test if any update available");
 	// Assert.isTrue(operation.getResolutionResult() != null);
 	// IStatus status = operation.getResolutionResult();
@@ -612,7 +616,8 @@
 	//
 	// // there is no plan, so we can't continue. Report any reason found
 	// if (operation.getProvisioningPlan() == null && !status.isOK()) {
-	// StatusManager.getManager().handle(status, StatusManager.LOG | StatusManager.SHOW);
+	// StatusManager.getManager().handle(status, StatusManager.LOG |
+	// StatusManager.SHOW);
 	//
 	// return false;
 	// }
@@ -621,7 +626,8 @@
 	// return true;
 	// }
 	//
-	// protected void doPostLoadBackgroundWork(IProgressMonitor monitor) throws OperationCanceledException {
+	// protected void doPostLoadBackgroundWork(IProgressMonitor monitor) throws
+	// OperationCanceledException {
 	// operation = getProvisioningUI().getUpdateOperation(null, null);
 	// // check for updates
 	// IStatus resolveStatus = operation.resolveModal(monitor);
@@ -632,7 +638,8 @@
 	// protected boolean preloadRepositories() {
 	// hasNoRepos = false;
 	// RepositoryTracker repoMan = getProvisioningUI().getRepositoryTracker();
-	// if (repoMan.getKnownRepositories(getProvisioningUI().getSession()).length == 0) {
+	// if (repoMan.getKnownRepositories(getProvisioningUI().getSession()).length ==
+	// 0) {
 	// hasNoRepos = true;
 	// return false;
 	// }
@@ -644,6 +651,4 @@
 	// return ProvSDKMessages.UpdateHandler_ProgressTaskName;
 	// }
 
-
-
 }
