chiark / gitweb /
Add the lib elevate stuff (even though it's only used by the old
[jarrg-ian.git] / lib / elevate.vbs
diff --git a/lib/elevate.vbs b/lib/elevate.vbs
new file mode 100644 (file)
index 0000000..5b3d3cb
--- /dev/null
@@ -0,0 +1,93 @@
+' //***************************************************************************\r
+' // ***** Script Header *****\r
+' // =======================================================\r
+' // Elevation PowerToys for Windows Vista v1.1 (04/29/2008)\r
+' // =======================================================\r
+' //\r
+' // File:      Elevate.vbs\r
+' //\r
+' // Additional files required:  Elevate.cmd\r
+' //\r
+' // Purpose:   To provide a command line method of launching applications that\r
+' //            prompt for elevation (Run as Administrator) on Windows Vista.\r
+' //\r
+' // Usage:     (Not used directly.  Launched from Elevate.cmd.)\r
+' //\r
+' // Version:   1.0.1\r
+' // Date :     01/03/2007\r
+' //\r
+' // History:\r
+' // 1.0.0   01/02/2007  Created initial version.\r
+' // 1.0.1   01/03/2007  Added detailed usage output.\r
+' //\r
+' // ***** End Header *****\r
+' //***************************************************************************\r
+\r
+\r
+Set objShell = CreateObject("Shell.Application")\r
+Set objWshShell = WScript.CreateObject("WScript.Shell")\r
+Set objWshProcessEnv = objWshShell.Environment("PROCESS")\r
+\r
+' Get raw command line agruments and first argument from Elevate.cmd passed\r
+' in through environment variables.\r
+strCommandLine = objWshProcessEnv("ELEVATE_CMDLINE")\r
+strApplication = objWshProcessEnv("ELEVATE_APP")\r
+strArguments = Right(strCommandLine, (Len(strCommandLine) - Len(strApplication)))\r
+\r
+If (WScript.Arguments.Count >= 1) Then\r
+    strFlag = WScript.Arguments(0)\r
+    If (strFlag = "") OR (strFlag="help") OR (strFlag="/h") OR (strFlag="\h") OR (strFlag="-h") _\r
+        OR (strFlag = "\?") OR (strFlag = "/?") OR (strFlag = "-?") OR (strFlag="h") _\r
+        OR (strFlag = "?") Then\r
+        DisplayUsage\r
+        WScript.Quit\r
+    Else\r
+        objShell.ShellExecute strApplication, strArguments, "", "runas"\r
+    End If\r
+Else\r
+    DisplayUsage\r
+    WScript.Quit\r
+End If\r
+\r
+\r
+Sub DisplayUsage\r
+\r
+    WScript.Echo "Elevate - Elevation Command Line Tool for Windows Vista" & vbCrLf & _\r
+                 "" & vbCrLf & _\r
+                 "Purpose:" & vbCrLf & _\r
+                 "--------" & vbCrLf & _\r
+                 "To launch applications that prompt for elevation (i.e. Run as Administrator)" & vbCrLf & _\r
+                 "from the command line, a script, or the Run box." & vbCrLf & _\r
+                 "" & vbCrLf & _\r
+                 "Usage:   " & vbCrLf & _\r
+                 "" & vbCrLf & _\r
+                 "    elevate application <arguments>" & vbCrLf & _\r
+                 "" & vbCrLf & _\r
+                 "" & vbCrLf & _\r
+                 "Sample usage:" & vbCrLf & _\r
+                 "" & vbCrLf & _\r
+                 "    elevate notepad ""C:\Windows\win.ini""" & vbCrLf & _\r
+                 "" & vbCrLf & _\r
+                 "    elevate cmd /k cd ""C:\Program Files""" & vbCrLf & _\r
+                 "" & vbCrLf & _\r
+                 "    elevate powershell -NoExit -Command Set-Location 'C:\Windows'" & vbCrLf & _\r
+                 "" & vbCrLf & _\r
+                 "" & vbCrLf & _\r
+                 "Usage with scripts: When using the elevate command with scripts such as" & vbCrLf & _\r
+                 "Windows Script Host or Windows PowerShell scripts, you should specify" & vbCrLf & _\r
+                 "the script host executable (i.e., wscript, cscript, powershell) as the " & vbCrLf & _\r
+                 "application." & vbCrLf & _\r
+                 "" & vbCrLf & _\r
+                 "Sample usage with scripts:" & vbCrLf & _\r
+                 "" & vbCrLf & _\r
+                 "    elevate wscript ""C:\windows\system32\slmgr.vbs"" \96dli" & vbCrLf & _\r
+                 "" & vbCrLf & _\r
+                 "    elevate powershell -NoExit -Command & 'C:\Temp\Test.ps1'" & vbCrLf & _\r
+                 "" & vbCrLf & _\r
+                 "" & vbCrLf & _\r
+                 "The elevate command consists of the following files:" & vbCrLf & _\r
+                 "" & vbCrLf & _\r
+                 "    elevate.cmd" & vbCrLf & _\r
+                 "    elevate.vbs" & vbCrLf\r
+\r
+End Sub\r