Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a very old program that needs the commands to be all caps. when I exit this program I often forget to put the Caps Lock off (very annoying). I had a batch program in XP that did this but can't find a way to do it in Win 7.

share|improve this question

The only way I know from cmd.exe is by spawning powershell or vbs.

Drop this at the end of your batch, it toggles CAPSLOCK

start /b /wait powershell.exe -nologo -WindowStyle Hidden -sta -command "$wsh = New-Object -ComObject WScript.Shell;$wsh.SendKeys('{CAPSLOCK}')"

That calls out to powershell via command line and invokes the sendkeys, the alternative method is to echo similar commands into a %temp% file and then wscript %temp%\my.vbs.

EDIT: Here is the IF statement to ensure it only turns capslock OFF

start /b /wait powershell.exe -nologo -WindowStyle Hidden -sta -command "IF ([console]::CapsLock -eq 'True'){$wsh = New-Object -ComObject WScript.Shell;$wsh.SendKeys('{CAPSLOCK}')}"
share|improve this answer
note: [console]::CapsLock displays current status $true or $false combined with an IF statement, you could ensure it doesn't run if capslock is already off. – Knuckle-Dragger Jan 3 '14 at 11:22
Thanks knuckle-dragger. how would I incorporate the [console] line into the if statement in the batch file (I know some Basic but not much else!)? Also, how do I get the batch file to process commands after execution of the powershell line? – Fly Right Jan 3 '14 at 15:33
added example IF statement. After the caplsock is toggled the start /wait will return focus to the batch script and run any further commands it finds. – Knuckle-Dragger Jan 4 '14 at 1:23
This is GREAT Knuckle-dragger. I have been trying to do this for years. The only problem I have is the batch file dumps out after the first line even though I have the /wait in the start commands you have indicated. What do I need to change in the following to get it to execute the second line? – Fly Right Jan 4 '14 at 21:39
start /b /wait powershell.exe -nologo -WindowStyle Hidden -sta -command "IF ([console]::CapsLock -ne 'True'){$wsh = New-Object -ComObject WScript.Shell;$wsh.SendKeys('{CAPSLOCK}')}" <<new line>> net use lpt1: \\downstairs\LaserJet /persistent:yes <<new line>> basic mainmenu <<new line>> net use lpt1: /delete <<new line>> start /b /wait powershell.exe -nologo -WindowStyle Hidden -sta -command "IF ([console]::CapsLock -eq 'True'){$wsh = New-Object -ComObject WScript.Shell;$wsh.SendKeys('{CAPSLOCK}')}" – Fly Right Jan 4 '14 at 21:52

Using JP Software's TCC/LE, which can run batch scripts of course, it's as simple as the built-in KEYBD command. So your wrapper script that you run with TCC/LE would be:

@echo off
:: Force CAPS LOCK on beforehand.
keybd /c1
call very-old-program
:: Force CAPS LOCK off afterwards.
keybd /c0
share|improve this answer
Have downloaded TCC/LE and this solves the problem perfectly. Thanks! – Fly Right Jan 9 '14 at 10:16

You can use a very small program in this page it´s free and Works fine for me. Just use "capslock on" or "capslock off" in cmd.

share|improve this answer
Please read How do I recommend software for some tips as to how you should go about recommending software. At the very least you should provide more than just a link, for example some additional information about the software itself. – DavidPostill Mar 22 '15 at 6:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .