2

This command will work in CMD if I copy and paste it from my batch file to CMD. When I run my batch file, it tells me access is denied (System Error 5). Any idea what I need to do to fix this?

NET USE * "\\server\folder\" "password" /USER:domain\username
phuclv
  • 37,963
  • 15
  • 156
  • 475
Hartley
  • 69
  • 1
  • 3
  • 13

4 Answers4

2

If the password happens to contains a percent character, double-up on the percent character to "escape" it. So command:

NET USE X: \\Myserver\Myshare /user:Mydomain\John Ha322%%xb%%

would be written into the batch file if the password were "Ha322%xb%"

phuclv
  • 37,963
  • 15
  • 156
  • 475
Jerry Ray
  • 21
  • 2
0

Try the following (Im assuming that * is a drive letter, fill in the angle braces):

net use <driveLetter>: "\\<servername>\<sharepath>" /u:<domain>\<user> <password>

make sure that the script is running under a context or interactive session. So, example you are running the task as a job (schedule task). Make sure that the task is running under a user account (not the SYSTEM account) and that "Don't store password" is unchecked in the schedule task properties.

0xGiddi
  • 404
  • 2
  • 12
  • Did you try running as administrator? (Bypass UAC) And what windows version are you running? – 0xGiddi Oct 23 '14 at 23:55
  • Clicked on "Run as Administrator" on CMD and ran my batch (to get system errors), now instead of "System Error 5", we have progressed to "System error 86" network password is not correct. Keep in mind this password is correct and works when I copy and paste this command directly to CMD. – Hartley Oct 24 '14 at 00:08
  • Do you have any AV? That will be a difference between a script and a command prompt security settings. Try disabling he AV/FW temporarily. – 0xGiddi Oct 24 '14 at 00:24
  • This server is on a local network that is not connected to the internet. No AV or FW. – Hartley Oct 24 '14 at 00:39
  • Does the password contain a `"` character? If it does, you will need to escape it in the string on the command line. – Bill_Stewart Oct 24 '14 at 00:49
  • No, passwords are only characters and numbers. – Hartley Oct 26 '14 at 21:33
  • Use the ShowArgs.exe utility from [this article](http://windowsitpro.com/powershell/running-executables-powershell) and make sure the `net use` command line is actually correct. (Substitute 'ShowArgs' with 'net' to see the command line PowerShell is really running.) – Bill_Stewart Oct 27 '14 at 16:21
  • `*` is legal for the drive argument. It tells the `net use` command to take the next available drive letter. – nobody Nov 27 '15 at 03:49
0

If it's System Error 5 then you should run cmd.exe as administrator.

But System Error 86 occurred when you type username without domain. The simplest way is to type /u:remoteIPaddressORremoteComputerName\username. It is about NTLM authentication on Windows 7+.

phuclv
  • 37,963
  • 15
  • 156
  • 475
mdghost
  • 376
  • 3
  • 8
0

If the password ends in a ! it will not work and will do this. Error 5 or Error 86 for some reason.