Get the CMD.exe Window to close
Do you ever have a bat or cmd file that you have written to do something like update a config file then launch a application or process, and have it fail to close the cmd window after it completes even with the “EXIT” command placed at the end of script?
Yes? Funny… me too.
Here is what I found fixes the issue.
I have a script that updates the desktop gadgets your profile should launch upon login. Pretty simple script, it copies the settings.ini file from a network share and places it in your profile directory under “sidebar” and then launches sidebar.exe with a switch. This is a great script for controlling the gadgets seen on a users desktop. (Script example below if you want it)
The problem I was having with this script was I was trying to launch the sidebar application after the update and that was causing the cmd window not to close after it launched the application.
C:\Program Files\Windows Sidebar\sidebar.exe” /autostart
Here is the trick to get a cmd that fails to release after launch in a batch file to actually release.
start “” “C:\Program Files\Windows Sidebar\sidebar.exe” /autostart
If you look at the command, I use the “start” cmd and then supply (“”) a literal nothing as a switch to the “start” cmd. Then in quotes (if spaces exist) the command to run.
Wow, the window now closes after it launches the sidebar application.
I hope this helps some scripter out there with login scripts they are writing. Below you will find a copy of my login script to set gadgets up on Desktop when a user logs in.
Here is a little more about the “load default gadgets at login” script.
[Force default gadgets to load on the desktop when a user logs in]
How to force default gadgets on a users desktop, First off to get started you need to setup a profile and launch the gadgets you want on the desktop. Move them where you want them to be on the desktop so that they are placed in the areas you want them. We have dual monitors across our tech team so we placed all gadgets on second monitor.
Now go grab the config file you just created by moving and launching the gadgets you wanted. The default location for the gadget config file in a users profile is:
%userprofile%\AppData\Local\Microsoft\Windows Sidebar\Settings.ini
Lastly we create a batch file to recopy this file each time a user logs in and then launches the sidebar application.
Create a new batch file called gadgets.bat then place the following in the file.
REM @echo off
taskkill /IM sidebar.exe /f
copy /Z /Y \\myserver\myshare\Settings.ini “%userprofile%\AppData\Local\Microsoft\Windows Sidebar\”
start “” “C:\Program Files\Windows Sidebar\sidebar.exe” /autostart
Copy the Settings.ini file to a network share. Edit the “myserver” and the “myshare” to represent your network share that holds the “Settings.ini” file.
Then add it to your users login script active directory properties. You can also just copy and paste the lines in to an existing login script if your using them to do other things like mapping drives or printers and such.
Download script -> Launch Default Gadgets batch file