SendKeys cannot close DOS window. 
Author Message
 SendKeys cannot close DOS window.

Torgeir,

Thanks for your help. I downloaded the control and seemed to solve the
problem I was facing. However, there should be a way to accomplish the same
without having to add an additional control. Perhaps I am losing focus on
the appropriate window and that is why the keys I am sending to the DOS
window are not interpreted properly. I have looked at description of the
"AppActivate" method in MSDN and  noticed it states: "You can use the task
ID returned by the Shell function in place of title to activate an
application." Do you (or anyone in the group) have an idea of how to access
the "task ID" referred to here? I am using the "Run" method to activate the
batch file running in the DOS window and it does not return the "task ID".

Any help would be greatly appreciated,

Thanks,

Jacob.


Quote:
> Using AutoItX (free), you can close a dos box (with a running bat-file

also) e.g. like this:
Quote:

> <code>

> Set WshShell = CreateObject("WScript.Shell")
> Set oAutoIt = CreateObject("AutoItX.Control")

> sComSpec = WshShell.ExpandEnvironmentStrings("%comspec%")
> WshShell.Run sComSpec

> MsgBox "Closing Command Box with Window title " & sComSpec
> oAutoIt.WinClose sComSpec,""

> </code>

> AutoIt: http://www.*-*-*.com/ , it can

automate any windows based task or even windowed DOS tasks
Quote:

> Note: It's defaults is to match the start of a window title that you

specify, use "SetTitleMatchMode 2" to  specify ANY substring of the window
title you want to match. Windows titles is case *sensitive* also.
Quote:

> Regards,
> Torgeir

> <qoute>

> AutoIt is a simple tool that can simulate key presses, mouse movements and

window commands (maximize, minimize, wait for, etc.) in order to automate
any windows based task (or even windowed DOS tasks).
Quote:

> AutoItX is an ActiveX control version of AutoIt.  It allows you to perform

the following types of functions:
Quote:

> Sending keystrokes and mouse clicks (all characters, keyboard layout
independent).
> Window functions (e.g. minimizing, hiding, restoring, waiting for,

activating (even under Win98/NT2000)).
Quote:
> Sleep (for those with WSH 1.0 :) )
> INI file reading and writing.
> Simple clipboard (text) commands.
> Shutdown and reboot commands (including a forced reboot that works under
both 9x and NT).
> Blocking input under Windows NT4 SP6 and 2000.
> Best of all, its small and FREE!

> </qoute>


> > Hello all,

> > I am looking for a way to use SendKeys to send the close window sequence
(ALT+SPACE+C)
> > to a DOS window under WinNT. I am facing an issue which involves closing

the DOS window which is running a batch file. I tried sending "^C" twice,
but that does not work. The first one is caught, but then the user is
prompted for input. The only way I seem to be able to close the window using
keystrokes without user intervention is via (ALT+SPACE+C). Manually this can
be done but programmatically,

- Show quoted text -

Quote:
> > the DOS window seems to ignore the sequence. Doing the same on a Notepad
> > application works fine, i.e. the sequence is correct and is sent
correctly.
> > If anyone has experienced such a phenomenon and may know of a solution
or work-around,
> > I would appreciate all the help you can offer.

> > Thanks,

> > Jacob.



Thu, 08 Apr 2004 14:35:41 GMT  
 SendKeys cannot close DOS window.
Hi

It is an error in the old docs, WshShell.Run does not return the task id.

