NET USE in a batch file

Hello,

I created a script to connect network drives at Windows login, which will be launched in the Task Scheduler.
To do this, I created a first .bat file that calls the second one in a cmd console (I first thought the problem was that the script was running in a taskeng console).
The first .bat file contains:
cmd /k start C:\Users\XXX\second.bat

and the second one
net use * /DELETE
net use Y: \\SERVER\Root /USER:XXX **** /PERSISTENT:NO
net use Z: \\SERVER\Root\BDD /PERSISTENT:NO
start explorer.exe \\SERVER\Root


If I run the first bat manually, it works perfectly.
However, when the first bat is launched by the Task Scheduler at session startup, it doesn't work (I get an "unreachable path" error).

I delayed the startup of the bat to ensure the network connection is properly established, but that didn't help...

I'm going in circles and I haven't found an answer online... not for lack of trying though :(

Thank you for your help.

3 answers

  1. Hi-

    why don't you do explore y:\?
    0
    1. The last line is provisional
      It’s just to check if the authentication was successful or not
      I can check if the network drive has been created as well, but that's not where it’s failing
      0
      1. Here's a bit more information
        I just restarted and I got:
        On the cmd console:

        C:\Windows\system32>net use * /DELETE /YES
        The list is empty.

        C:\Windows\system32>net view \\SERVER\Root
        The system error 5 occurred.

        Access denied.

        C:\Windows\system32>pause
        Press any key to continue...

        C:\Windows\system32>net use Y: \\SERVER\Root /USER:xxxxx ***** /PERSISTENT:NO
        The command completed successfully.

        C:\Windows\system32>net use Z: \\SERVER\Root\BDD /USER:xxxx ***** /PERSISTENT:NO
        The command completed successfully.

        C:\Windows\system32>pause
        Press any key to continue...

        C:\Windows\system32>start explorer.exe Y:

        C:\Windows\system32>


        and I get when opening the explorer
        The location is not available
        Y:\ is not available. If the location is on this PC,
        ensure that the device or drive is connected or that the disk is inserted, then try again. If the location is on a network, ensure that you are connected to the network or Internet, then try again. If the location is not found, it may have been changed or deleted


        that said, I have another error when I open \\SERVER\Root with the explorer.
        The error says that I do not have permission to access the files...

        Yet, when I run the .bat manually, everything works PERFECTLY
        0
        1. Under which operating system(s) are the different machines?
          0
        2. Windows 8.1
          As for the server, I don't know; it's a hosted site server.
          0
        3. I would create a single batch file launched by a shortcut (right-click on the desktop === create a shortcut and there you indicate the path to your second batch file

          In the advanced properties of the shortcut, check Run as administrator

          It is this shortcut that needs to be used in the scheduled task

          (That's how I used to do my automatic backups in RSO before switching to SyncBack)

          0