CMDH - command processor running in a hidden window.
This tiny tool helps to run a command line or a batch file in background without popping up CMD window.
CMDH utility launches command interpreter (CMD) in a hidden window. Running command processor in hidden window could be useful in cases if you want:
CMDH could replace any CMD call. It uses the same format and set of options provided by CMD. There is only one exception to that list: /C and /K options. Command processor running in hidden window should terminate itself automatically as soon as requested processing is completed. Therefore, when CMDH launches system provided CMD, it adds option /C automatically. It means that you should not specify neither /C option nor /K in command line.
cmdh [[/s] [/q] [/d] [{/a|/u}] [/t:fg] [/e:{on|off}] [/f:{on|off}] [/v:{on|off}] string]
Some of the options provided loose its sense in a hidden window and that should be considered when you try to use them. The most interesting part of the list of option of cause is string. It specifies the command you want to carry out. It could be a CMD direct command (for example: copy file1 file2 - to copy a file) or it could be any other program or a BAT/CMD file.
There are several practical examples below that you may found useful and use them with your applications too.
In all examples provided below it's assumed that program file cmdh.exe is located in folder C:\WINDOWS\CMD. If it's put in any other place - edit registry files accordingly.
You may want list a directory into a file (Dir.txt) within that directory by making right click on it in Windows Explorer and choosing new menu item - DIR to Dir.txt. CMDH will execute command DIR in hidden CMD window and redirect resulting output into file.
To add the new option into context menu of Windows Explorer run this registry file (WE_RtClk-Dir.reg):
REGEDIT4 [HKEY_CLASSES_ROOT\Folder\shell\DIR to Dir.txt\command] @="C:\\WINDOWS\\CMD\\cmdh DIR /a/s \"%L\" > \"%L\\Dir.txt\""If you want to remove the new menu item - run this registry file (WE_RtClk-Dir-.reg):
REGEDIT4 [-HKEY_CLASSES_ROOT\Folder\shell\DIR to Dir.txt]
Without using CMDH you would see flashing black CMD window when you execute the request.
If you want to be able to add a file into security zone 3 (Internet) you may want to add this new menu item in Windows Explorer context menu: Add to zone 3. Next time you try to use the file (put in 'Zone 3') you will get a dialog box warning you that the publisher could not be verified and asking how to proceed with it. It could be an additional layer of security protection form potentially insecure files.
To add the new menu item into Windows Explorer context menu run this registry file (WE_AddToZone3.reg):
REGEDIT4 [HKEY_CLASSES_ROOT\*\shell\Add to Zone 3] "Extended"="" [HKEY_CLASSES_ROOT\*\shell\Add to Zone 3\command] @="C:\\WINDOWS\\CMD\\cmdh ECHO [ZoneTransfer]>\"%L\":Zone.Identifier&ECHO ZoneId=^3>>\"%L\":Zone.Identifier"
New menu item is added into Extended menu. Keep in mind that to access the Extended menu you have locate the file on the right side of Windows Explorer, press SHIFT button and make right click on that file.
If you want to remove new menu item - run this registry file (WE_AddToZone3-.reg):
REGEDIT4 [-HKEY_CLASSES_ROOT\*\shell\Add to Zone 3]
Some programs may keep lot of unnecessary processes/services running when you don't use then. They just waste computer resources, making it run slow and, in some cases, unstable. For example, VMware program, when you're not using it, keeps a lot of services running. You may create a simple wrapper (BAT file that launches the program) and get rid of that waste. You make a shortcut to the wrapper and run it when you want program to start. Then when you done, you close the program and wrapper automatically frees computer from unnecessary services and programs.
Here is example of shortcut launching wrapper managed VMware v.6.5:
Name : VMware - Mngr Target : C:\WINDOWS\CMD\cmdh.exe "D:\VM\VMWare\VM Mgr.bat"
@echo off title VM Mgr :: Applied for VM Workstation v.6.5 echo Starting services... sc start "VMnetuserif" sc start "vmx86" sc start "hcmon" ::sc start "ufad-ws60" <-- is not started by default :: Next depends on vmx86: sc start "VMAuthdService" sc start "vmci" ::sc start "vmkbd" <- NOT_STOPPABLE, bug sc start "VMnetBridge" :: Next depends on VMnetuserif: sc start "VMnetDHCP" sc start "vmparport" :: Next depends on VMnetuserif: sc start "VMware NAT Service" sc start "vstor2-ws60" sc start "VMUSBArbService" :: Check list of available adapters: ::devcon enable *VMnetAdapter1 ::devcon enable *VMnetAdapter8 ::sc start "VMnetAdapter" echo. echo ------------------------------------------- echo Running vmware.exe. Wait until it's done... "C:\Program Files\VMware\VMware Workstation\vmware.exe" echo ------------------------------------------- ::sc stop "VMnetAdapter" ::devcon disable *VMnetAdapter8 ::devcon disable *VMnetAdapter1 :: Kill the persistent process: call pskill vmware-tray.exe echo. echo Stopping services... sc stop "VMUSBArbService" sc stop "vstor2-ws60" sc stop "VMware NAT Service" sc stop "vmparport" sc stop "VMnetDHCP" sc stop "VMnetBridge" :: sc stop "vmkbd" <- NOT_STOPPABLE, bug sc stop "vmci" sc stop "VMAuthdService" ::sc stop "ufad-ws60" <-- is not started by default sc stop "hcmon" sc stop "vmx86" sc stop "VMnetuserif" echo. echo Done... ::pause
As you can see - BAT file automatically stops a dozen of services when you don't need them. As a result - computer runs faster and you have more resources available when you stop using VMware. All necessary services will be started right before you next time run VMware program.
SandboxIE could be a very useful tool to run programs in a virtual environment. It requires a special service to run and usually sets extra menu items in Windows Explorer. Unfortunately it keeps service running and extra menu items in Windows Explorer context menu even if you are not going to use it.
There is an easy way to allow SandboxIE use those resources only when you need it and free them back when you don't. It could be done with a wrapper.
Let's make a wrapper that will make preparations for running SandboxIE:
After that you may use SanboxIE to run programs. When you done just exit the SbieCtrl.exe program (you may find its icon in systray) and wrapper will reverse the process:
Here is example of the wrapper file (SandboxIE-Ctrl.bat) that does all of the above:
@echo off title SB-Ctrl Manager :: WE command is @="C:\Program Files\Sandboxie\Start.exe" /box:__ask__ "%1" %* reg add HKCR\exefile\shell\sandbox\command /ve /d "\"C:\Program Files\Sandboxie\Start.exe\" /box:__ask__ \"%%1\" %%*" /f > nul reg add HKCR\exefile\shell\sandbox /ve /d "Run Sandboxed" /f > nul reg add HKCR\comfile\shell\sandbox\command /ve /d "\"C:\Program Files\Sandboxie\Start.exe\" /box:__ask__ \"%%1\" %%*" /f > nul reg add HKCR\comfile\shell\sandbox /ve /d "Run Sandboxed" /f > nul reg add HKCR\batfile\shell\sandbox\command /ve /d "\"C:\Program Files\Sandboxie\Start.exe\" /box:__ask__ \"%%1\" %%*" /f > nul reg add HKCR\batfile\shell\sandbox /ve /d "Run Sandboxed" /f > nul reg add HKCR\cmdfile\shell\sandbox\command /ve /d "\"C:\Program Files\Sandboxie\Start.exe\" /box:__ask__ \"%%1\" %%*" /f > nul reg add HKCR\cmdfile\shell\sandbox /ve /d "Run Sandboxed" /f > nul sc start SbieSvc echo Running SbieCtrl.exe. Wait until it exits... "C:\Program Files\Sandboxie\SbieCtrl.exe" sc stop SbieSvc reg delete HKCR\cmdfile\shell\sandbox /f > nul reg delete HKCR\batfile\shell\sandbox /f > nul reg delete HKCR\comfile\shell\sandbox /f > nul reg delete HKCR\exefile\shell\sandbox /f > nul :: Clean up in case of a first run: reg delete HKCR\*\shell\sandbox /f > nul reg delete HKCR\Folder\shell\sandbox /f > nul
You may put it, for example, into SandboxIE installation folder.
BAT file runs just fine, but when you start it:
To solve the problem - let's make a shortcut and run it using cmdh tool. The shortcut could be with this target:
C:\WINDOWS\CMD\cmdh.exe "C:\Program Files\Sandboxie\SandboxIE-Ctrl.bat"
Open its Properties box and set it to run Minimized.
Now, when you launch the shortcut - it runs the wrapper in a hidden CMD window. As a result - you don't see annoying black window and, therefore, you will not close it accidentally. And more importantly, SandboxIE now uses computer resources only when you need it to run.
You can run AceMoney as a portable application from USB drive. In this case it will not require any installation. You put it on your USB drive and then run from it on any computer. There will be no changes in registry of that computer when you close the program.
To make it portable:
[HKEY_CURRENT_USER\Software\MechCAD\AceMoney\Registration] "UserName"="your user name" "SerialNumber"="your key"
@echo off :: Running AceMoney as portable application setlocal set keyAM=HKCU\Software\MechCAD set keyReg=HKCU\Software\MechCAD\AceMoney\Registration set dataUN="your user name" set dataSN=your key :: Prepare the environment: reg add %keyReg% /v UserName /d %dataUN% reg add %keyReg% /v SerialNumber /d %dataSN% call AceMoney.exe Sample.mmw :: Restore the environment: reg delete %keyAM% /f endlocal
Replace strings in red with your values taken from step 2 and specify your data file that you want to use (replace Sample.mmw with that name).
Target: H:\AceMoney\cmdh.exe AM-Mgr.bat Start in: H:\AceMoneywhere: H:\AceMoney example of the folder where you put your portable AceMoney
Test it by running RunAM shortcut. It will start AM-Mgr.bat file in hidden window and launch AceMoney.exe with your data file. When you finish editing data file - just close AceMoney and the wrapper AM-Mgr.bat will remove any residue from registry.
In case if you see that computer assigns a different drive letter (different from the example - 'H:' used above) every time you insert your USB drive and because it may create problems for your shortcut (it has to use a specific drive letter inside) - there is a simple solution. Create RunAM.BAT file with this content:
@echo off start cmdh AM-Mgr.bat
Then run it instead of the shortcut. This BAT file will start AM-Mgr.bat file and exit immediately (perhaps flashing on the screen for a moment).
Note: running AM-Mgr.bat by cmdh.exe allows to hide its window from taskbar. Thus, you'll not close it by a mistake before you want to close the AceMoney program.
Even if you check Show hidden devices option in Device Manager it doesn't show you all devices. To force Device Manager to show all computer devices you have to set specific environment variable and then start it with that variable being set. See details: KB315539.
This example adds to context menu of My Computer new item All Devices. When you choose that menu item - CMDH will set environment variable and start Device Manager console with that variable. To add that menu item run registry file (WE_MyComp-AllDevices.reg):
REGEDIT4
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\All Devices\command]
@="C:\\WINDOWS\\CMD\\cmdh set DEVMGR_SHOW_NONPRESENT_DEVICES=1&start devmgmt.msc"
If you want to remove the new menu item - run this registry file (WE_MyComp-AllDevices-.reg):
REGEDIT4
[-HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\All Devices]
Download: CMDH-1.1.zip
Size: 8,192 bytes (8.0 KiB)
CRC32: 2a427a75; MD5: 215f85061e0f96ca00699832dd619582
Download: CMDH-1.0.zip
Size: 27,648 bytes (27.0 KiB)
CRC32: bd6e8d08; MD5: 1e662b398c70a6a49a1473c74cedee02
| Last modified: 2012-01-10 | Copyright © 2000-2012 Gate2NET. All Rights Reserved. |