changeset 438:df33b9cc7d39

'runas' does not supported under Windows XP. Check for Vista and upper.
author Oleksandr Gavenko <gavenkoa@gmail.com>
date Mon, 31 Oct 2011 13:16:39 +0200
parents f2ca93785a54
children 0c662ec813e2
files admin/win/reg/Makefile admin/win/reg/uac.js
diffstat 2 files changed, 32 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/admin/win/reg/Makefile	Mon Oct 31 03:09:40 2011 +0200
+++ b/admin/win/reg/Makefile	Mon Oct 31 13:16:39 2011 +0200
@@ -31,13 +31,7 @@
   fi; \
   echo 'pause'; \
 } >regimport.bat; \
-{ \
-  echo 'var fso = new ActiveXObject("Scripting.FileSystemObject");'; \
-  echo 'var curdir = fso.GetParentFolderName(WScript.ScriptFullName);'; \
-  echo 'var objShell = new ActiveXObject("shell.application");'; \
-  echo 'objShell.ShellExecute("regimport.bat", curdir, "", "runas", 1);'; \
-} >runas.js; \
-cscript runas.js;
+cscript uac.js;
 	rm -f regimport.bat runas.js emacs.tmp.reg;
 endif
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/admin/win/reg/uac.js	Mon Oct 31 13:16:39 2011 +0200
@@ -0,0 +1,31 @@
+// To run invoke: cscript uac.js
+
+var batch = "regimport.bat"
+
+var fso = new ActiveXObject("Scripting.FileSystemObject");
+var curdir = fso.GetParentFolderName(WScript.ScriptFullName);
+
+var wbemFlagReturnImmediately = 0x10;
+var wbemFlagForwardOnly = 0x20;
+var objWMIService = GetObject("winmgmts:\\\\.\\root\\CIMV2");
+// var objWMIService = GetObject("winmgmts:" + "{impersonationLevel=impersonate}!\\" + "." + "\root\cimv2");
+var colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL",
+                                      wbemFlagReturnImmediately | wbemFlagForwardOnly);
+var enumItems = new Enumerator(colItems);
+var objItem = enumItems.item();
+// http://en.wikipedia.org/wiki/Ver_(command)
+var major_ver = objItem.Version.split(".")[0];
+
+var objShell = new ActiveXObject("shell.application");
+// http://msdn.microsoft.com/en-us/library/windows/desktop/gg537745.aspx
+//                 Shell.ShellExecute method
+// iRetVal = Shell.ShellExecute( sFile, [ vArguments ], [ vDirectory ], [ vOperation ], [ vShow ] )
+// If (vShow==1) open the application with a normal window.
+// Check for Vista and upper.
+if (major_ver >= 6) {
+    // Request admin permission.
+    objShell.ShellExecute(batch, curdir, "", "runas", 1);
+} else {
+    objShell.ShellExecute(batch, curdir);
+}
+