Solved

Shelling out to DOS

Posted on 1998-11-17
2
154 Views
Last Modified: 2010-08-05
I have a VB program that repeatdly shells out to DOS. I want to make it run faster by shelling out once, and keeping the same DOS window open for future "shell outs." Is this possible?
0
Comment
Question by:rsoft1
2 Comments
 
LVL 3

Expert Comment

by:Sendoh
Comment Utility
Hi !

Is that you mean you need to shell app 1.
Then keep that shell for future use without terminate it ??
0
 
LVL 14

Accepted Solution

by:
waty earned 50 total points
Comment Utility
You should write a batch file and execute it once. It will be the easiest (if possible).

Otherwise, you could use the following class to send keystroke to dos command box :

' #VBIDEUtils#************************************************************
' * Programmer Name  : Waty Thierry
' * Web Site         : www.geocities.com/ResearchTriangle/6311/
' * E-Mail           : waty.thierry@usa.net
' * Date             : 24/09/98
' * Time             : 13:36
' * Module Name      : class_SendKeys
' * Module Filename  :
' **********************************************************************
' * Comments         : Allows users to be able to send keystrokes to
' *                    dos programs running in a windows95 dos box
' *
' * This class has one property, Destination, which needs to be the handle
' *  returned from the shell function of the dos program or any program
' *  started with the shell function.
' * It also has one method called, SendKeys, this is the string to be sent
' *  to the destination.
' *
' **********************************************************************

Option Explicit

Private mvarDestination As Long 'local copy
Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_SHIFT = &H10

Private Declare Function OemKeyScan Lib "user32" (ByVal wsOemchar As Integer) As Long
Private Declare Function CharToOem Lib "user32" Alias "CharToOemA" (ByVal lpszSrc As String, ByVal lpszDst As String) As Long
Private Declare Function VkKeyScan Lib "user32" Alias "VkKeyScanA" (ByVal cChar As Byte) As Integer
Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Sub SendAKey(ByVal sKeys As String)

   Dim vk            As Integer
   Dim nShiftScan    As Integer
   Dim nScan         As Integer
   Dim sOemchar      As String
   Dim nShiftKey     As Integer
   
   ' *** Get the virtual key code for this character
   vk = VkKeyScan(Asc(sKeys)) And &HFF
   ' *** See if shift key needs to be pressed
   nShiftKey = VkKeyScan(Asc(sKeys)) And 256
   sOemchar = " " ' 2 character buffer
   ' *** Get the OEM character - preinitialize the buffer
   CharToOem Left$(sKeys, 1), sOemchar
   ' *** Get the nScan code for this key
   nScan = OemKeyScan(Asc(sOemchar)) And &HFF
   ' *** Send the key down

   If nShiftKey = 256 Then
      ' *** if shift key needs to be pressed
      nShiftScan = MapVirtualKey(VK_SHIFT, 0)
      ' *** press down the shift key
      keybd_event VK_SHIFT, nShiftScan, 0, 0
   End If

   ' *** press key to be sent
   keybd_event vk, nScan, 0, 0
   ' *** Send the key up

   If nShiftKey = 256 Then
      ' *** keyup for shift key
      keybd_event VK_SHIFT, nShiftScan, KEYEVENTF_KEYUP, 0
   End If

   ' ***keyup for key sent
   keybd_event vk, nScan, KEYEVENTF_KEYUP, 0
   
End Sub

Public Sub SendKeys(ByVal sKeys As String)

   Dim x          As Integer
   
   ' *** Loop thru string to send one key at a time
   For x = 1 To Len(sKeys)
      ' *** Activate target application
      AppActivate (mvarDestination)
      ' *** Send one key to target
      SendAKey Mid$(sKeys, x, 1)
   Next

End Sub

Public Property Let Destination(ByVal vData As Long)
   'used when assigning a value to the property, on the left si
   '     de of an assignment.
   
   ' ***Syntax: X.Destination = 5
   mvarDestination = vData
   
End Property

Public Property Get Destination() As Long
   
   'used when retrieving value of a property, on the right side
   '      of an assignment.
   ' ***Syntax: Debug.Print X.Destination
   Destination = mvarDestination
   
End Property

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now