title: Script for running a batch file as Administrator without prompting for password
body: <p>The below script works on Windows XP as expected. The script abc.bat would run as Administrator without a prompt for password(password is supplied automatically). But the same script is not working on our Windows 7 Box. Are there any changes required? I have no experience with VB Scripting. Thanks!</p>
  
  <pre><code>Option Explicit
  
  Const USER               = "administrator"
  Const PASS               = "*********"
  Const WSNAME_COMMANDLINE = "C:\support\abc.bat"
  
  Dim fso         : Set fso = CreateObject("Scripting.FileSystemObject")
  Dim WSHShell    : Set WshShell = CreateObject("WScript.Shell")
  Dim WshNetwork  : Set WshNetwork = CreateObject("WScript.Network")
  Dim oDic        : Set oDic = CreateObject("Scripting.Dictionary")
  Dim objArgs     : Set objArgs = WScript.Arguments
  Dim oProcessEnv : Set oProcessEnv = WshShell.Environment("PROCESS")
  
  Dim sPathToRunAs, iReturnCode
  
  sPathToRunAs = oProcessEnv("SystemRoot")&amp;"\System32\runas.exe"
  ''msgbox sPathtorunas
  
  if Not fso.FileExists(sPathToRunAs) Then : WScript.Quit(1) 'Can't find RunAs
  
  '''msgbox "runas /user:" &amp; USER &amp; " " &amp; CHR(34) &amp; WSNAME_COMMANDLINE &amp; CHR(34)
  iReturnCode=WshShell.Run("runas /user:" &amp; USER &amp; " " &amp; CHR(34) &amp; WSNAME_COMMANDLINE &amp; CHR(34), 2, FALSE)
  
  Wscript.Sleep 40                  ' Time for window to open.
  WshShell.AppActivate(sPathToRunAs)' Activate the Window
  Wscript.Sleep 3
  WSHShell.SendKeys PASS &amp; "~"      ' Send the password
  Wscript.Sleep 3
  
  ''msgbox "done"
  </code></pre>