changeset 452:5cf2a46e4205

Initial support for WinXP.
author Oleksandr Gavenko <gavenkoa@gmail.com>
date Fri, 04 Nov 2011 18:05:44 +0200
parents 43932e6d0d46
children b5bf6f5caa7e
files win/uac/fixuac.bat win/uac/fixuac.js
diffstat 2 files changed, 47 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/win/uac/fixuac.bat	Fri Nov 04 10:41:55 2011 +0200
+++ b/win/uac/fixuac.bat	Fri Nov 04 18:05:44 2011 +0200
@@ -1,6 +1,29 @@
-cd "%*"
+@echo off
+
+for /f "tokens=2 delims=[]" %%v in ('ver') do set version=%%v
+REM Don't put spaces between '&' and '%%i'. These spaces take account in assignment.
+for /f "tokens=2,3,4 delims=. " %%v in ('echo %version%') do set major=%%v& set minor=%%w& set build=%%x
+
+REM echo version: x%version%x
+REM echo major: x%major%x
+REM echo minor: x%minor%x
+REM echo build: x%build%x
 
-takeown /r /f "%*"
-icacls "%*" /grant:r *S-1-1-0:(f) /t /c
+if "%major%"=="5" goto win2k
+if "%major%"=="6" goto win7
+echo Unknown major Windows version: %major%.
+exit 1
+goto EOF
 
-pause
+:win2k
+  REM /T recursive
+  cacls "%*" /T /G *S-1-1-0:F;T /Y
+  pause
+  goto EOF
+
+:win2k
+  takeown /r /f "%*"
+  icacls "%*" /grant:r *S-1-1-0:(f) /t /c
+  pause
+  goto EOF
+
--- a/win/uac/fixuac.js	Fri Nov 04 10:41:55 2011 +0200
+++ b/win/uac/fixuac.js	Fri Nov 04 18:05:44 2011 +0200
@@ -1,13 +1,31 @@
 // To run invoke: cscript uac.js
 
-// http://sites.google.com/site/eneerge/home/BatchGotAdmin
+var batch = "fixuac.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.
-objShell.ShellExecute("fixuac.bat", curdir, "", "runas", 1);
+// Check for Vista and upper.
+if (major_ver >= 6) {
+    // Request admin permission.
+    objShell.ShellExecute(batch, curdir, "", "runas", 1);
+} else {
+    objShell.ShellExecute(batch, curdir);
+}
+