Windows 10: 'net use' works in cmd window, not in .bat file

Discus and support 'net use' works in cmd window, not in .bat file in Windows 10 Network and Sharing to solve the problem; Win10 Pro, Version 2004, build 19041.804 (Suggestion to Microsoft- put a 'copy to clipboard' button on the WinVer window). On my home network I have... Discussion in 'Windows 10 Network and Sharing' started by SteveMann, Feb 19, 2021.

  1. SteveMann Win User

    'net use' works in cmd window, not in .bat file


    Win10 Pro, Version 2004, build 19041.804
    (Suggestion to Microsoft- put a 'copy to clipboard' button on the WinVer window).

    On my home network I have some servers and a couple of NAS drives. (Eight altogether). In startup I call a batch file to map them using 'net use'. Most of the time this works just fine. But once in a while, and with no particular repeatability (sometimes it's drive X, sometimes drive Y or one of the other net drives), the net use on the batch file fails. Most often with an error 67- unknown host, or network name not found.

    In all fails from the batch file, if I open a separate cmd window and manually enter the net use command line, it works.

    Here is my "top" bat file called from startup:
    Code:
    And this is typical of my subroutine bat files (fake password):
    Code:
    Any solutions would be appreciated....

    :)
     
    SteveMann, Feb 19, 2021
    #1
  2. SteveMann Win User

    NET USE in a batch file- sometimes works

    Windows 10 Pro
    I have a batch file where I map my net devices, mostly Samba shares from my Linux servers.
    (I know you don't like to see snippets, but the bat file is over 300 lines long.)
    Basically, I have a function for each drive to be mounted:
    Code:
    At least one of the drives, seemingly at random, will give me a "name not found" error or a "System Error 5" (AKA. BSOD for NET), but when I open a CMD window and manually enter the net use line, it works. Sometimes simply repeating the bat file corrects the problem.

    Can anyone suggest why running the net use from a bat file could fail when the same net use in a cmd window connects just fine?

    <And how do I properly post code?>
     
    SteveMann, Feb 19, 2021
    #2
  3. Kotabug Win User
    My Batch File(.bat) is no longer running CMD

    My Batch File(.bat) is no longer running CMD and when i go and change the program and find CMD and or Command Prompt it says that the program that i chose cannot be associated with this file type. Please choose another. I ran CMD with .bat file before, but
    now i can't. I there a solution to this, please?

    Original Title: Set Associations
     
    Kotabug, Feb 19, 2021
    #3
  4. Zahav Win User

    'net use' works in cmd window, not in .bat file

    Cant open ANY Bat file

    Hello,

    It does not matter what function the bat file has, what it's for and what is the address written in. Upon launch, it will give an error: "Windows cannot get access the specified path or file. You may not have the appropriate permissions to access this item".
    Launching as admin will not help, it will go blank or give another error. So no bat file will ever launch a software. Workaround for me its bat to exe converter, but it does not work in all cases.

    I have only the windows defender working. Looked all over, tried tweaks found on the net. Nothing won't work. There is a setting somewhere that blocks cmd for accessing the files using bat files. Would be grateful for the useful help.
     
    Zahav, Feb 19, 2021
    #4
Thema:

'net use' works in cmd window, not in .bat file

Loading...
  1. 'net use' works in cmd window, not in .bat file - Similar Threads - 'net use' works

  2. Bat or Cmd file not running at login

    in Windows 10 Gaming
    Bat or Cmd file not running at login: This should be an easy one. Created a net use map drive batch file, also as a cmd. Either one not both, just as a troubleshooting step. File is located on my desktop and if I double click on it, either one it executes as expected and maps the drives. 1st approach was a...
  3. Bat or Cmd file not running at login

    in Windows 10 Software and Apps
    Bat or Cmd file not running at login: This should be an easy one. Created a net use map drive batch file, also as a cmd. Either one not both, just as a troubleshooting step. File is located on my desktop and if I double click on it, either one it executes as expected and maps the drives. 1st approach was a...
  4. Comma escaping in BAT/CMD?

    in Windows 10 BSOD Crashes and Debugging
    Comma escaping in BAT/CMD?: Hi. I try to write script like this one: set %PLAYER%=<part of command> rtsp://192.168.1.1:554/?avm=1^&freq=450^&bw=8^&msys=dvbc^&mtype=256qam^&sr=6875^&specinv=0^&pids=0,16,17,18,20,3000,3001,3002,3009 <other command> for /f "tokens=2 delims==; " %%a in ' wmic process...
  5. Automatically close CMD window after .bat file finishes?

    in Windows 10 Ask Insider
    Automatically close CMD window after .bat file finishes?: I've got a little batch file I use to open two programs with one shortcut, and while it works, the CMD window remains open until I manually close it. There is an "exit" at the end, and I've googled for solutions for this but none of them worked. @Echo off cd C:\Program...
  6. Pin .cmd/bat files to taskbar

    in Windows 10 Ask Insider
    Pin .cmd/bat files to taskbar: Some UWP apps look very out of place on my taskbar and I wanted to change the icons. The only way I found looking instead of editing in MS Visual Studio was to make a run command and that opens the app. However, I can't pin it to the taskbar. I tried .bat but that didn't work...
  7. Need some Help with CMD and .bat files

    in Windows 10 Ask Insider
    Need some Help with CMD and .bat files: I have .bat file thats in a folder in my desktop (location). When i open the bat file i need it to run in the folder that's it's located (in the folder thats on my desktop) However, when i run the bat file it runs at the default location. So isn't there anyway I can change...
  8. Executing a .bat file on CMD

    in Windows 10 Support
    Executing a .bat file on CMD: Hello all, For a programming process we need to execute a .bat file from CMD. I'm on Windows 10 x64. When I paste the path to the file and hit Enter, the message below is expected to show up: Setting up environment for Qt usage... It happened a time and when we wanted to...
  9. rename cmd to command >bat file dont work Solution

    in Windows 10 Customization
    rename cmd to command >bat file dont work Solution: hello guys i m look for a solution i m like to rename C:\Windows\System32\cmd.exe to C:\Windows\System32\command.exe but then i m can not open anny *.bat file can you guys help me...
  10. Executing the bat file without showing the cmd window?

    in Windows 10 Support
    Executing the bat file without showing the cmd window?: I have a bat file closing a program - Digital Clock close.bat - containing: Code: taskkill /F /IM digital_clock.exe[/quote] How could I avoid this window to be opened when executing the bat file: [img] 92109