Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to send key strokes to a non-windowed dos box

Posted on 1997-12-13
2
Medium Priority
?
198 Views
Last Modified: 2010-05-18
I've read the MS article #Q77394 "How to send keystrokes from VB App to MS-DOS App" but this will only work if the dos box is windowed. Is there anyway to send keystrokes to a hidden dos box?
Thanks
0
Comment
Question by:Karma121397
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 4

Accepted Solution

by:
rantanen earned 400 total points
ID: 1445050
I suppose you mean a window which is really hidden, not only minimized.

Then the only thing I could figure out was to make the DOS window appear in minimized state and do what is desctibed in that KB article. The only problem is, what is taking place in the DOS window happens asynchronously from VB's point of view and hiding the window again requires more thinking, if you need that feature.

Anyway, following code supplements the code from that KB article and lets you do SendKeys to an originally hidden DOS window, which then stays as minimized window.

Option Explicit
Dim progname As String
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClasszName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetClasszName Lib "user32" Alias "GetClasszNameA" (ByVal hwnd As Long, ByVal lpClasszName As String, ByVal nMaxCount As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

Const SW_HIDE = 0
Const SW_NORMAL = 1
Const SW_MINIMIZE = 6

Const GW_CHILD = 5
Const GW_HWNDNEXT = 2

Private Sub btnSendKeys_Click()
    DOSWindowShow SW_MINIMIZE
    progname = "Project1 - Microsoft Visual Basic [run]"
    Clipboard.Clear
    Clipboard.SetText DosKeys.Text + Chr$(13)  ' Append a <CR>.
    AppActivate DoszClassName.Text
    SendKeys "% ep", 1
    AppActivate progname
    ' Following does or does not work dependingwhat is happening in DOS window
    DOSWindowShow SW_HIDE
End Sub


Private Sub DOSWindowShow(swMode As Integer)
    Dim szClassName As String
    Dim szName As String
    Dim hwnd As Long
    Dim lResult As Long
    Dim bSuccess As Boolean
   
    bSuccess = False
    ' Get first top-level window
    hwnd = GetWindow(GetDesktopWindow(), GW_CHILD)
    ' Iterate through remaining windows
    Do While hwnd <> 0
        szName = String$(80, 0)
        lResult = GetClasszName(hwnd, szName, 80)
        szClassName = Left$(szName, lResult)
        lResult = FindWindow(szClassName, "MS-DOS Prompt")
        If lResult <> 0 Then
            lResult = ShowWindow(hwnd, swMode)
            bSuccess = True
        End If
        hwnd = GetWindow(hwnd, GW_HWNDNEXT)
    Loop
End Sub

0
 
LVL 4

Expert Comment

by:rantanen
ID: 1445051
¤#%!,

theres also typos in this sample program. (Luckily I picked them up and not somebody else...have to be more careful with module wide replacements). The API function is not  GetClasszName but  GetClassName (GetClassNameA) and textbox used in original sample was not DoszClassName but DosTitle.

I'm sorry about this.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question