Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

runas log off vbs script that calls a batch file

$
0
0

Hi. I want to run a log off script that will enable the automatic updates service in xp. The users do not have admin rights and we cant make them members of the power users group.

I have a vbs script that does a runas on batch file with admin credentials. But now and then when logging off, a command window still prompts asking for the password. When running the vbs file manually, it works every time.

Please see script below

Option Explicit

Const USER = "domain\user"
Const PASS = "password"
Const WSNAME_COMMANDLINE = "\\domain\SYSVOL\domain\scripts\Enable AND Start Update Service.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")&"\System32\runas.exe"
''msgbox sPathtorunas

if Not fso.FileExists(sPathToRunAs) Then : WScript.Quit(1) 'Can't find RunAs

'''msgbox "runas /user:" & USER & " " & CHR(34) & WSNAME_COMMANDLINE & CHR(34)
iReturnCode=WshShell.Run("runas /user:" & USER & " " & CHR(34) & WSNAME_COMMANDLINE & CHR(34), 2, FALSE)

Wscript.Sleep 30000                ' Time for window to open.
WshShell.AppActivate(sPathToRunAs)' Activate the Window
Wscript.Sleep 30000
WSHShell.SendKeys PASS & "~"      ' Send the password
Wscript.Sleep 30000

I have tried changing the wscript.sleep value even to 10000 but still no joy

If anyone has any ideas, please let me know


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>