mjlaroda
asked on
VBScript Absolute path and Runas
Hi all,
I have a vbscript file I need users to run from their laptop, the users are part of the domain but their laptops are not, so the users must first log in.
I’m running two scripts, one the get the user credentials and run the script. The other, well is the script. Problem: Each user could save the scripts in different folders on their laptops so I have to use absolute path. That’s where I’m having a problem. Here is the script.
Can someone please help?
'Dim folderName
'folderName = "..\.."
dim fso: set fso = CreateObject("Scripting.Fi leSystemOb ject")
' directory in which this script is currently running
CurrentDirectory = fso.GetAbsolutePathName(". ")
'to use this to build a new path, you can use the BuildPath() function
NewPath = fso.BuildPath(CurrentDirec tory, "SetPrintChkFst.vbs") ‘Name of file to run-this part ‘works. **********************
If(fso.FileExists(NewPath) ) Then
WScript.Echo("The file " & NewPath & " exist")
Else
WScript.Echo("The file " & NewPath & " cannot be found")
End If
set objShell = WScript.CreateObject("WScr ipt.Shell" )
strUserName = inputBox("What is your username (domain\username)")
'objShell.Run "runas /user:" & strUserName & " ""wscript.exe" & "(fso.File(NewPath))"" "
objShell.Run "runas /user:" & strUserName & " ""wscript.exe " & "..\..\SetPrintChkFst.vbs" " "
‘Tried a lot here, nothing works ************************** *
WScript.sleep 10000
'objShell.Run "runas /user:" & strUserName & " " NewPath
WScript.Echo("Ent")
I have a vbscript file I need users to run from their laptop, the users are part of the domain but their laptops are not, so the users must first log in.
I’m running two scripts, one the get the user credentials and run the script. The other, well is the script. Problem: Each user could save the scripts in different folders on their laptops so I have to use absolute path. That’s where I’m having a problem. Here is the script.
Can someone please help?
'Dim folderName
'folderName = "..\.."
dim fso: set fso = CreateObject("Scripting.Fi
' directory in which this script is currently running
CurrentDirectory = fso.GetAbsolutePathName(".
'to use this to build a new path, you can use the BuildPath() function
NewPath = fso.BuildPath(CurrentDirec
If(fso.FileExists(NewPath)
WScript.Echo("The file " & NewPath & " exist")
Else
WScript.Echo("The file " & NewPath & " cannot be found")
End If
set objShell = WScript.CreateObject("WScr
strUserName = inputBox("What is your username (domain\username)")
'objShell.Run "runas /user:" & strUserName & " ""wscript.exe" & "(fso.File(NewPath))"" "
objShell.Run "runas /user:" & strUserName & " ""wscript.exe " & "..\..\SetPrintChkFst.vbs"
‘Tried a lot here, nothing works **************************
WScript.sleep 10000
'objShell.Run "runas /user:" & strUserName & " " NewPath
WScript.Echo("Ent")
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You need to make sure the whole path is in quotes like:
runas /user:rossdm\mlaroda wscript.exe "C:\users\mlaroda\Desktop\ SetPrinter Canon\new\SetPrintChkFst.v bs"
Next see what happens if you just paste that line into a command prompt.
runas /user:rossdm\mlaroda wscript.exe "C:\users\mlaroda\Desktop\
Next see what happens if you just paste that line into a command prompt.
I also don't think you need wscript.exe in there. You should be able to just run the vbs. I use Linux at work now, so I can't test that theory, but if it helps...
ASKER
I extended the folders for testing purposes to
C:\Users\mlaroda\Desktop\S etPrinter_ Canon\new\ Space folder\SetPrintChkFst.vbs
I'm Back to There is no file extension in
"C:\Users\mlaroda\Desktop\ SetPrinter _Canon\ner \Space".
using line:
objShell.Run "runas /user:" & strUserName & " ""wscript.exe " & "C:\Users\mlaroda\Desktop\ SetPrinter _Canon\new \Space folder\SetPrintChkFst.vbs"
This may be a windows 8 problem to I'll be satisfied if I get it to work without space in the folder for now.
C:\Users\mlaroda\Desktop\S
I'm Back to There is no file extension in
"C:\Users\mlaroda\Desktop\
using line:
objShell.Run "runas /user:" & strUserName & " ""wscript.exe " & "C:\Users\mlaroda\Desktop\
This may be a windows 8 problem to I'll be satisfied if I get it to work without space in the folder for now.
Hi, try this code. I think the main problem is that when you need to use multiple quotes in the runas string, you need to escape the "inner" ones using a backslash.
Regards,
Rob.
Regards,
Rob.
Set objFSO = CreateObject("Scripting.FileSystemObject")
' directory in which this script is currently running
CurrentDirectory = Replace(WScript.ScriptFullName, WScript.ScriptName, "")
NewPath = CurrentDirectory & "SetPrintChkFst.vbs"
If objFSO.FileExists(NewPath) = True Then
WScript.Echo("The file " & NewPath & " exist")
Set objShell = CreateObject("WScript.Shell")
strUserName = inputBox("What is your username (domain\username)")
objShell.Run "runas /user:" & strUserName & " ""wscript.exe \""" & newpath & "\""""", 1, True
Else
WScript.Echo("The file " & NewPath & " cannot be found")
End If
ASKER
runas /user:rossdm\mlaroda "wscript.exe C:\users\mlaroda\Desktop\S
which is good, but on objectShell.Run command I'm getting:
There is no file extension in "C:\Users\mlaroda\Desktop\
I've temporary changed that folder to SetPrinter_Canon, now it's showing the full name but still not running the file. meanwhile I'm checking the file itself.
But I will also most likely will need it to work with the space in the folder name