Share via


Net use command fails in batch file but succeeds when manually typed

Question

Wednesday, January 30, 2019 4:08 PM

THIS IS NOT SPAM - SPAM usually has links, asks people to buy something or at least click something and or do something.... not spam doesn't do these, this is not spam.

We currently do not have a domain and therefore I can't use Group Policy to manage network shares... 

I'm working on bringing up an AD Domain and a traditional file server, in the meantime I'm trying to utilize a QNAP NAS as a file server for the company, I've setup shares and can map to them - even using command line, however, when I've attempted to insert a startup batch file to do this for me, it fails...

after correcting for the new Windows 10 ways of handling startup items (i.e. create lnk to the actual batch file and adding some registry entries to "authenticate' the startup item) I'm still getting an error when executing the command.

I've started a powershell as admin to run the batch file and view the error, here's the result:

PS F:\STORAGE> .\Q-MapedDrive-Board.batSystem error 86 has occurred.The specified network password is not correct.

Copying the text from the batch file and pasting it in succeeds with no issue. 

I've adjusted the context of the batch a few different ways, all results are the same (doesn't work when run as a batch, works when typed in/pasted in manually). 

I'm using this command currently:

net use <drive letter>: \<IP.of.QNAP.NAS>\share> "password" /USER:"<NETBIOSNAMEofNAS>\Username>"

but I've tried:

net use <drive letter>: \<FQDNofNAS>\share> "password" /USER:"<NETBIOSNAMEofNAS>\Username>"

net use <drive letter>: \<IP.of.QNAP.NAS>\share> /USER:"username" <password>

All replies (3)

Thursday, October 3, 2019 12:30 PM

Hi, I got the same issue.

The problem for me was, my password contained character "%"
Percentage character is ignored on batch file execution. But command works fine when executed on CMD.exe

So don't use "%" characters into your passwords.

Hope this will help.


Thursday, January 9, 2020 8:46 PM

I got the same issue.

Solution?


Thursday, January 9, 2020 9:02 PM

I got the same issue.

Try using 2 percent characters in a bat file. 

https://stackoverflow.com/questions/14509652/what-is-the-difference-between-and-in-a-cmd-file