create shortcut to network directory with different user

8,182

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.

Share:
8,182

Related videos on Youtube

Our Man in Bananas
Author by

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, 2022

Comments

  • Our Man in Bananas
    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
    Darius over 8 years
    That 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
    Tobias Mädel over 8 years
    This 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
    Francesco Mantovani over 5 years
    how can I pass the password in the TARGET?
  • Darius
    Darius over 5 years
    To 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).