troubleshooting Question

VBScript Absolute path and Runas

Avatar of mjlaroda
mjlarodaFlag for Bahamas asked on
ProgrammingVB Script
6 Comments1 Solution978 ViewsLast Modified:
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.FileSystemObject")

' 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(CurrentDirectory, "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("WScript.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")
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros