Minimizing or closing a program with batch script - windows

I am writing a batch script intended for handling some tasks in my (and a few colleagues) windows startup. The main thing that needs to happen is the killing of a few processes that do to this being a large corporate environment are started as default. They interfere with our work so we have to kill them... I know it's stupid but thats beside the point. This is can not be changed and we have to make due.
I thought about adding some more useful functionality to the script, like starting up certain programs and so on. This all works decently well but the problem i have is that the OUClient won't start minimized. It doesn't open a window (so it is minimized to some extent) but it still appears in the alt-tab list, witch it doesn't when i minimize or close it manually. This is the script:
#echo off
C:
cd "C:\Program Files\SysInternals\"
pskill flxps12.exe
pskill flxps17.exe
start /minimized "" "C:\Program Files\Osiris Data\OUClient\OUClient.exe"
start "Outlook" "C:\Program Files\Microsoft Office\OFFICE11\OUTLOOK.EXE"
start "Explorer" "C:\Program Files\Internet Explorer\iexplore.exe"
cls
#exit
So the question is: How can I make the OUClient minimize, or even better close to the system tray (like if you clicked the red x in the upper right) after it is started.
We are running this on Windows XP SP2.
EDIT: Everything works fine except the /minimize on OUClient.

There is no way to do this from batch files directly, but you can write a little helper program which finds a window and then uses ShowWindow to minimize it. Unfortunately this doesn't seem to be easily available from VBScript which would have made this a little easier.

The minimized switch has a forward slash, not a backslash.
I don't know if OUClient will respect that, but it should.