You can take a look at this thread (use
http://groups.google.com/advanced_group_search to fetch it):


Subject: AppActivate using the shell function Task ID
Newsgroups: microsoft.public.scripting.wsh
Date: 2001-02-09 03:12:00 PST

Regards,
Torgeir

Quote:

> Torgeir,

> Thanks for your help. I downloaded the control and seemed to solve the
> problem I was facing. However, there should be a way to accomplish the same
> without having to add an additional control. Perhaps I am losing focus on
> the appropriate window and that is why the keys I am sending to the DOS
> window are not interpreted properly. I have looked at description of the
> "AppActivate" method in MSDN and  noticed it states: "You can use the task
> ID returned by the Shell function in place of title to activate an
> application." Do you (or anyone in the group) have an idea of how to access
> the "task ID" referred to here? I am using the "Run" method to activate the
> batch file running in the DOS window and it does not return the "task ID".

> Any help would be greatly appreciated,

> Thanks,

> Jacob.



> > Using AutoItX (free), you can close a dos box (with a running bat-file
> also) e.g. like this:

> > <code>

> > Set WshShell = CreateObject("WScript.Shell")
> > Set oAutoIt = CreateObject("AutoItX.Control")

> > sComSpec = WshShell.ExpandEnvironmentStrings("%comspec%")
> > WshShell.Run sComSpec

> > MsgBox "Closing Command Box with Window title " & sComSpec
> > oAutoIt.WinClose sComSpec,""

> > </code>

> > AutoIt: http://www.hiddensoft.com/AutoIt/ . As quoted below, it can
> automate any windows based task or even windowed DOS tasks

> > Note: It's defaults is to match the start of a window title that you
> specify, use "SetTitleMatchMode 2" to  specify ANY substring of the window
> title you want to match. Windows titles is case *sensitive* also.

> > Regards,
> > Torgeir

> > <qoute>

> > AutoIt is a simple tool that can simulate key presses, mouse movements and
> window commands (maximize, minimize, wait for, etc.) in order to automate
> any windows based task (or even windowed DOS tasks).

> > AutoItX is an ActiveX control version of AutoIt.  It allows you to perform
> the following types of functions:

> > Sending keystrokes and mouse clicks (all characters, keyboard layout
> independent).
> > Window functions (e.g. minimizing, hiding, restoring, waiting for,
> activating (even under Win98/NT2000)).
> > Sleep (for those with WSH 1.0 :) )
> > INI file reading and writing.
> > Simple clipboard (text) commands.
> > Shutdown and reboot commands (including a forced reboot that works under
> both 9x and NT).
> > Blocking input under Windows NT4 SP6 and 2000.
> > Best of all, its small and FREE!

> > </qoute>


> > > Hello all,

> > > I am looking for a way to use SendKeys to send the close window sequence
> (ALT+SPACE+C)
> > > to a DOS window under WinNT. I am facing an issue which involves closing
> the DOS window which is running a batch file. I tried sending "^C" twice,
> but that does not work. The first one is caught, but then the user is
> prompted for input. The only way I seem to be able to close the window using
> keystrokes without user intervention is via (ALT+SPACE+C). Manually this can
> be done but programmatically,
> > > the DOS window seems to ignore the sequence. Doing the same on a Notepad
> > > application works fine, i.e. the sequence is correct and is sent
> correctly.
> > > If anyone has experienced such a phenomenon and may know of a solution
> or work-around,
> > > I would appreciate all the help you can offer.

> > > Thanks,

> > > Jacob.



Fri, 09 Apr 2004 04:00:50 GMT  
 SendKeys cannot close DOS window.
Jacob,

I don't know your circumstances and why you have to use SendKeys. In my
practice I always could find a better solution. I played with this function
some time ago and found that it is not worth to be considered in modern
programming. However, here are some tips you may find helpful.

If you use

Dim x As Integer
x = Shell("cmd", vbNormalFocus) ' vbnormalfocus is optional

then the x will contain the task ID you requested. Note however that the use
of SendKeys is not reliable (at least) with all applications and should be
avoided whenever possible. This is especially true with command prompt
window. Under NT it does not work at all with Command.com shell; with
cmd.exe it often sends keystrokes to the shell faster that the shell can
process. A workaround of the last cause may be a use of custom sub like this
one:

Sub MySendKey(s As String)
    For i = 1 To Len(s)
    SendKeys Mid$(s, i, 1), True
    Next
