Windows 10: NET USE in a batch file- sometimes works

Discus and support NET USE in a batch file- sometimes works in Windows 10 Network and Sharing to solve the problem; 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... Discussion in 'Windows 10 Network and Sharing' started by SteveMann, Jul 26, 2020.

  1. 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, Jul 26, 2020
    #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, Jul 26, 2020
    #2
  3. Steevo Win User
    Batch file to ping network

    No, batch files are extremely easy.

    A "If" requires three extra steps.

    Code is not how much you can put in, but how lite can you make it and still perform the functions.

    So

    @ echo off


    ping 1.4.1.4 >a.txt

    findstr /m "Request timed out" a.txt
    if %errorlevel%%==0 (
    echo Save our nets!!!
    )

    pause
     
    Steevo, Jul 26, 2020
    #3
  4. oily_17 Win User

    NET USE in a batch file- sometimes works

    Batch Files Knowledge Base

    Don't use batch files very much but one I find useful is for creating a list of files in a directory.
    Just copy the text below into Notepad and save as Filelist.bat

    dir /a /-p /o:gen >filelist.txt

    When you run it from a folder it will create a Filelist.txt file,in the same folder, that lists all the files in that folder.Useful when you are too lazy to type all the files out yourself.
     
    oily_17, Jul 26, 2020
    #4
Thema:

NET USE in a batch file- sometimes works

Loading...
  1. NET USE in a batch file- sometimes works - Similar Threads - NET batch file

  2. batch file is not working

    in Windows 10 Network and Sharing
    batch file is not working: Hi world,I need to get an absolute path value like this but it's not working well.batch file:==================================for /F "tokens=1" %%i in 'PowerShell -Command "& {Get-ChildItem %USERPROFILE%\Desktop\privacy\*.xlsx select -exp Name -last 1}"' do set FNAME=%%i...
  3. Deleting files using a batch file

    in Windows 10 Gaming
    Deleting files using a batch file: I created a batch file using AI to delete files older than 3 months from a specific folder but the code I received does not work:. Files are dated in DD/MM/YYYY format in the folder.@echo offset "folder=C:\Users\CC\Documents\0Temp"set "cutoffdate="for /f "tokens=1-3 delims=/"...
  4. Deleting files using a batch file

    in Windows 10 Software and Apps
    Deleting files using a batch file: I created a batch file using AI to delete files older than 3 months from a specific folder but the code I received does not work:. Files are dated in DD/MM/YYYY format in the folder.@echo offset "folder=C:\Users\CC\Documents\0Temp"set "cutoffdate="for /f "tokens=1-3 delims=/"...
  5. Allow batch file renamer to work?

    in Windows 10 Software and Apps
    Allow batch file renamer to work?: I'm trying to use a batch file renamer in order to add terms to the beginning of a file:picture1.jpgpicture2.jpgadd "2022 - " to the beginning to give:2022 - picture1.jpg2022 - picture2.jpgFirst off, I'd like a suggestion as to a safe one to use. Free is obviously preferable,...
  6. 'net use' works in cmd window, not in .bat file

    in Windows 10 Network and Sharing
    '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...
  7. Batch file not working

    in Windows 10 Network and Sharing
    Batch file not working: Hello, Iam making autorun project that if I plug Flash disc in my pc it autoruns batch file with my "assistant" what says Hi, what do you want? But here are things that just doesn´t work: 1.If I plug in the Flash disc autorun.inf dont do anything. 2.If I manage batch file...
  8. Batch files for use in BSOD debugging

    in Windows 10 BSOD Crashes and Debugging
    Batch files for use in BSOD debugging: [img] Warning This thread is for use by the BSOD team ONLY, to store batch files that can be used to collect additional data, fix settings or anything else that is useful in debugging BSOD problems in Windows 10. [img] Information The way I see it working is the first post...
  9. Create batch files with Batch?

    in Windows 10 Software and Apps
    Create batch files with Batch?: How to create Batch and VBS files with Batch? So I write a batch file which I then convert to exe that creates new folders in a certain directory and then creates batch and VBS files with a certain content and saves them in the created folder. So it's similar to a program...
  10. Need to create batch file for "net share" command

    in Windows 10 Network and Sharing
    Need to create batch file for "net share" command: I created a simple command from powershell that maps a drive for me using the "net share" command (see below). However, i want to turn this in to a batch file so I do not have to type it every time. When I name it filename.bat and try to run it, I get a system error 5 has...