Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a folder (using a drive letter) as a different user via RUNAS

Status
Not open for further replies.

ADA2017

IS-IT--Management
Jun 27, 2017
6
US

Hi All,

Suppose I have a VBS file named Tester.vbs. Contents below:

Set objShell = CreateObject("Wscript.Shell")
objSHell.Run("""S:\Photos Folder\User ABC\Face Photos""")

This script runs fine and opens the folder.

Now, I want to open that specific folder (It's a network folder and the script STRICTLY has to use the mapped drive letter of S:--NO absolute path allowed) as user useradmin (password: password1)
I use the following script (RunAs.vbs) in the same folder:

Dim strCreateFolder

strCreateFolder = "Tester.vbs"

set WshShell = CreateObject("WScript.Shell")
strCmdLine = "runas /netonly /noprofile /user:DOMAIN123\useradmin" & _
" ""cmd.exe /c wscript " & "\""" & strCreateFolder & "\""" & """"
WshShell.Run strCmdLine, 2, False
WScript.Sleep 100
WshShell.Sendkeys "password1~"

User useradmin has permissions to that folder S:\Photos Folder\User ABC\Face Photos

I think I've exhausted all possible troubleshooting measures (e.g. changing the 3 quotes to 2 quotes to 1 quote, put absolute locations of the file, etc.). Nothing seems to work.

Bottom line is: I need to open a network folder (using the mapped drive letter) as a different user. PLEASE HELP.
 
The drive letter needs to be set up for all users. Without that, it won't work.
 
I failed to mention that that is a given: The drive letter is ALREADY set up for all users.
 
Do you get any errors?
Are you sure the credentials are correct?
What happens when you put the full path to Tester.vbs? Like [tt]strCreateFolder = "X:\MyFolder\Tester.vbs"[/tt]
 

See attached for the error message.
1. Credentials all verified.
2. Mapped drive and drive letter all good.
3. Tester.vbs and RunAs.vbs are in the same folder. I actually tried "X:\MyFolder\Tester.vbs" and "\\ServerLocation\Folder123\Tester.vbs". Eventually it did work for when you put the absolute network path.

But as in the error screenshot, it all comes down to the error where "The system cannot find the drive specified".

A. How come running Tester.vbs alone can open S:\Photos Folder\User ABC\Face Photos fine?
B. I need to open that folder as another user (but I need to use S: drive) using the script RunAs.vbs
C. How come RunAs.vbs is not able to do this?

 
 http://files.engineering.com/getfile.aspx?folder=9116e86d-4a80-4a98-b0a4-0a92b0fb47fa&file=error.jpg
Does that other user have drive S mapped to the same server that you do for drive S?

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Yes, drive S is mapped to the same location for all users running this script. All verified that they can access the S drive and the location in the S drive.
 
I may just be confused but, you said in #3 above "Eventually it did work for when you put the absolute network path." But the error message you show is using a UNC path. So, use the the absolute path (which is drive + path + filename) and then report any errors.

Also, a google search for error "8007000f" as it relates to vbscript returns just about nothing, so I don't even know what would cause that error to be thrown?!?! Strange.
 
Before WshShell.Run strCmdLine, 2, False can you put

WScript.echo strCmdLine

so you can see what is being executed. The error message is "cannot find the drive specified" so something on that command line is incorrect. If you

runas /user:useradmin cmd

Then execute whatever strCmdLine prints out, does it work?

 
Let me try to be clearer and use the actual network paths for illustration purposes:

***Please note: Item 4 is important. It's been established 1000 times. Thank you.***

1. R: drive is mapped to network path [highlight #FCE94F]\\RAO_ARIA_DB\Custom Reports\[/highlight]
2. S: drive is mapped to network path [highlight #FCE94F]\\ServerABC\Main Photos\[/highlight]
3. Let's simplify. Say there are only 3 user ID's involved. Domain: Domain123
Me: userme
Admin: useradmin Password: password1
3rd user: userregular
4. All 3 users have the same mapped drives for R: and S: drives on their respective PC's. All 3 users are permitted to access the locations linked to by R: and S:

[highlight #8AE234]
I need a script that will open S:\Photos Folder\User ABC\Face Photos as useradmin without having to use the network path. Please do not ask why. :) I need Explorer to open the location in the S drive.[/highlight]

Tester.vbs located in R:\~ Machine Links\zzz_Scripts works perfectly when userme or userregular runs it. Contents:

Set objShell = CreateObject("Wscript.Shell")
'Line2
'Line3
'Line4
'Line5
objSHell.Run("""S:\Photos Folder\User ABC\Face Photos""")

Now, I want to accomplish the highlighted in green, so I have another script in the same location: RunAs.vbs. Contents:


Dim strCreateFolder

'strCreateFolder = "R:\~ Machine Links\zzz_Scripts\Tester.vbs"
strCreateFolder = "\\RAO_ARIA_DB\Custom Reports\~ Machine Links\zzz_Scripts\Tester.vbs"
'strCreateFolder = "Tester.vbs"

set WshShell = CreateObject("WScript.Shell")
strCmdLine = "runas /netonly /noprofile /user:Domain123\useradmin" & _
" ""cmd.exe /c wscript " & "\""" & strCreateFolder & "\""" & """"
WScript.echo strCmdLine
WshShell.Run strCmdLine, 2, False
WScript.Sleep 100
WshShell.Sendkeys "password1~"​


Note: Ultimately, it is strCreateFolder = "\\RAO_ARIA_DB\Custom Reports\~ Machine Links\zzz_Scripts\Tester.vbs" that worked. So I'm down to the issue of why RunAs.vbs cannot execute Tester.vbs correctly so that S:\Photos Folder\User ABC\Face Photos is opened as user useradmin

I hope I am very clear enough here. All the previous questions and unclear assumptions have been addressed. There are only 2 scripts involved: RunAs.vbs and Tester.vbs. Attached are the error messages returned when RunAs.vbs is run by userme or userregular. The 3 error messages pertain to that strCreateFolder line when it is changed.

HELP PLEASEEEEEEEEEEEEE!!!!


 
 http://files.engineering.com/getfile.aspx?folder=3697f0cf-63b1-45e7-9e7d-0af708251db7&file=Error_Illustrations.jpg
OK, some research shows that when you use "RunAs", the mapped drives you created earlier are not necessarily available to the new user you are "running as". So don't use the R: drive. You have to use the UNC path.

With that said, it should work with a UNC path and I don't see anything wrong. Works on my system. Let's make it less complicated... First try pasting this in a Run window (fix domain and username) and see if it works when you manually enter the password (it should):

[tt]runas /netonly /noprofile /user:Domain123\useradmin "cmd.exe /c wscript \"\\RAO_ARIA_DB\Custom Reports\~ Machine Links\zzz_Scripts\Tester.vbs"\" [/tt]

If that fails, locate "Command Prompt", and do a shift-right-click over it (Win 7) and select "Run as different user". Enter Domain\username and password. Then run:

[tt]wscript "\\RAO_ARIA_DB\Custom Reports\~ Machine Links\zzz_Scripts\Tester.vbs"[/tt]

Barring any typos, all should work. If not, maybe there are other permission issues that are not obvious.
 
Thanks for the analysis, GUITARZAN. It's actually established that RunAs.vbs is able to execute Tester.vbs. The error CODE: "8007000F - The system cannot find the drive specified." returned refers to this line in Tester.vbs : objSHell.Run("""S:\Photos Folder\User ABC\Face Photos""").

Yes, using UNC path will work. But I need to use the mapped drive letter.

[highlight #8AE234]
So, I guess there is no way to open a mapped drive as another user (via RUNAS command)? Like I have mentioned several times, it is given that all users involved have access to the network folder/location and the drive letters involved are all the same and all set up the same way.[/highlight]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top