Have you had a look at the TASKKILL command? A basic example would be
TASKKILL /IM /F iexplore.exe
(yes, who wouldn't want to kill iexplore? ;-))
Best.

Related

Run windows batch script on file change

As part of the corporate policy I'm forced to look at ugly, branded wallpaper and manual change is turned off, as being managed by the company. I have come up with a following script, that when run, changes the wallpaper. It is based on swapping the file that is used by the company theme.
set tapeta="C:\my_wallpaper\Branding.JPG"
copy /Y %tapeta% C:\bin\Branding\Wallpaper
rem taskkill /im explorer.exe /f
rem start explorer.exe
RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters 1, True
The commented out part works every time, but has a side effect of closing all open folders. The next line works sometimes.
The real problem is, the managed system replaces the file back every now and then - sometimes few times a day. This means I have to run this script manually few times a day. Is there a way to run the script on file change? Or is there any other way to solve this?
Cheers

Run Explorer as the Admin Account In the Standard User's Environment

This is more of a pet project, as I like to try my best to batch script whatever I feel like without using a 3rd party app. I understand it would be easier that way, but I want to just try this for the heck of it. I understand the basic issue might just be the way the shell executes explorer, as I know it was NOT intended to run like this.
I have a standard user account and a batch script:
#echo OFF
FOR /F "usebackq" %%i IN (`hostname`) DO SET COMPNAME=%%i
ECHO Computer %COMPNAME%
TASKKILL /F /IM explorer.exe
runas /user:"%COMPNAME%"\ADMIN "C:\Windows\System32\cmd.exe"
Echo.
Echo Press Enter once you are finished
Pause
TASKKILL /F /IM explorer.exe
explorer.exe
Exit
Basically each computer's name is the hostname of the computer, so I created a variable to process that. Then I have it kill explorer, then run CMD as the admin account. (I can replace this with Explorer as well.) Then when CMD opens I type explorer.exe and it opens the admin account with full access. The script runs fine, no issues at all with the script. But in regards to the environment, there are 2 issues I am running into.
Windows 7 everything works fine, every program I open is ADMIN, even the start menu user profile title at the top right of the start menu says ADMIN, until I open Administrative tools, then every application I open from there uses the standard user, such as computer management. I assume explorer processes the command off of the local user environment which is why. I know I can just use compmgmt as an admin to solve that, but I want to know the specific reason why Explorer is swapping, is it as simple as the shell uses the local environment and that is just how it is?
On Windows 10, the script process successfully, but Explorer runs extremely slow. Every other program runs fine, cmd, compmgmt, regedit, Firefox, etc... But Explorer is slow, I'm talking 5 minutes to open the favorites window, and the start menu will not open at all. I checked process explorer and nothing takes it up, except the standard get resolution and other graphic handles. I assume it might be just the way this Shell operates.
Anyway, I understand this is not ideal, and that there are far easier ways to do it, and that Explorer.exe was never intended to be run like this. I just wanted to try for my own personal creativity. Any help would be greatly appreciated.
Thanks,

Batch force windows calculator to close in Windows 10

I have three monitors, and I like to play SMITE in triple surround. To do this the NVIDIA Control Panel wants me to close a few (to me random) applications before it can do its magic. This is all good and well, but the calculator application is a pain to close. I have to use the task manager to force the process to stop, because for some reason it doesn't always by itself.
I want to use a batch script for this, so it will close automatically with only a single double click (along with some other applications that sometimes do and sometimes don't need to be closed)
But since the calculator isn't just a simple .exe, I can't figure out how to shut it down. What I've found for a regular process is taskkill /f /im processname.exe but, the calculator doesn't have a simple .exe I can kill. The default Windows 10 apps have odd names, and are technically file folders according to their properties.
Can somebody help me with how to kill the Windows apps processes via batch (or something else if that's better)?
Windows Calculator's executable is located (for me) at
C:\Program Files\WindowsApps\Microsoft.WindowsCalculator_10.1611.3123.0_x86__8wekyb3d8bbwe
\calculator.exe
that program is launched by calc.exe. You can terminate Windows Calculator with:
taskkill /f /im calculator.exe
Instead use Stop-Process -Name calculator

Windows batch start up script to move windows

I'm experienced with many different programming languages. I decided to expand my horizons and try some simple batch scripts. I have a windows start up script that I'm running.
startupScript.bat
start "" "explorer.exe"
start "" "explorer.exe"
start "" "taskmgr.exe"
start "" "cmd.exe"
start "" "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
Works great. I would like to be able to move the windows where I want them though. I'm running 5 monitors, and I want the two explorer windows on my bottom left monitor each taking half the screen. I want the command prompt and task manager in my top left monitor each taking half of the screen, and I want my chrome browser on my bottom right monitor taking up the whole screen.
Chrome remembers where it was, so that isn't a problem. The other windows don't though.
Is there a way for me to run keystrokes after each program is started? I could do "winkey+left", "winkey+left", etc... for each window if that's possible. Otherwise how might I accomplish this?
Also, when the command line is run, the properties go to defaults. Is there a way to use my command line settings so that it is sized right, has quick edit mode enabled, and has the colors that I set it to?
I'd try setting up a shortcut to the application with shortcut/Run=normal window; layout and hues to taste. Then start the shortcut (.lnk file) in your batch. Certainly works for cmd - can't say for the others...
I would have a look at AutoHotKey. I don't remember enough to tell you what your script should look like, but the little I remember tells me all you need is in their toolbox.

How to close Windows Explorer from CMD

Is it possible to close Windows Explorer from CMD? I have a batch that does this: it will change directory, open explorer in this folder, than run a program. After the user closes the program the batch should close the explorer (or all explorers opened), continue on next folder (cd folder), run the same program in this folder and so on. Till the last folder is processed.
Close the explorer windows by killing the explorer process (note that this may do more than just kill the windows, but it will definitely do that):
for example, use win+r and try this
cmd /c "taskkill /f /im explorer.exe && start explorer"
If you kill explorer without restarting it, use Ctrl+shift+Esc to pull up the taskmanager and start a new task "explorer".
Not from a batch file unless you want to write your own command line application that opens up a windows explorer window, and (this is the key part) somehow knows the window handle of that explorer window, so it can post a WM_CLOSE message to it, which basically simulates someone closing that window.
How you would determine "all the explorer windows that got opened" would be that instead of just starting explorer.exe instances from a command line you would do it from your own application.
I think that determining the window handle (HWND in win32 api terms) and posting a close message would be better than trying to track process handles and terminating explorer process instances, since that could cause some side effects beyond those that you'd want.

Resources