33

I am trying to use following command to map a drive in persistent mode, and I don't want it to ask login credentials everytime I reboot the machine:

net use P: \\server\folder Password123 /user:user123 /savecred /persistent:yes

But I am getting folowing error:

A command was used with conflicting switches.
More help is available by typing NET HELPMSG 3510.

I followed this article: http://pcsupport.about.com/od/commandlinereference/p/net-use-command.htm

Please help with this issue.

sabertooth1990
  • 1,048
  • 1
  • 13
  • 19

2 Answers2

37

When we use /savecred switch we should not give the credentials in the same line. The correct command should be:

net use P: \\server\folder /savecred /persistent:yes

It will ask for username and password.

sabertooth1990
  • 1,048
  • 1
  • 13
  • 19
  • 4
    The help doesn't give any indication of this at all :/ It's worth noting if you have credentials in the vault already, the command line won't ask you for them. – Mooing Duck May 14 '15 at 02:50
  • 2
    This doesn't ask for a password for me, it just announces success and a "dir p:" gives "access is denied". – Andrew J. Brehm Jan 04 '17 at 09:04
24

You can add your credentials to Windows Vault and then map you drive, this way you can avoid the limitation sabertooth1990 mentioned:

CMDKEY /add:%server% /user:%username% /pass:%password%
NET USE \\%server%\%folder% %localdrive% /SAVECRED /PERSISTENT:YES
bugrasan
  • 397
  • 2
  • 9
  • 1
    This doesn't do anything for me. – Andrew J. Brehm Jan 04 '17 at 09:12
  • 2
    +1 for letting me know about the poorly named `cmdkey` command (really Microsoft?). Also note that if you use this command first, there's no need to pass /SAVECRED to `net use`. /SAVECRED really means "use current credentials, but if they don't work, ask me for credentials and save them in Credential Manager". – Paul Feb 21 '19 at 03:03