Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SendKeys and Command prompt window problem

5,893 views
Skip to first unread message

Luigino Rossi

unread,
Mar 13, 2004, 11:27:42 AM3/13/04
to
I'm trying to minimize a command prompt window using SendKeys:
wshShell.AppActivate("Command Prompt");
wshShell.SendKeys("%( ){DOWN}{DOWN}{DOWN}{ENTER}");
but the characters Alt+Space do not open the window's menu so the
others characters are sent into the window and not to the menu.

I hope anyone could help me, thanks B-)

Austin M. Horst

unread,
Mar 13, 2004, 1:56:05 PM3/13/04
to
wshShell.AppActivate("Command Prompt");
wshShell.SendKeys("%{SPACE}N");

-or-

wshShell.AppActivate("Command Prompt");
wshShell.SendKeys("% N");

In the second example; there is a space between the % and the letter N.


Austin M. Horst

Luigino Rossi

unread,
Mar 14, 2004, 10:28:07 AM3/14/04
to
None of your solutions work B-(

The first generates the error "invalid procedure call or arguments"
The second works like my procedure, the character N is sent to the
command prompt window and of course the window is not minimized.

I also tryed the combination of both solutions:
wshShell.SendKeys("%( )N");
but it works the same way.

still hoping... ;-)

Austin M. Horst <anon...@discussions.microsoft.com> wrote in message news:<A5DCBF14-AFE2-4ECD...@microsoft.com>...

Torgeir Bakken (MVP)

unread,
Mar 14, 2004, 1:11:27 PM3/14/04
to
Luigino Rossi wrote:

Hi

WSH's SendKeys method doesn't work very well against a
dos box/command prompt.

For a Sendkeys solution that will work for this scenario, you should
use AutoIt or AutoItX.

AutoIt/AutoItX is free and can be found here:
http://www.hiddensoft.com/AutoIt/


AutoItX is an ActiveX control version of AutoIt and can be used from a
vbscript.

--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide:
http://www.microsoft.com/technet/community/scriptcenter/default.mspx


Benny Pedersen

unread,
Mar 14, 2004, 3:43:59 PM3/14/04
to
sbor...@hotmail.com (Luigino Rossi) wrote in message news:<a7d9f7ce.04031...@posting.google.com>...

You can also try this vbs:

dim wso: set wso = createObject("wScript.shell")

msgBox "Minimized:"
for i=1 to 4
wso.run "%comspec% /c " & "ECHO Hello", 2, true
next

msgBox "Maximized:"
for i=1 to 4
wso.run "%comspec% /c " & "ECHO Hello", 3, true
next

msgBox "Normal:"
for i=1 to 4
wso.run "%comspec% /c " & "ECHO Hello", 5, true
next

wso.run "%comspec% /K " & "ECHO Welcome to DOS", 3

set wso = nothing

Austin M. Horst

unread,
Mar 14, 2004, 3:51:06 PM3/14/04
to
Tested, works for me.

VBSctipt:

Set WSHShell = WScript.CreateObject("WScript.Shell")
WSHShell.Run "cmd.exe"
WSHShell.AppActivate "Command Prompt"
WSHShell.SendKeys "% N"

JScript:

var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.Run("cmd.exe");
WshShell.AppActivate("Command Prompt");
WshShell.SendKeys("% N");


Austin M. Horst

Austin M. Horst

unread,
Mar 14, 2004, 3:51:09 PM3/14/04
to

Luigino Rossi

unread,
Mar 15, 2004, 10:01:11 AM3/15/04
to
I tryed both js and vbs, but they does not work for me, both scripts
start a command prompt window with the character N just before the
blinking cursor.

I thanks you all, but for now I give up B-(

Austin M. Horst <anon...@discussions.microsoft.com> wrote in message news:<680E924A-0D63-48B9...@microsoft.com>...

Peter Nguyen

unread,
Mar 15, 2004, 2:52:27 PM3/15/04
to
You need to give time for the command prompt to open before you can enter
inputs.

Set WSHShell = WScript.CreateObject("WScript.Shell")
WSHShell.Run "cmd.exe"

wsh.sleep 1000 ' wait 1 second


WSHShell.AppActivate "Command Prompt"
WSHShell.SendKeys "% N"

Peter Nguyen


"Luigino Rossi" <sbor...@hotmail.com> wrote in message
news:a7d9f7ce.04031...@posting.google.com...

Luigino Rossi

unread,
Mar 16, 2004, 6:35:57 PM3/16/04
to
Yes I know, so I tryed also with a command prompt windows already open
but it did not work.

I tested the script on Windows XP and on Windows 2000 with a Script
Host version 5.6

Thanks anyway B-)

"Peter Nguyen" <pet...@adobe.com> wrote in message news:<%Pn5c.239$g07.1...@newshog.newsread.com>...

ravipa...@gmail.com

unread,
Jan 1, 2013, 1:25:28 AM1/1/13
to
Even iam facing same issue,could you plz tell me your Microsoft Windows Version

tlav...@gmail.com

unread,
Jan 8, 2013, 9:29:10 AM1/8/13
to
On Tuesday, January 1, 2013 1:25:28 AM UTC-5, ravipa...@gmail.com wrote:
> On Monday, 15 March 2004 02:22:48 UTC+5:30, Austin M. Horst wrote:

This could be made to work up through Win XP, but cannot be made to work with Vista or Win 7. I would therefore have to surmise it is also disabled in Win8.

What exactly are you trying to do that requires a minimized command prompt window? If you are running a WSH script, you should be able to execute it under the Wscript.exe host which doesn't open a console window at all.
_______________________
Tom Lavedas

cre...@gmail.com

unread,
Nov 25, 2014, 2:23:16 PM11/25/14
to
I had the same problem, and found a workaround using powershell:

powershell -windowstyle minimized -command ""

To restore the window:

powershell -windowstyle normal -command ""

See http://stackoverflow.com/a/27134310/1683264 for use case. I know this isn't a WSH solution, but scripting a batch script wrapper for your cscript command should be trivial.
0 new messages