net use mapping not working in batch files but works in cmd

15,861

Solution 1

I ran into the same problem. For me, the solution was this:

  • I couldn't map a the root directory of a network share to a letter.
  • I couldn't use a trailing backslash in the mapped path.

So:

net use B: \\MYSERVER didn't work and resulted in error 53 right away.

net use B: \\MYSERVER\Components\ didn't work and resulted in error 53 after a pause.

net use B: \\MYSERVER\Components did work.

Solution 2

Two options:

1) Use Process Monitor (SysInternals) with its boot logging option, filtering on CMD.EXE and System. Monitor the logon process and script execution.

2) Add a small test to the user's logon script, which uses ROBOCOPY's TBD switch to wait for the server/share to be available, i.e.:

setlocal
set LOG_FILE=c:\temp\foo.log
echo %DATE% %TIME% >%LOG_FILE%
%SystemRoot%\System32\robocopy.exe \\server\directory c:\temp\test /tbd /eta /log+:%LOG_FILE%
echo %DATE% %TIME% >>%LOG_FILE%
endlocal

Check the log file to see if ROBOCOPY does have to wait for the server/share to be available.

Share:
15,861

Related videos on Youtube

Philippe
Author by

Philippe

Updated on September 18, 2022

Comments

  • Philippe
    Philippe over 1 year

    Ok so here's the problem :

    I've got users using logon script in the domain (username.bat). The script simply lists 4 or 5 (net use letter: \\SERVER\directory\). However, when they open their session, the logon script doesnt work and returns system error 53 or 67 for all of them. I tried running the script after the profile has loaded and evrything is running, and it still gives me the error.

    I've then tried to run the same command in the cmd.exe. Everything mapped correctly. It also works fine if I map the drives using the "Tools > Map network drives" utility.

    Is there anything that can prevent a command to work when ran in a batch-file but works correctly when typed in manually?

    • raja
      raja about 13 years
      What os is the client?
    • MDMarra
      MDMarra about 11 years
      Post the script or we can't help.
  • Philippe
    Philippe about 13 years
    I've tried out the fqdn to no avail. I haven't been able to disable the firewall yet, because my customer is really picky about his security, I will have to load a client VM just to try it out later. I've also found out a lot of people say I should try by simply replacing the server name with it's IP address, although I don't see the difference since it resolves the name correctly when I type the command out manually. I'll still try it and let you know the results later on.
  • Nixphoe
    Nixphoe about 13 years
    A quick test you could also do is to put in the login script to ping that server, both as the IP and the fqdn and pipe it somewhere local. That would tell you if the AV is blocking any network connections. Might also give the event viewer a once over see if there are any errors with drive mapping in there.
  • Binarus
    Binarus almost 5 years
    +1 and thanks! This should be the accepted solution. I have lost many hours searching for the reason why I couldn't map a network drive from within a batch script, and your answer definitely was the solution. The problem even still exists in Windows 10 (version 1809). I am a bit late to the party, though ...