Solved

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

Posted on 1997-12-13
2
197 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 100 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month7 days, 6 hours left to enroll

623 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