create shortcut to network directory with different user
Solution 1
The reason the command fails is that you need to quote the entire command with it's arguments, otherwise you're just passing more arguments to runas
.
Consider:
C:\Windows\System32\runas.exe /user:DOMAINNAME\UserName "explorer.exe \"\\ServerName\drive$\directory\""
I think you need the /user:
part there too, so I've included that for completion.
It could also default to Documents
if it can't access the path for some reason.
Solution 2
Use Net Use
Command
What you want is:
net use x: \\servername\drive$\directory * /user:username
Basically it creates a mapped network drive on x: (or any drive of your choice) that points to \servername\drive$\directory. * refers that it will prompt you for password. And /user:username refers to what username to use.
If you don't want it to prompt you for password, you can write your password in there.
I hope this helps.
Note: If you already connected to that share drive as a different user previously, it will fail. You will need to remove any current connection with other username.
Related videos on Youtube
![Our Man in Bananas](https://i.stack.imgur.com/OvhXm.jpg?s=256&g=1)
Our Man in Bananas
I am a developer at a Non-Profit organization in London, UK. We mainly work in SQL Server, c#, web-services, and SharePoint, but love using Excel and Excel VBA as well as tinkering with XML/XSLT when the opportunity arises Matt Gemmell: What have you tried? Rubber Duck Debugging How to debug small programs
Updated on September 18, 2022Comments
-
Our Man in Bananas almost 2 years
I am trying to use a shortcut to open a network directory as a different user but it's not working properly.
In the Target of my shortcut I have this:
C:\Windows\System32\runas.exe /DOMAINNAME\UserName explorer.exe "\\ServerName\drive$\directory"
what am I doing wrong - it just opens the My Documents folder
-
Darius over 8 yearsThat is interesting =) I didn't realize that was an option. Thanks I learn something new :) At least this way, it won't map a drive, but simply open it as a different user...
-
Tobias Mädel over 8 yearsThis will probably only work if you're using a windows-AD domain. With for example a Linux samba-server and system users, I doubt this would work.
-
Francesco Mantovani over 5 yearshow can I pass the password in the TARGET?
-
Darius over 5 yearsTo put the password into the net use command? Put the password as part of the command
net use x: \\servername\drive$\directory /user:username password
separated with a space. Note: Not recommended to put as part of a batch script as the password is in the clear (anyone can read the password from the batch file).