New
#101
Extract the files and just double-click on "# Run batch files.cmd" without changing anything. Tell me the results.
Extract the files and just double-click on "# Run batch files.cmd" without changing anything. Tell me the results.
Thanks @Matthew Wai,It worked!
It stopped with the file that could not be processed, I clicked OK and it continued, and it also gave me the Operations completed and Pause at the end.
So is the reason the other .cmd scripts didn't run have something to do with the fact it was being run from a different directory instead of within the same directory?
I replaced %~dp0*.bat with C:\Users\System-Admin\System_Admin_Implementation\*.bat and it didn't work!
It doesn't matter, the point is it works, thank you.
Last edited by Paul Black; 19 Mar 2020 at 06:32.
Thanks @Matthew Wai,
I did as you advised above and it Worked!
I then copied the .bat files I want to use into the folder three at a time and run the code again. I found one file which I have listed below that made the code exit as before. I copied the rest of the files into the folder [except that one] and ran the code again and it Worked. So there was a problem .bat file that stopped the previous versions running. The file in question is . . .
Code::: Created by: Shawn Brink :: Created on: October 13th 2017 :: Tutorial: https://www.tenforums.com/tutorials/95383-enable-disable-fast-user-switching-windows-10-a.html powershell -windowstyle hidden -command "Start-Process cmd -ArgumentList '/s,/c,REG Delete HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /V HideFastUserSwitching /F & REG Delete HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System /V HideFastUserSwitching /F & taskkill /f /im explorer.exe & start explorer.exe' -Verb runAs"
It is NOT a problem because when I come to run this on my actual OS I will leave that one out and run it separately. Thanks to the code it was easy to find.
As your code needs to be run from within the active directory, I then changed the code so that it could be run from outside the active directory and that Worked also . . .
Code:@echo off Set Folder="C:\Users\System-Admin\System-Admin_Implement" cd %Folder% (Net session >nul 2>&1)||(PowerShell start """%~0""" -verb RunAs & Exit /B) For %%i In ("%Folder%\*.bat") Do (echo Processing: "%%i"&CMD /C "%%i" & echo.) echo Operations completed. & pause
I have got to go out for a while but I will try creating a new code to run .ps1 PowerShell files and then I can finally mark this thread as solved!
The following is my suggestion. Give it a go.
Code:@echo off (Net session >nul 2>&1)||(PowerShell start """%~0""" -verb RunAs & Exit /B) Set "Folder=C:\Users\System-Admin\System-Admin_Implement" For %%i In ("%Folder%\*.bat") Do (echo Processing "%%i"&CMD /C "%%i" & echo.) echo The last one is pending. & pause powershell -windowstyle hidden -command "Start-Process cmd -ArgumentList '/s,/c,REG Delete HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /V HideFastUserSwitching /F & REG Delete HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System /V HideFastUserSwitching /F & taskkill /f /im explorer.exe & start explorer.exe' -Verb runAs"
Thanks @Matthew Wai,
That will NOT work because the file will need to be in the same folder, which as we know, causes the script to exit straight away.
As I said previously, it is NOT a problem to just to run that single script manually.
I like your thinking though.![]()
Last edited by Paul Black; 19 Mar 2020 at 13:17.
Thanks @Matthew Wai,
That works Perfectly thank you!
Yes, you are right, the above snippet was the cause of forcing the CMD window to exit automatically.
Thanks very much again!
I will have a go at running all the .ps1 files now and then I can mark this thread as solved!
Yet another suggestion:
"explorer.exe" will be restarted only after you press a key after all the .bat files have been processed.Code:@echo off (Net session >nul 2>&1)||(PowerShell start """%~0""" -verb RunAs & Exit /B) Set "Folder=C:\Users\System-Admin\System-Admin_Implement" For %%i In ("%Folder%\*.bat") Do (echo Processing "%%i"&CMD /C "%%i" & echo.) echo Press a key to restart "explorer.exe". & pause > nul taskkill /f /im explorer.exe & start explorer.exe