Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
tobwz
- Posts: 30
- Joined: 25 Feb 2022 03:21
#1
Post
by tobwz » 24 Apr 2022 15:00
If I enter in Command Prompt the following command:
to check NetBIOS status then it works.
If I execute exactly the same command from a DOS batch script I was told:
'nbtstat' is not recognized as an internal or external command,
operable program or batch file.
Whats wrong?
-
OJBakker
- Expert
- Posts: 90
- Joined: 12 Aug 2011 13:57
#2
Post
by OJBakker » 24 Apr 2022 18:22
cmd will use the system variables %path% and %pathext% to search for nbtstat.exe.
You have probably changed these system variables in your script or used variables with these names.
Without the correct path large parts of cmd will cease to function, for example, find, notepad, reg are all external programs that rely on the systempath.
-
tobwz
- Posts: 30
- Joined: 25 Feb 2022 03:21
#3
Post
by tobwz » 25 Apr 2022 00:25
@OJBakker:
I disagree.
BOTH Command Prompt and batch scripts execution use the SAME Environment (variables).
So if I would change %PATH% and %PATHEXT% this would affect BOTH methods.
BUT: Command Prompt direct execution works while Batch Script execution NOT.
So it must be another reason
Is this an access permission problem?
-
OJBakker
- Expert
- Posts: 90
- Joined: 12 Aug 2011 13:57
#4
Post
by OJBakker » 25 Apr 2022 02:00
No, Command prompt and scripts START with the same environment.
Try this script.
Code: Select all
@echo off
setlocal
%systemroot%\system32\where nbtstat
nbtstat -n
path=%TEMP%
%systemroot%\system32\where nbtstat
nbtstat -n
endlocal
pause
Please post the code that shows your problem, so we don't have to keep guessing for the cause of your problem.
-
tobwz
- Posts: 30
- Joined: 25 Feb 2022 03:21
#5
Post
by tobwz » 25 Apr 2022 13:04
Ok, at first here is the batch script ShowNetBiosState.bat:
Code: Select all
@echo off
cls
echo If you get any response other than "Failed to access NetBT driver -- NetBT may not be loaded" means NetBIOS is enabled
echo.
nbtstat -n
echo.
pause
When I double click on the batch script in fails with the error message mentioned in my first post
If I open a Command Prompt, then navigate to exactly the directory where the batch script is stored (D:\tools\net services\show state\" and finally enter the batch file name and hit RETURN the same, unmodified batch script runs fine.
-
OJBakker
- Expert
- Posts: 90
- Joined: 12 Aug 2011 13:57
#6
Post
by OJBakker » 26 Apr 2022 03:01
add the following lines to your batch file.
Code: Select all
echo path: %path%
echo pathext: %pathext%
%systemroot%\system32\where nbtstat
Run this both from prompt and from windows.
Compare the output from both and that will show you why nbtstat can not be found.
-
Aacini
- Expert
- Posts: 1914
- Joined: 06 Dec 2011 22:15
- Location: México City, México
-
Contact:
#7
Post
by Aacini » 26 Apr 2022 14:26
First, you said:
tobwz wrote: ↑24 Apr 2022 15:00
If I enter in Command Prompt the following command:
to check NetBIOS status then it works.
If I execute exactly the same command from a DOS batch script I was told:
'nbtstat' is not recognized as an internal or external command,
operable program or batch file.
Whats wrong?
After that, you add:
tobwz wrote: ↑25 Apr 2022 13:04
When I double click on the batch script in fails with the error message mentioned in my first post
If I open a Command Prompt, then navigate to exactly the directory where the batch script is stored (D:\tools\net services\show state\" and finally enter the batch file name and hit RETURN the same, unmodified batch script runs fine.
From this description, I assume that the
nbtstat command is
not located in a directory of %PATH% variable, but in the same directory of the Batch script ("D:\tools\net services\show state\"). If so, you should:
- Copy or move the nbstat(.exe?) command to a directory in %PATH%, or
- Add the following command at the beginning of the Batch file:
Antonio
-
tobwz
- Posts: 30
- Joined: 25 Feb 2022 03:21
#8
Post
by tobwz » 27 Apr 2022 07:33
I solved it as follows:
I reviewed my full PATH and PATHEXT environment strings and dropped (out of approx 40 entries) around 15 deprecated paths.
They were added in past but not removed when I uninstalled the corresponding software.
Then (after clean-up) I rebooted....and it worked.
This is curious
Thank you anyway