INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

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

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

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

(OP)

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.

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

The drive letter needs to be set up for all users. Without that, it won't work.

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

(OP)
I failed to mention that that is a given: The drive letter is ALREADY set up for all users.

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

Do you get any errors?
Are you sure the credentials are correct?
What happens when you put the full path to Tester.vbs? Like strCreateFolder = "X:\MyFolder\Tester.vbs"

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

(OP)

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?

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

Does that other user have drive S mapped to the same server that you do for drive S?

Skip,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

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

(OP)
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.

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

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.

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

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?

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

(OP)
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 \\RAO_ARIA_DB\Custom Reports\
2. S: drive is mapped to network path \\ServerABC\Main Photos\
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:


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.


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!!!!


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

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):

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

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:

wscript "\\RAO_ARIA_DB\Custom Reports\~ Machine Links\zzz_Scripts\Tester.vbs"

Barring any typos, all should work. If not, maybe there are other permission issues that are not obvious.

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

(OP)
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.


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.

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

>no way to open a mapped drive as another user

Correct

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close