Visual Basic Scripts

Microsoft Windows xp professional w/serv...
August 3, 2010 at 06:05:03
Specs: Windows XP
The script below was working great now it only works on certain computers. It works on all computers if I do not not use the long file names.

' Visual Basic Script file to invoke the 'Runas' program to start the TE8888
' test program with administrator capabilities.
' 12/12/05 Modified Code

On Error Resume Next
dim WshShell,oArgs,FSO

set oArgs=wscript.Arguments

'**Start Encode**
sCmd="C:\TE8888 Test Set\8888 RUNTIME\Executables\sol.exe"

set WshShell = CreateObject("WScript.Shell")
set WshEnv = WshShell.Environment("Process")
WinPath = WshEnv("SystemRoot")&"\System32\runas.exe"
set FSO = CreateObject("Scripting.FileSystemObject")

if FSO.FileExists(winpath) then
'wscript.echo winpath & " " & "verified"
'WshShell.Popup "Please Wait", 2, "The Program is loading...", 64
wscript.echo "!! ERROR !!" & VBCRLF & "Can't find or verify " & winpath &"." & VBCRLF & "You must be running Windows 2000 for this script to work."
set WshShell=Nothing
set WshEnv=Nothing
set oArgs=Nothing
set FSO=Nothing
end if

rc=WshShell.Run("runas /profile /env /user:" & sUser & " " & CHR(34) & sCmd & CHR(34), 2, FALSE)
Wscript.Sleep 30 'need to give time for window to open.
WshShell.AppActivate(WinPath) 'make sure we grab the right window to send password to
WshShell.SendKeys sPass 'send the password to the waiting window.
WshShell.Popup "Please Wait", 4, "The Program is loading...", 64

set WshShell=Nothing
set oArgs=Nothing
set WshEnv=Nothing
set FSO=Nothing


'* Usage Subroutine *
Sub Usage()
On Error Resume Next
msg="Usage: cscript|wscript vbrunas.vbs Username Password Command" & VBCRLF & VBCRLF & "You should use the full path where necessary and put long file names or commands" & VBCRLF & "with parameters in quotes" & VBCRLF & VBCRLF &"For example:" & VBCRLF &" cscript vbrunas.vbs quilogy\jhicks luckydog e:\scripts\admin.vbs" & VBCRLF & VBCRLF &" cscript vbrunas.vbs quilogy\jhicks luckydog " & CHR(34) &"e:\program files\scripts\admin.vbs 1stParameter 2ndParameter" & CHR(34)& VBCRLF & VBCRLF & VBCLRF & "cscript vbrunas.vbs /?|-? will display this message."

wscript.echo msg


end sub
'End of Script

See More: Visual Basic Scripts

Report •

August 3, 2010 at 08:45:13
I suspect if you looked on the computers that didn't work, you'd find it had a "C:\TE8888" or "C:\TE8888 Test" or "C:\TE8888 Test Set\8888".

One option would be to remove these files. A better option would be to fix the command you pass:

sCmd="\""C:\TE8888 Test Set\8888 RUNTIME\Executables\sol.exe\"""

Report •

August 3, 2010 at 13:40:48
I don't understad your first comment are you saying those files names exist? However your correct command works great. The only question that remains is what changed on my system to require the extra double quotes??? Regardless thanks for the help!!!!!!

Report •

August 3, 2010 at 14:21:37
are you saying those files names exist?
That is what I'm saying, yes.

Report •

Related Solutions

August 4, 2010 at 04:27:17
Well it turns out you where right on both counts a coworker created a file called c:\TE8888 which "killed" my old script. The new command line you provide is robost enough to ignore that file.

Thanks for some GREAT help.........

Report •

Ask Question