Post Reply

Forums -> UltraMon™ -> One click UltraMon script toggle(on off)
Go20   2015-08-31 03:15
Hello, I made a batch file to complement the UltraMon Wallpaper Auto Changer 2. It adds the possibility to easily toggle on/off ANY UltraMon script with a simple shortcut. Put one in your 'UltraMon Shortcuts' folder and you can now also set a keyboard shortcut to it. For use on multiple scripts at once, duplicate the .cmd file and modify accordingly.

I tought I'd share it with you. And first ask : Is there already a better way to do this ? I did not find any. If im in the wrong park we'll leave it at that, but if this is new, I'll be happy to take more time and take your input on how to fix the current flaws.

For more info see documentation (::# comments lines) in the file content.

Create a file named "UltraMonScriptToggle.txt"(or any name you prefer), append the file content to it, then save and rename to extention .cmd

File content (copy paste):
::######## UltraMon Wallpaper On/Off Toggle ########
::# * Why? To enable ONE-CLICK on/off when using UltraMon with the script "UltraMon Wallpaper Auto Changer" OR any other UltraMon script :)
::#
::# * How it works : - IF process wscript.exe exists, terminate it. If it doesn't exist, launch the referenced script(wallpaper changer per default)
::#
::# * How to set up(V1&V2):
::# - If you choose version 2, Make sure you rename the .vbs script to a no-space name version and place it in a no-space named folder.
::# - Modify the 'start' call(V1) or the 'create' call(V2) to point to your .vbs script, example "C:\utils\UltraMonWallpaperAutoChanger2.vbs"
::# - Place a shortcut to this current .cmd you are reading on your desktop(and/or wherever).
::# - Give shortcut an integrated look and feel. (*OPTIONAL*)
::# Set a nice icon
::# - Right click your shortcut -> properties
::# - button 'Change icon'
::# Get rid of the black window that appears for a sec
::# - In the same shortcut tab, set 'Run' to 'Minimized' instead of 'Normal window'
::# - Now copy the shortcut in your preferred locations
::# - MANDATORY : if you use to use UM Wallpaper Changer script in the past, you will want to replace your previous 'Programs/Startup' short-cut with this one.
::# - NICE TO HAVE : I personally like to put a copy of that shortcut in my "UltraMon Shortcuts" folder. This way you I can set a keyboard shortcut key to toggle wallpaper changes on and off :)
::# - You may also consider putting one wherever in your startmenu.
::#
::# * Version 1 NOT compatible if you run other ultramon script under wscript.exe.
::# *Because we terminate ALL wscript.exe instance(no knowledge of the PID)
::#
::# * Version 1 works fine if you use ONLY ONE ultramon script.
::#
::# * Version 1 doesn't have the flaws of Version 2 (see below).
::#
::# * If you do decide to go with Version 1, you may go ahead and uncomment next 2 lines:
::@echo off
::tasklist /fi "ImageName eq wscript.exe" | find /i "wscript.exe" && taskkill /f /fi "ImageName eq wscript.exe" || start "" "C:\Program Files\UltraMon\UltraMon Wallpaper Auto Changer 2.vbs"
::# *** And don't forget to comment(add '::') the rest of this .cmd file lines.
::#
::#
::# Version 2 Why : Make this compatible while running other UltraMon scripts.
::# How : Save process PID in a environment variable at first launch. So we can use the PID for the terminate call.
::# *Because of this we will need to make sure we launch the script from the batch
::# file from now on, not the script directly.(example in Programs/Startup).
::# *Note this will also imply the use of an environment variable.
::#
::# Version 2 IMPORTANT NOTE : Make sure you rename the .vbs script to a no-space name version and place it in a no-space named folder.
::#
::# Precisely how it works :
::# Save its PID as environment variable every time it starts.
::# Tries to find and terminate process first, if it fails(||) = first launch, start it
::#
::# Version 2 Current Flaws : (if ever fixed, adjust above comments accordingly)
::# - Need no-space name for the .vbs script name AND location.
::# - Current way of getting PID when doing StarTscript(with 'find') takes almost 10% CPU for half a sec(because of 'find command')
::# ***This overhead will occurs once every system bootup(if in startup) and on every toggle on... Comparatively, V1 takes 1 to 3 % CPU on toggle.
::# - Use of an environment variable maybe not optimal? To save the PID I saw no other choice since we don't have an active process in this scenario.
::# Because of this last flaw, for a traceless removal of the script you'll want to manually delete the 'UM_WP_CH_PID' env variable.
::# It may as-well sit there for eternity, no arm-done.
@echo off
IF "%UM_WP_CH_PID%"=="" goto:StopScript
:StopScript
taskkill /f /pid %UM_WP_CH_PID% || goto:StartScript
goto:eof
:StartScript
for /f "tokens=2 delims==; " %%a in (' wmic process call create "wscript C:\utils\UltraMonWallpaperAutoChanger2.vbs" ^| find "ProcessId" ') do SetX UM_WP_CH_PID %%a

Go20
Go20   2015-08-31 03:22
One more thing

Want to skip all the reading and just use it?

ONLY thing you need to do is edit the part "C:\utils UltraMonWallpaperAutoChanger2.vbs" to point to the ultramon .vbs script of your choice.

Enjoy !

*Any contribution to fix the documented flaws would be appreciated.

Go20
Go20   2015-08-31 05:40
I decided to start implementing a Version 3 that will have make use of Microsoft SysInternals 'pssuspend.exe' tool. The point is to give the ability to suspend process instead of terminate. (I'm thinking suspend per default. Terminate if param given).

This new suspend method should bring compatibility to all UltraMon persistent script. *For my usage(only one script: the wall paper auto change), it did not matter to restart the process every-time but I'm guessing other scripts would want to take back where they left off, instead of being re-initiated each toggle.

Will post V3 soon.

Also note this is still a one-night project(Documentation pretty messy right now). I will clean all the comments/doc once I get approval of the concept by a Realtime Soft representative AND after the final solution is implemented. Until then, as I write these lines I'm using V2 and it's working like a charm.

By the way, nice job with UltraMon application. An awesome piece of software that lets me avoid the use of the newer cancerous windows OS.

Go20
Go20   2015-08-31 13:50
I just realized that pssuspend.exe wont cut it because we cannot(a prompt window apears).

V3 still use pssuspend.exe as it stand but I will look at other options tomorrow.

Until then here is the current V3 (with updated comments in other parts than V3 - so the whole thing)

You may now ignore the File content part of my first post and replace it with this one.

File content :
::######## Go20 UltraMon Wallpaper Changer On/Off Toggle V1, V2 and V3 (default V3) #######
::## (Toggle On or Off any persistent .vbs script (developed for usage with UltraMon by RealTimeSoft)
::## IMPORTANT : *The current content of this file must sit in a file named with .cmd or .bat extension
::#
::# * Why use this : To enable ONE-CLICK on/off when using UltraMon with the script "UltraMon Wallpaper Auto Changer" OR any other UltraMon script :)
::#
::# * How it works : - IF script is running, terminate it. If it doesn't, launch the referenced script(wallpaper changer per default)
::#
::# * How to set up(V1&V2&V3):
::# - If you choose V2/V3, Make sure you rename the .vbs script to a no-space name version and place it in a no-space named folder.
::# - Modify the 'start' call(V1), the 'create' call(V2), or the Script_Location(V3) to point to your .vbs script, example "C:\utils\UltraMonWallpaperAutoChanger2.vbs"
::# - Place a shortcut to this current .cmd you are reading on your desktop(and/or wherever).
::# - Give shortcut an integrated look and feel. (*OPTIONAL*)
::# Set a nice icon
::# - Right click your shortcut - properties
::# - button 'Change icon'
::# Get rid of the black window that appears for a sec
::# - In the same shortcut tab, set 'Run' to 'Minimized' instead of 'Normal window'
::# - Now copy the shortcut in your preferred locations
::# - MANDATORY : if you use to use UM Wallpaper Changer script in the past, you will want to replace your previous 'Programs/Startup' short-cut with this one.
::# - NICE TO HAVE : I personally like to put a copy of that shortcut in my "UltraMon Shortcuts" folder. This way you I can set a keyboard shortcut key to toggle wallpaper changes on and off :)
::# - You may also consider putting one wherever in your startmenu.
::#
::###############################################################################
::#
::# * Version 1 NOT compatible if you run other ultramon script under wscript.exe.
::# *Because we terminate ALL wscript.exe instance(no knowledge of the PID)
::#
::# * Version 1 is still the fastest version, it just lacks compatibility/features. (Its still fine if you use ONLY ONE ultramon script.)
::#
::# * Version 1 doesn't have the flaws of Version 2 and 3 (see below).
::#
::# * If you do decide to go with Version 1, you may go ahead and uncomment next 2 lines:
::@echo off
::tasklist /fi "ImageName eq wscript.exe" | find /i "wscript.exe" && taskkill /f /fi "ImageName eq wscript.exe" || start "" "C:\Program Files\UltraMon\UltraMon Wallpaper Auto Changer 2.vbs"
::#
::# *** And don't forget to comment(add '::') the rest of this .cmd file lines.
::#
::###############################################################################
::#
::# *EDIT* About V2(edit after V3): * I believe V2 is now obsolete(beside the dependency con... All comments here should be edited/merged with V3 into 2.1 maybe?
::# ... TODO ... Until then consider ALL V2 comments valid for V3 as well.
::#
::# Version 2 Why : V1 was not a viable solution for use of multiple scripts at once. V2 is.
::# How : Save process PID in a environment variable at first launch. So we can use the PID for the terminate call.
::# *Because of this we will need to make sure we launch the script from the batch
::# file from now on, not the script directly.(example in Programs/Startup).
::# *Note this also imply the script now makes use of an environment variable(may not be optimal/see 'flaws' below for more info about this).
::#
::# Version 2 IMPORTANT NOTE / REMINDER : Make sure you rename the .vbs script to a no-space name version and place it in a no-space named folder.
::#
::# Precisely how it works (if you care):
::# Save its PID as environment variable every time it starts.
::# Tries to find and terminate process first, if it fails(||) it means system startup(environement var are boot persistent...), then start it
::#
::# Version 2 Current Flaws : (if ever fixed, adjust above comments accordingly)
::# - Need no-space name for the .vbs script name AND location.
::# - Current way of getting PID when doing StarTscript(with 'find') takes almost 10% CPU for half a sec(because of 'find command')
::# ***This overhead will occurs once every system bootup(if in startup) and on every toggle on... Comparatively, V1 takes 1 to 3 % CPU on toggle.
::# - Use of an environment variable maybe not optimal? To save the PID I saw no other choice since we don't have an active process in this scenario.
::# Because of this last flaw, for a traceless removal of the script you'll want to manually delete the 'UM_TOGGLE_SCRIPT_PID' env variable.
::# It may as-well sit there for eternity, no arm-done.
::#
::# * If you do decide to go with Version 2, you may go ahead and uncomment next 7 lines:
::#@echo off
::#IF "%UM_TOGGLE_SCRIPT_PID%"=="" GOTO:ToggleScript
::#:ToggleScript
::#taskkill /f /pid %UM_TOGGLE_SCRIPT_PID% || GOTO:StartScript
::#GOTO:eof
::#:StartScript
::#for /f "tokens=2 delims==; " %%a in (' wmic process call create "wscript C:\utils\UltraMonWallpaperAutoChanger2.vbs" ^| find "ProcessId" ') do SetX UM_TOGGLE_SCRIPT_PID %%a
::#
::# *** And don't forget to comment(add '::') the rest of this .cmd file lines.
::#
::###############################################################################
::#
::# *** First off, not that all notes about V2 applies for V3 as well ***
::#
::# Version 3 Why : Give the ability to suspend instead of terminate.(Suspend per default. Terminate if argument given).
::#
::# Version 3 Pros : - Compatibility to all UltraMon persistent script(Some scripts want to take back where they
::# left-off instead of being re-initiated each toggle like V1 and V2 where doing).
::# - Should also help with CPU usage for the StartScript line(compared to V2... fastest is still V1).
::# - Added argument -f to give ability to use on any script without manually editing this .cmd file(must be last argument).
::# - Added argument /? for usage help.
::#
::# Version 3 Cons / Dependencies :
::# - Requires you to download Microsoft SysInternal package and copy it's 'pssuspend.exe' file to your C:/windows/system32 folder.
::# Download at : https://technet.microsoft.com/en-us/sysinternals/bb897540.aspx
::# * This is not really a con(no reason to doubt SysInternal), we should probably just call this a dependency ...
::#
::# Version 3 usage : - Same as V1 and V2 but you may add optional argument /t to FORCE TERMINATE instead of V3 new default behavior:suspend.
::# - Another new optional argument is available : -f pathandfilename to avoid having to manually edit this current script.
::# - Lastly, /? argument now shows help.
::#
@ECHO off
SETLOCAL
IF "%1"=="" GOTO:ToggleScript
IF "%1"=="/?" GOTO:ShowHelp
IF "%UM_TOGGLE_SCRIPT_PID%"=="" GOTO:eof
IF "%1"=="-f" GOTO:SetScriptLocation
IF "%2"=="-f" GOTO:SetScriptLocation
SET /A Script_Location=C:\utils\UltraMonWallpaperAutoChanger2.vbs
:SetScriptLocation
IF "%3"=="" GOTO:OnlyFileParam
SET /A Script_Location="%3"
GOTO:ToggleScript
:OnlyFileParam
SET /A Script_Location="%2"
:ToggleScript
IF "%1"=="/k" GOTO:ForceTerminate
IF "%2"=="/k" GOTO:ForceTerminate
pssuspend.exe -accepteula %UM_TOGGLE_SCRIPT_PID% || GOTO:StartScript
GOTO:eof
:ForceTerminate
taskkill /f /pid %UM_TOGGLE_SCRIPT_PID% || GOTO:StartScript
GOTO:eof
:ShowHelp
ECHO UltraMonScriptToggle.cmd by Mathieu Gauvin - 2015-08-31
ECHO WHAT IT DOES :
ECHO - Toggle On or Off any persistent .vbs script (developed for usage with UltraMon by RealTimeSoft.com)
ECHO DEPENDENCIES Microsoft SysInternal 'pssuspend.exe':
ECHO - Download the package at : https://technet.microsoft.com/en-us/sysinternals/bb897540.aspx
ECHO - Drag and drop 'pssuspend.exe' from the archive, to your C:/windows/system32 folder.
ECHO * Note the first time this script triggers 'pssuspend.exe', you MAY be prompt to agree.
ECHO (only first and only if -accepteula somehowfailed)
ECHO USAGE :
ECHO - If you want to enable no argument usage, edit this file and change the Script_Location to point
ECHO to the desired vbs script.(no space* see below)
ECHO * Alternativly you may use -f argument to specify a script file name(documented below).
ECHO OPTIONS ARGUMENTS :
ECHO - Use /t argument to force script termination instead of default suspend behavior.
ECHO - Use -f pathandfilename to overide default Script_Location.
ECHO * Example usage : UltramonToggleScript.cmd /t -f C:/utils/aDifferentScript.vbs
ECHO * Note : pathandfilename must be last.
ECHO * Current flaw : can't have spaces in pathandfilename.
GOTO:eof
:StartScript
for /f "tokens=2 delims==; " %%a in (' wmic process call create "wscript %Script_Location%" ^| find "ProcessId" ') do SetX UM_TOGGLE_SCRIPT_PID %%a

Go20
Christian Studer   2015-08-31 15:22
Thanks for sharing the batch file, glad to hear you like UltraMon.

I don't think there's a better way to do this, you do need to kill the script process in order to terminate the script (you can't send it a stop message for example).

Christian Studer - www.realtimesoft.com
Go20   2015-09-01 16:23
Glad to hear I didn't do this for nothing:)

I'm working on V3 so that it works as intended (unlike V3 I posted yesterday). Details about this coming in upcoming post.(notably I just figured the correct usage of PsSuspend).

Until then, workaround for V3 posted yesterday is to use the /f argument.(or use v1/v2)

More to come!

Go20
Go20   2015-09-03 05:58
Good day!

I finally have a working/postable version.

Note, I fed the /help option in a way that we shouldn't need a separate documentation anymore.

After its all said and done, you'd probably want me to start a new forum post and delete this one. Right? * But until then if anyone could use/test it with me, I would appreciate.

Also any things I should make more clear in documentation? Are you ok with me keeping the reference to your forum, and name etc into the file - and propagating it outside your forum?.

Oh my! I didn't mean to ask you all these questions. Sorry to make you work. At least I did'nt show empty handed:

Enjoy !

Filecontent :
::# NEW/FIXES 2015-09-01..03
::#
::# - Figured out 'stealth' pssuspend usage. Now V3 "works" as intended even if not using /f, unlike yesterday version.
::# - Also yesterday version wouldn't actually have worked for multiple scripts(it would have only shut down the last started one)
::# *This is now fixed (using dynamic env. var. name with the scriptfilename as unique identifier)
::# -
::# To prevent any possible unwanted lock messing around mass toggling, scripts now makes these checks :
::# - Make sure process exist before we try suspend
::# - Keep track of suspend status in a second environment variable.
::#
::# Also new :
::# - Added arguments alias with clear names (renamed existing argument to avoid confusion)
::# - Added debug modes(slow/fast/none) (available by editing file(see_Debug_Mode))
@ECHO off
SETLOCAL EnableExtensions
:: Possible values for _Debug_Mode :1."slow": pause/confirm at each operation
:: 2."fast": pause/confirm only at end
:: 3."none": never pause
SET _Debug_Mode=none
IF "%1"=="/?" GOTO:ShowHelp
IF "%1"=="/help" GOTO:ShowHelp
IF "%1"=="/c" GOTO:DoCleanup
IF "%1"=="/clean" GOTO:DoCleanup
IF "%1"=="-l" GOTO:SetScriptLocation
IF "%1"=="-location" GOTO:SetScriptLocation
IF "%2"=="-l" GOTO:SetScriptLocation
IF "%2"=="-location" GOTO:SetScriptLocation
SET _Path_And_Filename=C:\utils\UltraMonWallpaperAutoChanger2.vbs
IF "%1"=="" GOTO:DoToggleLogic
:SetScriptLocation
IF "%3"=="" GOTO:OnlyFileParam
SET _Path_And_Filename="%3"
GOTO:DoToggleLogic
:OnlyFileParam
SET _Path_And_Filename="%2"
:DoToggleLogic
ECHO DEBUG Starting DoToggleLogic. _Path_And_Filename is "%_Path_And_Filename%"
IF "%_Debug_Mode%" == "slow" pause
For %%A in ("%_Path_And_Filename%") do (
Set Var_Sufix=%%~nA
)
ECHO DEBUG _Var_Sufix extracted : "%Var_Sufix%"
IF "%_Debug_Mode%" == "slow" pause
if "!UMTOG%Var_Sufix%!"=="" GOTO:_Debug_DynVar_emptyornotset
if "!UMTOG%Var_Sufix%!"=="testvalue" GOTO:_Debug_DynVar_IsEq_testvalue
GOTO:_Debug_DynVar_MoveAlongSir
:_Debug_DynVar_emptyornotset
ECHO DEBUG emptyornotset Eqto testvalue confirmed
IF "%_Debug_Mode%" == "slow" pause
:_Debug_DynVar_IsEq_testvalue
ECHO DEBUG IsEq_testvlue Eqto testvalue confirmed
IF "%_Debug_Mode%" == "slow" pause
:_Debug_DynVar_MoveAlongSir
call SET Script_PID=%%UMTOG%Var_Sufix%%%
ECHO DEBUG Move along : Script_PID is "%Script_PID%"
IF "%_Debug_Mode%" == "slow" pause
IF "%Script_PID%"=="" GOTO:StartScript
IF "%1"=="/t" GOTO:ForceTerminate
IF "%1"=="/terminate" GOTO:ForceTerminate
IF "%2"=="/t" GOTO:ForceTerminate
IF "%2"=="/terminate" GOTO:ForceTerminate
ECHO DEBUG Checking if progress exist using "%Script_PID%"
QPROCESS %Script_PID% || GOTO:EnvVarExistButNoProcess_DoCleanAndStart
GOTO:ExistsConfirmed_DoCheckStatus
:EnvVarExistButNoProcess_DoCleanAndStart
ECHO DEBUG Env var exist but no process exists. Cleaning first(will start after)
ECHO DEBUG UMTOG%Var_Sufix%
ECHO DEBUG *AND*
ECHO DEBUG UMTOGSTA%Var_Sufix%
ECHO DEBUG Deleting...
IF "%_Debug_Mode%" == "slow" pause
REG delete HKCU\Environment /F /V UMTOG%Var_Sufix%
REG delete HKCU\Environment /F /V UMTOGSTA%Var_Sufix%
ECHO DEBUG UMTOG%Var_Sufix% and UMTOGSTA%Var_Sufix% flushed sucessfully.
ECHO DEBUG Now starting script...
IF "%_Debug_Mode%" == "slow" pause
GOTO:StartScript
:ExistsConfirmed_DoCheckStatus
ECHO DEBUG %Script_PID% Process exists confirmed. Checking env var for status...
IF "%_Debug_Mode%" == "slow" pause
call SET Script_Status=%%UMTOGSTA%Var_Sufix%%%
ECHO DEBUG Script_Status is "%Script_Status%"
IF "%_Debug_Mode%" == "slow" pause
IF "%Script_Status%"=="Running" GOTO:RunningConfirmed_DoSuspend
IF "%Script_Status%"=="Suspended" GOTO:SuspendedConfirmed_DoResume
ECHO Something wrong : "%Script_PID%" dont have valid Status :"%Script_Status%"
ECHO If you keep getting this msg and think you should't, please let me know
ECHO on the ultramon forum. I'd be glad to help you(and fix any flaw in this tool).
ECHO See /help
ECHO ############# Choose Alternate Action ###############
ECHO # -Press any key to simply terminate target script. #
ECHO # -Press CTRL+C(or click X) to do nothing. #
pause
GOTO:ForceTerminate
:RunningConfirmed_DoSuspend
ECHO DEBUG %Script_PID% Running confirmed. Now SUSPENDING...
IF "%_Debug_Mode%" == "slow" pause
SetX UMTOGSTA%Var_Sufix% "Suspended"
pssuspend.exe %Script_PID% -accepteula
ECHO DEBUG %Script_PID% Suspend Done. Changed UMTOGSTA%Var_Sufix% to "Suspended".
IF "%_Debug_Mode%" == "slow" pause
IF "%_Debug_Mode%" == "fast" pause
GOTO:eof
:SuspendedConfirmed_DoResume
ECHO DEBUG %Script_PID% Suspended Confirmed. Now RESUMING(longer than starting)...
ECHO DEBUG Resuming can easily take 5 seconds or more.
IF "%_Debug_Mode%" == "slow" pause
SetX UMTOGSTA%Var_Sufix% "Running"
ECHO DEBUG Don't like this delay? See if '/t' mode fits your needs(see '/help').
ECHO DEBUG Resuming In progress ...
call pssuspend.exe %Script_PID% -accepteula -r
ECHO DEBUG %Script_PID% Resume Done. Changed UMTOGSTA%Var_Sufix% to "Running".
IF "%_Debug_Mode%" == "slow" pause
IF "%_Debug_Mode%" == "fast" pause
GOTO:eof
:ForceTerminate
ECHO DEBUG Forcing process termination. Using PID %Script_PID%...
IF "%_Debug_Mode%" == "slow" pause
taskkill /f /pid %Script_PID% || GOTO:StartScript
ECHO DEBUG Process %Script_PID% terminated.
IF NOT "%1"=="/t" GOTO:DoCleanup
IF NOT "%2"=="/t" GOTO:DoCleanup
IF "%_Debug_Mode%" == "slow" pause
IF "%_Debug_Mode%" == "fast" pause
GOTO:eof
:DoCleanup
ECHO DEBUG Cleanup triggered. Deleting :
ECHO DEBUG UMTOG%Var_Sufix%
ECHO DEBUG *AND*
ECHO DEBUG UMTOGSTA%Var_Sufix%
ECHO DEBUG Deleting...
IF "%_Debug_Mode%" == "slow" pause
REG delete HKCU\Environment /F /V UMTOG%Var_Sufix%
REG delete HKCU\Environment /F /V UMTOGSTA%Var_Sufix%
ECHO DEBUG flushed sucessfully.
IF "%_Debug_Mode%" == "slow" pause
GOTO:eof
:ShowHelp
ECHO #############################################################
ECHO ## UltraMonScriptToggle.cmd by Mathieu Gauvin - 2015-09-02 #
ECHO ## ( Toggles On or Off target persistent .vbs script ) #
ECHO #############################################################
ECHO ## * Developed for usage with UltraMon by RealTimeSoft.com
ECHO ## * CAN be used on ANY vb script, not only ultramon script.
ECHO ## * CAN be used on multiple scripts at once.
ECHO ## * It may also be worth to mention you could easily edit this file
ECHO ## and change the 'call create wscript' to make this work on .exe
ECHO #############################################################
ECHO.
ECHO #######################
ECHO ## WHAT DOES IT DO ? ##
ECHO #######################
ECHO It toggles On or Off target persistent .vbs script.
ECHO.
ECHO To accomplish this, the tool will :
ECHO - Run the script if its not already running.
ECHO - Suspend the script if it was running.
ECHO - Resume the script if it was suspended.
ECHO.
ECHO * Along with those 3 basic things, the tool needs to keep track of process
ECHO identifiers(PID) and their status in environment variables. Because the
ECHO PID change from one boot session to another, this tool also do checks to
ECHO ensure these vars are flushed after the PID changes.
ECHO.
ECHO * For more details about the inner-works I welcome you to open this tool in
ECHO your favourite text editor and take a look at the code. May I also recommend
ECHO changing "_Debug_Mode" to "slow"(must edit file).
ECHO.
ECHO ###################
ECHO ## USAGE - WHY ? ##
ECHO ###################
ECHO To easily toggle on/off ANY UltraMon script with
ECHO a simple desktop shortcut pointing to this tool.
ECHO Put one of those shortcuts in your 'UltraMon Shortcuts' folder
ECHO and you can now also set a keyboard shortcut to toggle
ECHO you preferred ultramon script.
ECHO.
ECHO Example scenario : You are running one of the "Auto wallpaper change"
ECHO scripts. A wallpaper you liked just showed so you decided to prevent it
ECHO from changing again. Before this toggle batch existed, the suggested
ECHO way of accomplishing this was to CTRL-ALT-DEL - task manager - end process.
ECHO And you still had to have a shortcut to start it back(to automate a bit).
ECHO.
ECHO The alternatives to these painful user operation were to program your
ECHO own batch files or exe. NOT ANYMORE !
ECHO.
ECHO ########################
ECHO ## ANY DEPENDENCIES ? ##
ECHO ########################
ECHO Yes and no :
ECHO - NO, nothing if you use '/t'(force terminate)
ECHO * Not an option if target script must take back where it left off.
ECHO * For some scripts it makes no difference so if you unsure, give
ECHO it a try with '/t' and see.
ECHO - YES, for the default suspend/resume behavior you need :
ECHO Microsoft SysInternal 'pssuspend.exe':
ECHO - Download the package at :
ECHO https://technet.microsoft.com/en-us/sysinternals/bb897540.aspx
ECHO - Drag and drop 'pssuspend.exe' from zip to C:/windows/system32 folder.
ECHO * Note the first time 'pssuspend.exe' is used, you MAY be prompt.
ECHO (only first time ever and only if -accepteula somehow failed)
ECHO.
ECHO ###################
ECHO ## USAGE - HOW ? ##
ECHO ###################
ECHO If you want to enable no argument usage, edit this file and change the
ECHO '_Path_And_Filename' to point to the desired vbs script.(no space see below)
ECHO * Alternativly you may use '-l' argument to
ECHO specify a script file name(documented below).
ECHO.
ECHO ########################
ECHO ## OPTIONAL ARGUMENTS ##
ECHO ########################
ECHO - Use '/t' to force termination instead of default suspend/resume behaviour.
ECHO * Even with '/t', IF not running, script will START instead of terminate.
ECHO (BUT WHY? For On/Off with same command - One click toggle remember?)
ECHO - Use '-l' (or -filelocation) to overide default _Path_And_Filename.
ECHO * If you use both '/t' and '-l', make sure '/t' is first.
ECHO.
ECHO ####################
ECHO ## USAGE EXAMPLES ##
ECHO ####################
ECHO 'UltramonToggleScript.cmd /t -l C:/utils/anotherScript.vbs'
ECHO 'yourdognameToggle.cmd /t'
ECHO 'yourdognameToggle.cmd' (should be preferred usage)
ECHO * Notes:
ECHO - Reminder : If used,'-l pathandfilename' must be last.
ECHO - Current version does not support spaces in pathandfilename.
ECHO - For multiple scripts at once without '-l', you could make copies of
ECHO this... But know that I made '-l' to avoid the need of duplicates)
ECHO.
ECHO ############################################################
ECHO ## About SPEED/PERFORMANCE with different operating modes ##
ECHO ############################################################
ECHO Noticed the black window stays open longer when resuming ?
ECHO Here is why :
ECHO - The '/t' terminator mode takes less time to START a script
ECHO than the default resume mode. However, it use enough ressources
ECHO to notice it on your cpu usage(2..3% on my system) whereas
ECHO RESUMING seems surprisingly efficient(totally unnoticeable-0%).
ECHO
ECHO My point being :even if the window stays open a few secs, it
ECHO is important to understand it is working "slowly but efficiently".
ECHO If you want to get rid of that black window as soon as possible,
ECHO don't mind a 2% cpu jump, I then recommend using '/t'. Also keep
ECHO in mind some scripts will be incompatible with '/t' mode.
ECHO.
ECHO ##########################################
ECHO ## About traceless removal of this tool ##
ECHO ##########################################
ECHO Normal operation should'nt left anything behind but if you play
ECHO around with multiple scripts name, you may end up with leftovers
ECHO in your env vars. You can delete those manually :
ECHO - Win StartMenu search, goto/search "system environment var"
ECHO - Delete all entry with the prefix UMTOG.
ECHO - More simple? Don't delete them, no harm done.
ECHO.
ECHO #############################################################
ECHO ## UltraMonScriptToggle.cmd by Mathieu Gauvin - 2015-09-02
ECHO ## For more details see www.realtimesoft.com/multimon/forum/
ECHO ## Find 'Go20' post by searching for 'one click toggle'.
ECHO #############################################################
GOTO:eof
:StartScript
ECHO DEBUG - PROGRES NOT FOUND ? Will start process next keypress
IF "%_Debug_Mode%" == "slow" pause
for /f "tokens=2 delims==; " %%a in (' wmic process call create "wscript %_Path_And_Filename%" ^| find "ProcessId" ') do SetX UMTOG%Var_Sufix% %%a
SetX UMTOGSTA%Var_Sufix% "Running"
call ECHO DEBUG started. status var UMTOGSTA%Var_Sufix% now equal to %%UMTOGSTA%Var_Sufix%%%
call ECHO DEBUG started. pid var UMTOG%Var_Sufix% now equal to %%UMTOG%Var_Sufix%%%
IF "%_Debug_Mode%" == "slow" pause
IF "%_Debug_Mode%" == "fast" pause

Go20
Christian Studer   2015-09-03 13:24
Thanks. There's no need for a new thread, you can also link directly to the thread from the batch file. Feel free to distribute the file any way you like.

Christian Studer - www.realtimesoft.com
Go20   2015-09-04 12:14
Additionally to the usage method I describe at ":# * How to set up(V1&V2&V3): "
- standard shortcut (click toggle)
- ultramon shortcut (keyboard toggle)
- startup shortcut (auto startup at boot)

Here are some other possibilities this tool opens up :

-If for example you have a "pre gaming session" batch you run to optimize your system for gaming use, just add a ref to this tool in it. (Add the same call to your "gamin session over" batch file.)

-Another new possibility: If you want a Windows Logged event to toggle on/off a Ultramon script. For example, I saw in the "wall paper change" forum thread you answered it was impossible to stop the script when the screen saver is running. Now it can be easily done using a scheduled task triggered by Windows Log Event ID 4802 and 4803. (step by step here http://superuser.com/questions/538146/run-a-batch-cmd-upon-screensaver *See part "Using no 3rd party tools")

-Using this last "Log Event ID +Sheduled task" example, you can probably figure out lots of new automation possibilities.
For ideas see all windows events log-gables(trigger-able):
https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/Default.aspx

Go20
Go20   2015-09-04 15:39
For those of you looking to toggle on and off a script, know you can ignore all the rest of this forum tread and go with this post only :

- Fixed: "/t" mode would not trigger in last posted version. Now works as expected.

- Removed some useless debugging messages.

- Updated /help and comments.

File content (save this with .cmd extension):
::######## Go20 UltraMon Wallpaper Changer On/Off Toggle V1, V2 and V3 (default V3) #######
::## (Toggle On or Off any persistent .vbs script (developed for usage with UltraMon by RealTimeSoft.com)
::## IMPORTANT : *The current content of this file must sit in a file named with .cmd or .bat extension
::#
::# * Why use this : To enable ONE-CLICK on/off when using UltraMon with the script "UltraMon Wallpaper Auto Changer" OR any other UltraMon script :)
::#
::# * How it works : - IF script is running, suspend(or terminate) it. If its not running, launch the referenced script(wallpaper changer per default)
::#
::# * How to set up(V1&V2&V3):
::# - If you choose V2/V3, Make sure you rename the .vbs script to a no-space name version and place it in a no-space named folder.
::# - Modify the 'start' call(V1), the 'create' call(V2), or the Script_Location(V3) to point to your .vbs script, example "C:\utils\UltraMonWallpaperAutoChanger2.vbs"
::# - Place a shortcut to this current .cmd you are reading on your desktop(and/or wherever).
::# - Give shortcut an integrated look and feel. (*OPTIONAL*)
::# Set a nice icon
::# - Right click your shortcut -> properties
::# - button 'Change icon'
::# Get rid of the black window that appears for a sec
::# - In the same shortcut tab, set 'Run' to 'Minimized' instead of 'Normal window'
::# - Now copy the shortcut in your preferred locations
::# - MANDATORY : if you use to use UM Wallpaper Changer script in the past, you will want to replace your previous 'Programs/Startup' short-cut with this one.
::# - NICE TO HAVE : I personally like to put a copy of that shortcut in my "UltraMon Shortcuts" folder. This way you I can set a keyboard shortcut key to toggle wallpaper changes on and off :)
::# - You may also consider putting one wherever in your startmenu.
::#
::###############################################################################
::#
::# * Version 1 NOT compatible if you run other ultramon script under wscript.exe.
::# *Because we terminate ALL wscript.exe instance(no knowledge of the PID)
::#
::# * Version 1 is still the fastest version, it just lacks compatibility/features. (Its still fine if you use ONLY ONE ultramon script.)
::#
::# * Version 1 doesn't have the flaws of Version 2 and 3 (see below).
::#
::# * If you do decide to go with Version 1, you may go ahead and uncomment next 2 lines:
::@echo off
::tasklist /fi "ImageName eq wscript.exe" | find /i "wscript.exe" && taskkill /f /fi "ImageName eq wscript.exe" || start "" "C:\Program Files\UltraMon\UltraMon Wallpaper Auto Changer 2.vbs"
::#
::# *** And don't forget to comment(add '::') the rest of this .cmd file lines.
::#
::###############################################################################
::#
::# *EDIT* About V2(edit after V3): * I believe V2 is now obsolete(beside the dependency con... All comments here should be edited/merged with V3 into 2.1 maybe?
::# ... TODO ... Until then consider ALL V2 comments valid for V3 as well.
::#
::# Version 2 Why : V1 was not a viable solution for use of multiple scripts at once. V2 is.
::# How : Save process PID in a environment variable at first launch. So we can use the PID for the terminate call.
::# *Because of this we will need to make sure we launch the script from the batch
::# file from now on, not the script directly.(example in Programs/Startup).
::# *Note this also imply the script now makes use of an environment variable(may not be optimal/see 'flaws' below for more info about this).
::#
::# Version 2 IMPORTANT NOTE / REMINDER : Make sure you rename the .vbs script to a no-space name version and place it in a no-space named folder.
::#
::# Precisely how it works (if you care):
::# Save its PID as environment variable every time it starts.
::# Tries to find and terminate process first, if it fails(||) it means system startup(environement var are boot persistent...), then start it
::#
::# Version 2 Current Flaws : (if ever fixed, adjust above comments accordingly)
::# - Need no-space name for the .vbs script name AND location.
::# - Current way of getting PID when doing StarTscript(with 'find') takes almost 10% CPU for half a sec(because of 'find command')
::# ***This overhead will occurs once every system bootup(if in startup) and on every toggle on... Comparatively, V1 takes 1 to 3 % CPU on toggle.
::# - Use of an environment variable maybe not optimal? To save the PID I saw no other choice since we don't have an active process in this scenario.
::# Because of this last flaw, for a traceless removal of the script you'll want to manually delete the 'UM_TOGGLE_SCRIPT_PID' env variable.
::# It may as-well sit there for eternity, no harm done. (V3 clean this for you automatically)
::#
::# * If you do decide to go with Version 2, you may go ahead and uncomment next 7 lines:
::#@echo off
::#IF "%UM_TOGGLE_SCRIPT_PID%"=="" GOTO:ToggleScript
::#:ToggleScript
::#taskkill /f /pid %UM_TOGGLE_SCRIPT_PID% || GOTO:StartScript
::#GOTO:eof
::#:StartScript
::#for /f "tokens=2 delims==; " %%a in (' wmic process call create "wscript C:\utils\UltraMonWallpaperAutoChanger2.vbs" ^| find "ProcessId" ') do SetX UM_TOGGLE_SCRIPT_PID %%a
::#
::# *** And don't forget to comment(add '::') the rest of this .cmd file lines.
::#
::###############################################################################
::#
::# *** First off, note that all notes about V2 applies for V3 as well ***
::#
::# Version 3 Why : Give the ability to suspend instead of terminate.(Suspend per default. Terminate if argument given).
::#
::# Version 3 Pros : - Compatibility to all UltraMon persistent script(Some scripts want to take back where they
::# left-off instead of being re-initiated each toggle like V1 and V2 where doing).
::# - Can be used on multiple scripts at once.(without duplicating the tool)
::# - Does better with CPU usage. See notes about performance in /help.
::# - Added argument -f to give ability to use on any script without manually editing this .cmd file(must be last argument).
::# - Added argument /? for usage help.
::# - Added /help and debug (see _Debug_Mode)
::#
::# Version 3 Cons / Dependencies :
::# - Requires you to download Microsoft SysInternal package and copy it's 'pssuspend.exe' file to your C:/windows/system32 folder.
::# Download at : https://technet.microsoft.com/en-us/sysinternals/bb897540.aspx
::# * This is not really a con(no reason to doubt SysInternal), we should probably just call this a dependency ...
::# - The command prompt will remain open for a few more seconds than if you terminate even tho its done processing.
::#
::# Version 3 usage : - See above "How to set up(V1&V2&V3)"
::# - argument /t to FORCE TERMINATE instead of V3 new default behavior:suspend.
::# - Another new optional argument is available : -f pathandfilename to avoid having to manually edit this current script.
::# - Lastly, /? argument now shows help.
::#
@ECHO off
SETLOCAL EnableExtensions
::Possible values for _Debug_Mode :
:: 1."slow": pause/confirm at each operation
:: 2."fast": pause/confirm only at end
:: 3."none": never pause
SET _Debug_Mode=none
IF "%1"=="/?" GOTO:ShowHelp
IF "%1"=="/help" GOTO:ShowHelp
IF "%1"=="-l" GOTO:SetScriptLocation
IF "%1"=="-location" GOTO:SetScriptLocation
IF "%2"=="-l" GOTO:SetScriptLocation
IF "%2"=="-location" GOTO:SetScriptLocation
SET _Path_And_Filename=C:\utils\UltraMonWallpaperAutoChanger2.vbs
IF "%1"=="" GOTO:DoToggleLogic
:SetScriptLocation
IF "%3"=="" GOTO:OnlyFileParam
SET _Path_And_Filename="%3"
GOTO:DoToggleLogic
:OnlyFileParam
IF "%1"=="/t" GOTO:DoToggleLogic
SET _Path_And_Filename="%2"
:DoToggleLogic
ECHO DEBUG Starting DoToggleLogic. _Path_And_Filename is "%_Path_And_Filename%"
IF "%_Debug_Mode%" == "slow" pause
For %%A in ("%_Path_And_Filename%") do (
Set Var_Sufix=%%~nA
)
ECHO DEBUG _Var_Sufix extracted : "%Var_Sufix%"
IF "%_Debug_Mode%" == "slow" pause
if "!UMTOG%Var_Sufix%!"=="" GOTO:_Debug_DynVar_emptyornotset
GOTO:_Debug_DynVar_MoveAlongSir
:_Debug_DynVar_emptyornotset
ECHO DEBUG dyn var empty or not set
::IF "%_Debug_Mode%" == "slow" pause
:_Debug_DynVar_MoveAlongSir
call SET Script_PID=%%UMTOG%Var_Sufix%%%
ECHO DEBUG Move along : Script_PID is "%Script_PID%"
IF "%_Debug_Mode%" == "slow" pause
IF "%Script_PID%"=="" GOTO:StartScript
IF "%1"=="/t" GOTO:ForceTerminate
IF "%1"=="/terminate" GOTO:ForceTerminate
IF "%2"=="/t" GOTO:ForceTerminate
IF "%2"=="/terminate" GOTO:ForceTerminate
ECHO DEBUG Checking if progress exist using "%Script_PID%"
QPROCESS %Script_PID% || GOTO:EnvVarExistButNoProcess_DoCleanAndStart
GOTO:ExistsConfirmed_DoCheckStatus
:EnvVarExistButNoProcess_DoCleanAndStart
ECHO DEBUG Env var exist but no process exists. Cleaning first(will start after)
ECHO DEBUG UMTOG%Var_Sufix%
ECHO DEBUG *AND*
ECHO DEBUG UMTOGSTA%Var_Sufix%
ECHO DEBUG Deleting...
IF "%_Debug_Mode%" == "slow" pause
REG delete HKCU\Environment /F /V UMTOG%Var_Sufix%
REG delete HKCU\Environment /F /V UMTOGSTA%Var_Sufix%
ECHO DEBUG UMTOG%Var_Sufix% and UMTOGSTA%Var_Sufix% flushed sucessfully.
ECHO DEBUG Now starting script...
IF "%_Debug_Mode%" == "slow" pause
GOTO:StartScript
:ExistsConfirmed_DoCheckStatus
ECHO DEBUG %Script_PID% Process exists confirmed. Checking env var for status...
IF "%_Debug_Mode%" == "slow" pause
call SET Script_Status=%%UMTOGSTA%Var_Sufix%%%
ECHO DEBUG Script_Status is "%Script_Status%"
IF "%_Debug_Mode%" == "slow" pause
IF "%Script_Status%"=="Running" GOTO:RunningConfirmed_DoSuspend
IF "%Script_Status%"=="Suspended" GOTO:SuspendedConfirmed_DoResume
ECHO Something wrong : "%Script_PID%" dont have valid Status :"%Script_Status%"
:Somthing_Wrong
ECHO If you keep getting this msg and think you should't, please let me know
ECHO on the ultramon forum. I'd be glad to help you(and fix any flaw in this tool).
ECHO See /help
ECHO ############# Choose Alternate Action ###############
ECHO # -Press any key to simply terminate target script. #
ECHO # -Press CTRL+C(or click X) to do nothing. #
pause
GOTO:ForceTerminate
:RunningConfirmed_DoSuspend
ECHO DEBUG %Script_PID% Running confirmed. Now SUSPENDING...
IF "%_Debug_Mode%" == "slow" pause
SetX UMTOGSTA%Var_Sufix% "Suspended"
pssuspend.exe %Script_PID% -accepteula
ECHO DEBUG %Script_PID% Suspend Done. Changed UMTOGSTA%Var_Sufix% to "Suspended".
IF "%_Debug_Mode%" == "slow" pause
IF "%_Debug_Mode%" == "fast" pause
GOTO:eof
:SuspendedConfirmed_DoResume
ECHO DEBUG %Script_PID% Suspended Confirmed. Now RESUMING(longer than starting)...
ECHO DEBUG Resuming can easily take 5 seconds or more.
IF "%_Debug_Mode%" == "slow" pause
SetX UMTOGSTA%Var_Sufix% "Running"
ECHO DEBUG Don't like this delay? See if '/t' mode fits your needs(see '/help').
ECHO DEBUG I prefer to make a shortcut to this file and then change 'Run' option
ECHO DEBUG to 'Minimized'(in the shortcut properties).
ECHO DEBUG Resuming In progress ...
call pssuspend.exe %Script_PID% -accepteula -r
ECHO DEBUG %Script_PID% Resume Done. Changed UMTOGSTA%Var_Sufix% to "Running".
IF "%_Debug_Mode%" == "slow" pause
IF "%_Debug_Mode%" == "fast" pause
GOTO:eof
:ForceTerminate
ECHO DEBUG Forcing process termination. Using PID %Script_PID%...
IF "%_Debug_Mode%" == "slow" pause
taskkill /f /pid %Script_PID% || GOTO:StartScript
ECHO DEBUG Process %Script_PID% terminated.
IF NOT "%1"=="/t" GOTO:DoCleanup
IF NOT "%2"=="/t" GOTO:DoCleanup
IF "%_Debug_Mode%" == "slow" pause
IF "%_Debug_Mode%" == "fast" pause
GOTO:eof
:DoCleanup
ECHO DEBUG Cleanup triggered. Deleting :
ECHO DEBUG UMTOG%Var_Sufix%
ECHO DEBUG *AND*
ECHO DEBUG UMTOGSTA%Var_Sufix%
ECHO DEBUG Deleting...
IF "%_Debug_Mode%" == "slow" pause
REG delete HKCU\Environment /F /V UMTOG%Var_Sufix%
REG delete HKCU\Environment /F /V UMTOGSTA%Var_Sufix%
ECHO DEBUG flushed sucessfully.
IF "%_Debug_Mode%" == "slow" pause
GOTO:eof
:ShowHelp
ECHO #############################################################
ECHO ## UltraMonScriptToggle.cmd by Mathieu Gauvin - 2015-09-02 #
ECHO ## Toggles On or Off target persistent .vbs script #
ECHO #############################################################
ECHO ## * Developed for usage with UltraMon by RealTimeSoft.com
ECHO ## * CAN be used on ANY vb script, not only ultramon script.
ECHO ## * CAN be used on multiple scripts at once.
ECHO ## * It may also be worth to mention you could easily edit this file
ECHO ## and change the 'call create wscript' to make this work on .exe
ECHO #############################################################
ECHO.
ECHO #######################
ECHO ## WHAT DOES IT DO ? ##
ECHO #######################
ECHO It toggles On or Off target persistent .vbs script.
ECHO.
ECHO To accomplish this, the tool will :
ECHO - Run the script if its not already running.
ECHO - Suspend the script if it was running.
ECHO - Resume the script if it was suspended.
ECHO.
ECHO * Along with those 3 basic things, the tool needs to keep track of process
ECHO identifiers(PID) and their status in environment variables. Because the
ECHO PID change from one boot session to another, this tool also do checks to
ECHO ensure these vars are flushed after the PID changes.
ECHO.
ECHO * For more details about the inner-works I welcome you to open this tool in
ECHO your favourite text editor and take a look at the code. May I also recommend
ECHO changing "_Debug_Mode" to "slow"(must edit file).
ECHO.
ECHO ###################
ECHO ## USAGE - WHY ? ##
ECHO ###################
ECHO ## Manual toggling ##
ECHO.
ECHO To easily toggle on/off ANY UltraMon script with
ECHO a simple desktop shortcut pointing to this tool.
ECHO Put one of those shortcuts in your 'UltraMon Shortcuts' folder
ECHO and you can now also set a keyboard shortcut(using ultramon GUI) to toggle
ECHO you preferred ultramon script.
ECHO.
ECHO Example scenario : You are running one of the "Auto wallpaper change"
ECHO scripts. A wallpaper you liked just showed so you decided to prevent it
ECHO from changing again. Before this toggle batch existed, the suggested
ECHO way of accomplishing this was to CTRL-ALT-DEL - task manager - end process.
ECHO And you still had to have a shortcut to start it back(doing half the job).
ECHO.
ECHO The alternatives to these painful user operation were to program your
ECHO own batch files or exe. NOT ANYMORE !
ECHO.
ECHO ## Triggered toggling ##
ECHO.
ECHO Following on the previously described auto wallpaper changing scenario.
ECHO If you'd like to the script be toggled off automatically when the
ECHO screen saver is invoked(and back on when dismissed): you can simply
ECHO reference this tool in a Windows Sheduled Task and have that task trigged
ECHO on "Log Event ID" 4802 and 4803. First you will need to make sure your
ECHO system is logging those 2 events. The specific steps are described here:
ECHO http://superuser.com/questions/538146/run-a-batch-cmd-upon-screensaver
ECHO *See part "Using no 3rd party tools")
ECHO.
ECHO With the last described example scenario in mind, you can you can probably
ECHO figure out lots of new automation possibilities.
ECHO *For ideas, see all windows events log-gables(trigger-able) here:
ECHO https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/Default.aspx
ECHO.
ECHO ###################
ECHO ## USAGE - WHY ? ##
ECHO ###################
ECHO How to set up(V1&V2&V3):
ECHO -If you choose V2/V3, Make sure you rename the .vbs script to a no-space
ECHO name version and place it in a no-space named folder.
ECHO - Modify the 'start' call(V1), the 'create' call(V2), or the
ECHO Script_Location(V3) to point to your .vbs script, example
ECHO "C:\utils\UltraMonWallpaperAutoChanger2.vbs"
ECHO - Place a shortcut to this current .cmd you are reading on your
ECHO desktop(and/or wherever you preffer).
ECHO - Give the shortcut an integrated look and feel. (*OPTIONAL*):
ECHO Set a nice icon :
ECHO - Right click your shortcut -> properties .
ECHO - Click button 'Change icon'.
ECHO Get rid of the black window that appears for a sec :
ECHO - Still in the shortcut tab in shortcut tab, set 'Run' to 'Minimized'.
ECHO - Now copy the shortcut in your preferred locations.
ECHO - MANDATORY : if you use to use UM Wallpaper Changer script in the
ECHO past, you will want to replace your previous 'Programs/Startup'
ECHO short-cut with this one.
ECHO * NICE TO HAVE : I personally like to put a copy of that shortcut in
ECHO my "UltraMon Shortcuts" folder. This way you I can set a keyboard
ECHO shortcut key to toggle wallpaper changes on and off.
ECHO * You may also consider putting one wherever in your startmenu.
ECHO.
ECHO ########################
ECHO ## ANY DEPENDENCIES ? ##
ECHO ########################
ECHO Yes and no :
ECHO - NO, nothing if you use '/t'(force terminate)
ECHO * Not an option if target script must take back where it left off.
ECHO * For some scripts it makes no difference so if you unsure, give
ECHO it a try with '/t' and see.
ECHO - YES, for the default suspend/resume behavior you need :
ECHO Microsoft SysInternal 'pssuspend.exe':
ECHO - Download the package at :
ECHO https://technet.microsoft.com/en-us/sysinternals/bb897540.aspx
ECHO - Drag and drop 'pssuspend.exe' from zip to C:/windows/system32 folder.
ECHO * Note the first time 'pssuspend.exe' is used, you MAY be prompt.
ECHO (only first time ever and only if -accepteula somehow failed)
ECHO.
ECHO ###################
ECHO ## USAGE - HOW ? ##
ECHO ###################
ECHO If you want to enable no argument usage, edit this file and change the
ECHO '_Path_And_Filename' to point to the desired vbs script.(no space see below)
ECHO * Alternativly you may use '-l' argument to
ECHO specify a script file name(documented below).
ECHO.
ECHO ########################
ECHO ## OPTIONAL ARGUMENTS ##
ECHO ########################
ECHO - Use '/t' to force termination instead of default suspend/resume behaviour.
ECHO * Even with '/t', IF not running, script will START instead of terminate.
ECHO (BUT WHY? For On/Off with same command - One click toggle remember?)
ECHO - Use '-l' (or -filelocation) to overide default _Path_And_Filename.
ECHO * If you use both '/t' and '-l', make sure '/t' is first.
ECHO.
ECHO ####################
ECHO ## USAGE EXAMPLES ##
ECHO ####################
ECHO 'UltramonToggleScript.cmd /t -l C:/utils/anotherScript.vbs'
ECHO 'yourdognameToggle.cmd /t'
ECHO 'yourdognameToggle.cmd' (should be preferred usage)
ECHO * Notes:
ECHO - Reminder : If used,'-l pathandfilename' must be last.
ECHO - Current version does not support spaces in pathandfilename.
ECHO - For multiple scripts at once without '-l', you could make copies of
ECHO this... But know that I made '-l' to avoid the need of duplicates)
ECHO.
ECHO ############################################################
ECHO ## About SPEED/PERFORMANCE with different operating modes ##
ECHO ############################################################
ECHO Noticed the black window stays open longer when resuming ?
ECHO Here is why :
ECHO - The '/t' terminator mode takes less time to START a script
ECHO than the default resume mode. However, it use enough ressources
ECHO to notice it on your cpu usage(2..3% on my system) whereas
ECHO RESUMING seems surprisingly efficient(totally unnoticeable-0%).
ECHO
ECHO My point being :even if the window stays open a few secs, it
ECHO is important to understand it is working "slowly but efficiently".
ECHO If you want to get rid of that black window as soon as possible and
ECHO don't mind a 2% cpu jump, I then recommend using '/t'. Also keep
ECHO in mind some scripts will be incompatible with '/t' mode.
ECHO
ECHO Recommended : You should be running this tool from a shortcut. In that
ECHO shortcut properties, set the option 'Run' to 'Minimized'.
ECHO.
ECHO ##########################################
ECHO ## About traceless removal of this tool ##
ECHO ##########################################
ECHO Normal operation should'nt leave anything behind, but IF you play
ECHO around with multiple scripts name, you may end up with leftovers
ECHO in your env vars. You can delete those manually :
ECHO - Win StartMenu search, goto/search "system environment var"
ECHO - Delete all entry with the prefix UMTOG.
ECHO - More simple? Don't delete them, no harm done.
ECHO.
ECHO #############################################################
ECHO ## UltraMonScriptToggle.cmd by Mathieu Gauvin - 2015-09-02
ECHO ## For more details see www.realtimesoft.com/multimon/forum/
ECHO ## Find 'Go20' post by searching for 'one click toggle'.
ECHO #############################################################
GOTO:eof
:StartScript
ECHO DEBUG - PROGRES NOT FOUND ? Will start process next keypress
IF "%_Debug_Mode%" == "slow" pause
for /f "tokens=2 delims==; " %%a in (' wmic process call create "wscript %_Path_And_Filename%" ^| find "ProcessId" ') do SetX UMTOG%Var_Sufix% %%a
SetX UMTOGSTA%Var_Sufix% "Running"
call ECHO DEBUG started. status var UMTOGSTA%Var_Sufix% now equal to %%UMTOGSTA%Var_Sufix%%%
call ECHO DEBUG started. pid var UMTOG%Var_Sufix% now equal to %%UMTOG%Var_Sufix%%%
IF "%_Debug_Mode%" == "slow" pause
IF "%_Debug_Mode%" == "fast" pause

Go20
Forums -> UltraMon™ -> One click UltraMon script toggle(on off)

Post Reply