Run windows batch script on file change - windows

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

Related

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

Can you run Windows batch file not in a command prompt?

My programming teacher is requiring that everyone participate in the science fair this year, and now they accept computer-related projects. So, knowing only one language (Windows batch), I asked if I could make some kind of text based game in batch code. She said that I can only write the code, but not execute it.
She said that if we're even caught on the command prompt, we apparently get in big trouble and never get access to a school computer for the rest of the time I'm at the high school, or something like that... Even if all the code contains is a bunch of echos and simple variables, she won't let me and my partner run it. She also said that we must work on the project during school in her class.
So to sum all that up, she's letting me write a game/program, but I'm not allowed to test it to make sure it works in school, which will be when I'm writing it most...
So is there any way to run/test a batch script with simple echo and set /p commands without the "dangerous, black command prompt" showing up?
I think she has no idea what she's talking about, because on the board, she wrote "back script" lol
A batch file runs like any other executable file by double-clicking the file within Windows. However, because a batch file runs in a command line it immediately exits when done, so you may only see a black box for a second.
If the batch file is closing too fast, or you want to read the output from the batch file you can edit the batch file and add a pause to the end of the file. The pause command waits for user input before continuing.
A .BAT file can be made into a .EXE or .COM file to keep the program's source hidden from a user. You could use the .BAT to .EXE converter file to convert the batch files to .EXE file. In this program you can point to the batch file you want to convert into an executable file, include additional files, change the icon of the file, and add file details.
For Information on Batch files, this is one of the best resource.
Try this:
#echo off
color F0
mode con lines=25 cols=60
cls
title "Notepad - MyProgram.bat"
set /P "name=What is your name? "
echo Hello %name%, glad to see you...
pause
Execute it via a double click or enter in files browser...

Windows task scheduler: save a text file

Gist: I want a task scheduled that just saves an existing text file every 15 minutes.
I used the task scheduler to create a task and when I'm in the area where I add actions, I'm stuck. I know, this sounds stupid.
I chose start a program and set the program to "C:\Windows\System32\notepad.exe". I don't know what to put in the Arguments or Start in. I'm thinking I should put the path to the file, but that would just open it, right? I want it saved. I tried adding a -s /s or whatever but it doesn't seem to work.
Very interesting. Try moving file to itself by "cmd /c move file.txt file.txt". You are correct that opening file in notepad would need you to save it. however I would like to say no file, even if some changes being made to it, need to be saved. In my understanding if any application that is making change to the file is actually writing to it permanently.

Minimizing or closing a program with batch script

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.

Resources