Advertisement
Guest User

Elevate Vista/7

a guest
May 12th, 2010
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.75 KB | None | 0 0
  1. ' //***************************************************************************
  2. ' // ***** Script Header *****
  3. ' //
  4. ' // File:      Elevate.vbs
  5. ' //
  6. ' // Additional files required:  Elevate.cmd
  7. ' //
  8. ' // Purpose:   To provide a command line method of launching applications that
  9. ' //            prompt for elevation (Run as Administrator) on Windows Vista.
  10. ' //
  11. ' // Usage:     (Not used directly.  Launched from Elevate.cmd.)
  12. ' //
  13. ' // Version:   1.0.1
  14. ' // Date :     01/03/2007
  15. ' //
  16. ' // History:
  17. ' // 1.0.0   01/02/2007  Created initial version.
  18. ' // 1.0.1   01/03/2007  Added detailed usage output.
  19. ' //
  20. ' // ***** End Header *****
  21. ' //***************************************************************************
  22.  
  23.  
  24. Set objShell = CreateObject("Shell.Application")
  25. Set objWshShell = WScript.CreateObject("WScript.Shell")
  26. Set objWshProcessEnv = objWshShell.Environment("PROCESS")
  27.  
  28. ' Get raw command line agruments and first argument from Elevate.cmd passed
  29. ' in through environment variables.
  30. strCommandLine = objWshProcessEnv("ELEVATE_CMDLINE")
  31. strApplication = objWshProcessEnv("ELEVATE_APP")
  32. strArguments = Right(strCommandLine, (Len(strCommandLine) - Len(strApplication)))
  33.  
  34. If (WScript.Arguments.Count >= 1) Then
  35.     strFlag = WScript.Arguments(0)
  36.     If (strFlag = "") OR (strFlag="help") OR (strFlag="/h") OR (strFlag="\h") OR (strFlag="-h") _
  37.         OR (strFlag = "\?") OR (strFlag = "/?") OR (strFlag = "-?") OR (strFlag="h") _
  38.         OR (strFlag = "?") Then
  39.         DisplayUsage
  40.         WScript.Quit
  41.     Else
  42.         objShell.ShellExecute strApplication, strArguments, "", "runas"
  43.     End If
  44. Else
  45.     DisplayUsage
  46.     WScript.Quit
  47. End If
  48.  
  49.  
  50. Sub DisplayUsage
  51.  
  52.     WScript.Echo "Elevate - Elevation Command Line Tool for Windows Vista" & vbCrLf & _
  53.                  "" & vbCrLf & _
  54.                  "Purpose:" & vbCrLf & _
  55.                  "--------" & vbCrLf & _
  56.                  "To launch applications that prompt for elevation (i.e. Run as Administrator)" & vbCrLf & _
  57.                  "from the command line, a script, or the Run box." & vbCrLf & _
  58.                  "" & vbCrLf & _
  59.                  "Usage:   " & vbCrLf & _
  60.                  "" & vbCrLf & _
  61.                  "    elevate application <arguments>" & vbCrLf & _
  62.                  "" & vbCrLf & _
  63.                  "" & vbCrLf & _
  64.                  "Sample usage:" & vbCrLf & _
  65.                  "" & vbCrLf & _
  66.                  "    elevate notepad ""C:\Windows\win.ini""" & vbCrLf & _
  67.                  "" & vbCrLf & _
  68.                  "    elevate cmd /k cd ""C:\Program Files""" & vbCrLf & _
  69.                  "" & vbCrLf & _
  70.                  "    elevate powershell -NoExit -Command Set-Location 'C:\Windows'" & vbCrLf & _
  71.                  "" & vbCrLf & _
  72.                  "" & vbCrLf & _
  73.                  "Usage with scripts: When using the elevate command with scripts such as" & vbCrLf & _
  74.                  "Windows Script Host or Windows PowerShell scripts, you should specify" & vbCrLf & _
  75.                  "the script host executable (i.e., wscript, cscript, powershell) as the " & vbCrLf & _
  76.                  "application." & vbCrLf & _
  77.                  "" & vbCrLf & _
  78.                  "Sample usage with scripts:" & vbCrLf & _
  79.                  "" & vbCrLf & _
  80.                  "    elevate wscript ""C:\windows\system32\slmgr.vbs"" –dli" & vbCrLf & _
  81.                  "" & vbCrLf & _
  82.                  "    elevate powershell -NoExit -Command & 'C:\Temp\Test.ps1'" & vbCrLf & _
  83.                  "" & vbCrLf & _
  84.                  "" & vbCrLf & _
  85.                  "The elevate command consists of the following files:" & vbCrLf & _
  86.                  "" & vbCrLf & _
  87.                  "    elevate.cmd" & vbCrLf & _
  88.                  "    elevate.vbs" & vbCrLf
  89.  
  90. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement