Recently I am interested in programming a windows batch file.
In this process, I found a critical problem in programming CMD batch.
Many CMD batch windows cause crashing explorer.exe and Windows desktop.
Many odd symptoms on Window desktop occurred.
Thus, I must kill explorer.exe and restart explorer.exe
Example
A.cmd:
#echo off
set /a a=0
:loop
set /a a=%a%+1
echo %a%
timeout /t 2 > nul
start B.cmd
goto loop
B.cmd
#echo off
echo Hello, WORLD !!!
timeout /t 60 > nul
exit
I executed A.cmd.
After a while, windows screen crashed.
Someone said that's hardware spec problem.
Someone said that's loop batch problem.
Someone said that's malware problem.
I don't think that's a computer, malware and hardware spec problem.
I think Microsoft windows itself problem.
The batch file that I am think of must need many (1~30) new CMD windows that will closed after a while.
Thus I made a CMD batch file.
No problem.
Working well.
The only problem is crashing Explorer.exe with crashing Windows desktop.
What's the solution?
Related
I made 2 bat files to start apps with examples below:
My expectation is to execute them simultaneously, meaning after double click bat file, then 3 programs will pop up.
With the 1st example, the behavior is to execute outlook first, then both Mircrosoft Edge and OneNote still not pop up, until I stop Outlook.
Example 1
#echo off
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Outlook.lnk"
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Edge.lnk"
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\OneNote.lnk"
exit
With the 2nd example, both Mrcrosoft Edge and OneNote were executed simultaneously, however Outlook not until I stop OneNote.
Example 2
#echo off
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Edge.lnk"
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\OneNote.lnk"
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Outlook.lnk"
exit
My questions is why it behaves like this way and how to make these 3 programs start up in the same time ?
Shown below is the Windows config:
Edition Windows 10 Enterprise
Version 21H2
Installed on 10/27/2021
OS build 19044.1826
Experience Windows Feature Experience Pack 120.2212.4180.0
1)Run the first program using the start command.
2)Check the task list in a loop to see if the program has appeared there.
3)Impose some time limitation to the said loop.
4)Run the next program in case of success, exit with notification otherwise.
#ECHO
OFF START program1.exe
FOR /L %%i IN (1,1,100) DO (
(TASKLIST | FIND /I "program.exe") && GOTO :startnext
:: you might add here some delaying
)
ECHO Timeout waiting for program1.exe to start
GOTO :EOF
:startnext
program2.exe
:: or START
program2.exe
Remember that the timing is not precise, especially if you are going to insert delays between the task list checks.
Normally to run tasks parallel, you should add start /b before the command to run.
The start command allows the command to be executed in another process, while /b prevents the opening of a new window.
In this specific case start /b does not work, for reasons unknown to me, but you can always use cmd /c.
I am probably missing the right vocabulary to talk about this problem more succinctly so excuse me if I'm a little wordy here. Under Windows 10 I have a program that runs inside a CMD command prompt It's an executable called OpenSim and it has it's own extensive command set, including 'shutdown', which initiates a graceful termination of the processes therein, closes SQL connections etc, then finally closes the CMD command window. I also have a CMD .bat file that is activated by my UPS when the power goes down that will of course open it's own window, and then does some housekeeping before closing down the hardware. One thing I want the .bat file to do is to somehow insert a 'shutdown'command into the other window's process. Is that possible? If so, how? Please assume I am a total newbie at this and you won't go far wrong. Thank you.
EDIT It looks like creating a file to flag the closedown event taking place is the only (and I guess rather primitive) way to do this. So, building on what others have said in stackoverflow, I have the following now. When I run it to test it waits - it doesn't. It runs right through to the end, running 'shutdown', even though the UPSFLAG.TXT file does not exist. What's going wrong?
echo Waiting for UPS Power Down Signal.
echo =================================
#ECHO OFF
SET LookForFile="C:\Opensim OSGrid\UPSFLAG.TXT"
:CheckForFile
IF EXIST %LookForFile% GOTO FoundIt
REM If we get here, the file is not found.
REM Wait 10 seconds and then recheck.
REM If no delay is needed, comment/remove the timeout line.
TIMEOUT /T 10 >nul
GOTO CheckForFile
:FoundIt
ECHO Found: %LookForFile%
rem Tidy up
del "C:\Opensim OSGrid\UPSFLAG.TXT"
shutdown
Adding double quote after the = will save your variable as that "C:\Opensim OSGrid\UPSFLAG.TXT" which you do not want. rather you want to store it as C:\Opensim OSGrid\UPSFLAG.TXT so move the quote to before lookforfile.
Also, you created a variable for the file, so you might as well use it in the delete.
Finally, as a safety measure, always put an exit after a goto. That will ensure the system exists should there be a problem in the script and you can make sure you do not delete files or shutdown the system when it was not planned for.
echo Waiting for UPS Power Down Signal.
echo =================================
#ECHO OFF
SET "LookForFile=C:\Opensim OSGrid\UPSFLAG.TXT"
:CheckForFile
IF EXIST "%LookForFile%" GOTO FoundIt
REM If we get here, the file is not found.
REM Wait 10 seconds and then recheck.
REM If no delay is needed, comment/remove the timeout line.
TIMEOUT /T 10 >nul
GOTO CheckForFile
exit
:FoundIt
ECHO Found: %LookForFile%
rem Tidy up
del "%LookForFile"
shutdown
I need to restart explorer.exe after my application is installed. I'm currently using:
taskkill /f /im explorer.exe
start explorer.exe
That works ok on windows 7, with administrator or standard user, but when I try this on windows 8 as a standard user, the command just kills the explorer and doesn't restart it.
This happens because the command line is called as administrator, even with the standard user. Then the explorer doesn't restart.
Any thoughts about how to solve this?
The code should work but since I'm not using win8 (no thanks) can not diagnose.
But some I can offer.
This may work (time needed to unload some handlers) And double tried with or without start (yes it differs in some software, don't know win8)
taskkill /f /im explorer.exe
timeout 7
start "" explorer.exe
timeout 2
explorer.exe
explorer.exe keeps many handlers, shell stuff etc. One of those can cause trouble. Try also to disable them and test again
If not you can also try reexplorer tool to do the same. Maybe they considered this kind of situations while coding.
All bests
I'm playing an old game that conflicts with the Windows Graphical Shell for Windows 7 and doesn't allow it to display properly so I simply go into Task Manager (TM) and close explorer.exe and the game displays fine but in order for me to enable explorer.exe I need to go into TM and start a new task for it to come back. I was wonder if there was a way to write a .Bat file that would kill explorer.exe launch my game and once the game closes it would simply run the task for me instead of manually needing to turn it back on.
taskkill /f /IM explorer.exe
start CNC95Launcher.exe
this is what i have so far
The start causes windows to launch your program asynchronously - that is, it will start it, then continue with the next instruction without waiting for your app to close.
Try this:
taskkill /f /IM explorer.exe
start /wait CNC95Launcher.exe
start explorer.exe
You probably don't actually need the start for explorer, because it's that kind program.
I use this (on window 7):
taskkill /F /IM Explorer.exe
*.exe
Start explorer.exe
replace * with the exe name that launches the actual game not a pre launch menu and save as .bat in the same folder directory.
It works for Star Wars Galactic Battlegrounds and AoE which can suffer weird colour issues if explorer runs.
Long time reader of posts first time posting, firstly thanks for a great site I couldn’t do my job without this site half the time.
My question is I currently have a batch file that I run on our clients that maps network drives copy files from the server to a Ram drive
And then runs the application code below. What I need to do is replace this with a nice looking GUI window. I have looked at some task automation apps (vtask studio, winautomation, visual cron) but none have the ability to create a window.
Ideally the start up would go something like, welcome to loader ping the server if it gets a reply then continues with the file copy a progress bar would be great.
Essentially build a nice looking application loader I’m running window 7 pro on the clients Windows server 2008 R2 for the server.
Any and all suggestions gratefully received thanks in advance !
Code:
:START
#echo off
TIMEOUT /T 15
NET USE m: /delete
NET USE n: /delete
NET USE n: \\SERVER\Apps
NET USE m: \\SERVER\Media
NET USE l: \\SERVER\Logs
MD d:\Apps
XCOPY n:\*.* d:\Apps\ /Y /H /E /B
TIMEOUT /T 5
mklink /D C:\Apps D:\Apps
TIMEOUT /T 5
START /MIN /WAIT "Launcher" "C:\Apps\shortcuts\Launcher.Lnk"
START /MIN E:\PY.BAT
TIMEOUT /T 10
START /MIN "reader" "C:\Apps\shortcuts\Reader.Lnk"
TIMEOUT /T 5
:LAUNCH
ECHO %Time% %Date% "Launching Application" >>"%MyLogFile%"
START /MIN /WAIT "Launcher" "C:\Apps\applications\Launch.lnk"
GOTO LAUNCH
You can do ALL of these steps in a single vTask script.
Mounting / unmounting network drives, copying files, and even displaying simple GUIs that you control.
Certainly there is a progress bar command and it works well.
vTask is probably the easiest way to build a simple GUI, put actual code behind it (including SQL etc.) and even call .DLLs if needed.
Paul
I know that VisualCron (that you mentioned) has the Popup Task which can ask questions or provide information in a window before doing somethign (like starting a Task) with any parameters you supply in that window.