End Sub

Alex.


Quote:
> Torgeir,

> Thanks for your help. I downloaded the control and seemed to solve the
> problem I was facing. However, there should be a way to accomplish the
same
> without having to add an additional control. Perhaps I am losing focus on
> the appropriate window and that is why the keys I am sending to the DOS
> window are not interpreted properly. I have looked at description of the
> "AppActivate" method in MSDN and  noticed it states: "You can use the task
> ID returned by the Shell function in place of title to activate an
> application." Do you (or anyone in the group) have an idea of how to
access
> the "task ID" referred to here? I am using the "Run" method to activate
the
> batch file running in the DOS window and it does not return the "task ID".

> Any help would be greatly appreciated,

> Thanks,

> Jacob.



> > Using AutoItX (free), you can close a dos box (with a running bat-file
> also) e.g. like this:

> > <code>

> > Set WshShell = CreateObject("WScript.Shell")
> > Set oAutoIt = CreateObject("AutoItX.Control")

> > sComSpec = WshShell.ExpandEnvironmentStrings("%comspec%")
> > WshShell.Run sComSpec

> > MsgBox "Closing Command Box with Window title " & sComSpec
> > oAutoIt.WinClose sComSpec,""

> > </code>

> > AutoIt: http://www.hiddensoft.com/AutoIt/ . As quoted below, it can
> automate any windows based task or even windowed DOS tasks

> > Note: It's defaults is to match the start of a window title that you
> specify, use "SetTitleMatchMode 2" to  specify ANY substring of the window
> title you want to match. Windows titles is case *sensitive* also.

> > Regards,
> > Torgeir

> > <qoute>

> > AutoIt is a simple tool that can simulate key presses, mouse movements
and
> window commands (maximize, minimize, wait for, etc.) in order to automate
> any windows based task (or even windowed DOS tasks).

> > AutoItX is an ActiveX control version of AutoIt.  It allows you to
perform
> the following types of functions:

> > Sending keystrokes and mouse clicks (all characters, keyboard layout
> independent).
> > Window functions (e.g. minimizing, hiding, restoring, waiting for,
> activating (even under Win98/NT2000)).
> > Sleep (for those with WSH 1.0 :) )
> > INI file reading and writing.
> > Simple clipboard (text) commands.
> > Shutdown and reboot commands (including a forced reboot that works under
> both 9x and NT).
> > Blocking input under Windows NT4 SP6 and 2000.
> > Best of all, its small and FREE!

> > </qoute>


> > > Hello all,

> > > I am looking for a way to use SendKeys to send the close window
sequence
> (ALT+SPACE+C)
> > > to a DOS window under WinNT. I am facing an issue which involves
closing
> the DOS window which is running a batch file. I tried sending "^C" twice,
> but that does not work. The first one is caught, but then the user is
> prompted for input. The only way I seem to be able to close the window
using
> keystrokes without user intervention is via (ALT+SPACE+C). Manually this
can
> be done but programmatically,
> > > the DOS window seems to ignore the sequence. Doing the same on a
Notepad
> > > application works fine, i.e. the sequence is correct and is sent
> correctly.
> > > If anyone has experienced such a phenomenon and may know of a solution
> or work-around,
> > > I would appreciate all the help you can offer.

> > > Thanks,

> > > Jacob.



Fri, 09 Apr 2004 14:53:20 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. SendKeys cannot close DOS window.

2. SendKeys cannot close DOS window.

3. SendKeys cannot close DOS window.

4. SendKeys cannot close DOS window.

5. SendKeys cannot close DOS window.

6. SENDKEYS for MS-DOS Window (16-bit)?

7. SendKeys to MS-DOS Window

8. Sendkeys to DOS Window - VB4.0

9. SendKeys to DOS window

10. SendKeys to DOS window

11. Cannot close Access window

12. Cannot find top level window to send a close command

 

 
Powered by phpBB® Forum Software