New
#81
Thanks @Matthew Wai,
I am going to look at this and try to get this working today!
Well, I have sort of got this working [needs to be right-click and Run as Administrator] . . .
I can't get it to say Processing completed! at the end for some reason, it just exits!Code:@echo off cd /d "C:\Users\System-Admin\System-Admin_Implementation" For %%i In (*.bat) Do ( echo Processing BAT file: "%%i". Call "%%i" & echo. & Pause & echo.)
Last edited by Paul Black; 18 Mar 2020 at 05:55.
Just double-click on the following CMD script file, which will automatically get administrative privileges.
It will display "Operations completed" in the end of the process. An error message will appear and the process will be paused as long as an error has arisen. The following code in a batch file will cause such an error.Code:@echo off (Net session >nul 2>&1)||(PowerShell start -verb runas '%~0' &exit /b) For %%i In ("E:\Testing\*.bat") Do (echo Processing "%%i"&CMD /C "%%i") echo Operations completed. & pause
Try it yourself. See for yourself.Code:@echo off Start "" "C:\filename.txt"
Thanks @Matthew Wai,
I see what you mean . . .
It didn't however stop when all the .bat files had finished, it just exit!
Hello @Matthew Wai,
In the two instances in my post above . . .
The first It means "The Program / Code", it is capitalised because it is at the beginning of a sentence.
The second it means the same as the one above but is not capitalised because it is not the beginning of a sentence.
It basically refers to an object or thing!
Do you mean the code did not stop running even when all the .bat files had been processed?
The code will still exist in the script file but will not keep running when all the .bat files have already been processed.
When you see "Press any key to continue", just press a key, and the Command Prompt window will be closed.
Sorry, I misread "exit" as "exist", so I did not get your point.
The following is the CMD script, in which the last command ispause
.
The following are the output:Code:@echo off (Net session >nul 2>&1)||(PowerShell start -verb runas '%~0' &exit /b) For %%i In ("E:\Testing\*.bat") Do (echo Processing "%%i"&CMD /C "%%i") echo Operations completed. & pause
When I click on "OK", it will go on to the next batch file and then display "Operations completed".
Have you used the commandpause
at the end of your script?
You have to put& Pause
outside the brackets.
Hello @Matthew Wai,
This is the .cmd which I am using which you posted earlier [except I changed the path to my path] . . .
Code:@echo off (Net session >nul 2>&1)||(PowerShell start -verb runas '%~0' &exit /b) For %%i In ("C:\Users\System-Admin\System-Admin_Implementation\*.bat") Do (echo Processing "%%i"&CMD /C "%%i") echo Operations completed. & pause
It gives me the ERROR message after the script has finished, but it DOESN'T Pause when it has finished!