I am writing batch file to use 'netsh' command repetitive. So far I wrote this code.
#Echo Off
SET PCNAME=%COMPUTERNAME%.%USERDNSDOMAIN%
#Echo On
netsh http add urlacl url=http://%COMPUTERNAME%.%USERDNSDOMAIN%:1000/ user=everyone
Exit
When I am running this command, this runs infinitely. Even when I run only
netsh http add urlacl url=http://%COMPUTERNAME%.%USERDNSDOMAIN%:1000/ user=everyone
It's going infinitely.
What can I do to run it properly?
Filename was netsh.bat. I changed file name and its working fine
Related
The issue
I am trying to create a batch file that will execute the following two commands:
cd /some/path
dotnet run
that produces the following output:
It starts my localhost server.
Trying To Accomplish
What I would like to do is, put those two commands in a batch file and automatically open Chrome to the server address, HOWEVER, the dotnet command takes some time to finish. So somehow, I would have to keep monitoring localhost to see if it is available.
Any help would be appreciated. Although opening a CMD window, typing those 2 commands, and waiting a minute isn't all that much of a problem, it sure would be nice to just click on a batch file.
Thank you.
You can create a batch file like this code :
#echo off
Set "ApplicationPath=%UserProfile%\source\repos\PruttPos\PruttPosSystem\"
CD /D "%ApplicationPath%"
dotnet run
Start "Chrome" Chrome.exe "http://localhost:5000"
pause
START "Test Server" "%~dp0\server.exe" LAN %M%.aao log=server.log ini=server.ini
Everything after "LAN" is not being executed by server.exe I can see in the servers log file that it is trying to open lan but it should be trying to open %m%.aao which means everything after "LAN" is being ignored.
How can I fix this?
Using
START "Test Server" server.exe LAN %M%.aao log=server.log ini=server.ini
will not work as I'm trying to run the batch file from WOTGreal. I am unsure why, but the way I fixed it for the other two files/programs I open was to use %~dp0, but the server requires that the spaces not be ignored.
I'm trying to run the batch file from WOTGreal
So the batchfile will be run from a different folder. That will also mean server.exe will be run from a different folder. so local filenames like in %M%.aao log=server.log ini=server.ini will be read from the wrong directory.
You could probably fix that by also using %~dp0 in all other paths. But it is probably easier to change the current directory at the start of the batchfile. To do that, add the following line to the start of the batchfile.
cd /d "%~dp0"
When I want to start a local hotspot, I normally run cmd as administrator and type the command
netsh wlan start hostednetwork . It wastes of time to run cmd and type this command. Is there any alternative way to do it using bat file?
Might be late, but save only this line into .bat file:
netsh wlan start hostednetwork
And then use any .bat to .exe converter like this one: Advanced BAT to EXE Converter OR you can use anyone else you like.
Convert it, right click on the new one, Properties -> Compatibility -> Run this program as an administrator
Double click the new .exe file, and there you go!
You need to set the hostednetwork for the first time if you haven't before using this line:
netsh wlan set hostednetwork mode=allow ssid=SSID_NAME key=PASSWORD
IFF you want to run your hostednetwork at startup:
Open Run (Windows key + R)
type: shell:startup
Then copy the .exe file you made previously in that folder.
You may need to enable "Run as an administrator" option for that program after moving it to startup folder.
Take a look into this gist, in resume just write this into a batch-File
netsh wlan set hostednetwork mode=allow ssid=SSID_NAME key=PASSWORD
netsh wlan start hostednetwork
pause
Me too, I don't want run command every create wifi, so I find a solution, that is create shortcut. It's easier than creating batch-file.
Start: netsh wlan start hostednetwork
Stop: netsh wlan stop hostednetwork
Right click shortcut / Properties / Advanced / Tick Run as administrator/ ok / Apply / ok.
You cant watch on youtube, this is tutorial video.
im tyring to write a bat file to ensure i am logged into a remote pc by a certain time so that some other auto processes can run on that pc.
heres where i am
cmdkey /generic:TERMSRV/server /user:**** /pass:*****
mstsc /v:server
ping 8.8.8.8 -n 10
taskkill /im mstsc.exe /f
problem im facing is that after lauching the remote pc is doesnt move to the ping until i manually close the cmd window
seems really simple, im just blanking. and if i could schedule it and save my creds in task scheduler i would, current gp doesnt allow me to.
thanks in advance.
You can call mstsc with start to run mstsc independently of the batch script.
start "" mstsc /v:server
I have a batch file called test.bat in server which contains 2 call batch command inside it.
I am running this test.bat from another server using psexec command
The first call batch file command working fine however when it goes to next call batch command its throwing error ".bat exited with error code 0."
Actually what the second command does is that something like below
call D:\abc\def\ghi\test2.bat test >>test.log
I am not sure why its failing in this line. Is it due to write permission?
Please advise...
Error code 0 actually means success. This is psexec reporting that the remote execution completed successfully.
Finally I resolved by the below command and write the log in my local server where I am running the psexec command
psexec -u username -p password \\testserver "c:\test\test.bat" 1>Outputlog