Solved

Shell command and rc with GetModuleUsage

Posted on 1998-08-26
2
542 Views
Last Modified: 2010-10-05
Early with VB3 I had a program within I start a shell function and wait for the termination of the shell to continue within the function with the following code:
Private Declare Function GetModuleUsage Lib "Kernel32" (ByVal hModule As Integer) As Integer
...
comm = "xcopy " & fwininp & fwinout & " /e /s"

    X = Shell(comm, 1)
    While GetModuleUsage(X) > 0
        z = DoEvents()
    Wend
    If GetModuleUsage(X) < 0 Then
        MsgBox ("shell < 0 ")
    End If
...
Now with VB5, GetModuleUsage isn't found in any library I search !
Where can I found this function or by what can I replace it.
Is it another way to stay in my program while the shell is'nt terminated.
Thanks in advance.

Alain Feuchaux
feuch@distri.be

0
Comment
Question by:feuch
2 Comments
 
LVL 4

Accepted Solution

by:
mcix earned 200 total points
ID: 1431123
Try this it's straight out of the MS Knowledge Base:

      Private Type STARTUPINFO
         cb As Long
         lpReserved As String
         lpDesktop As String
         lpTitle As String
         dwX As Long
         dwY As Long
         dwXSize As Long
         dwYSize As Long
         dwXCountChars As Long
         dwYCountChars As Long
         dwFillAttribute As Long
         dwFlags As Long
         wShowWindow As Integer
         cbReserved2 As Integer
         lpReserved2 As Long
         hStdInput As Long
         hStdOutput As Long
         hStdError As Long
      End Type

      Private Type PROCESS_INFORMATION
         hProcess As Long
         hThread As Long
         dwProcessID As Long
         dwThreadID As Long
      End Type

      Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
         hHandle As Long, ByVal dwMilliseconds As Long) As Long

      Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
         lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
         lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
         ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
         ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
         lpStartupInfo As STARTUPINFO, lpProcessInformation As _
         PROCESS_INFORMATION) As Long

      Private Declare Function CloseHandle Lib "kernel32" (ByVal _
         hObject As Long) As Long

      Private Const NORMAL_PRIORITY_CLASS = &H20&
      Private Const INFINITE = -1&

      Public Sub ExecCmd(cmdline$)
         Dim proc As PROCESS_INFORMATION
         Dim start As STARTUPINFO

         ' Initialize the STARTUPINFO structure:
         start.cb = Len(start)

         ' Start the shelled application:
         ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
            NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)

         ' Wait for the shelled application to finish:
         ret& = WaitForSingleObject(proc.hProcess, INFINITE)
         ret& = CloseHandle(proc.hProcess)
      End Sub


Add the following code the Form_Click() event procedure of Form1:

      Sub Form_Click ()
         ExecCmd "notepad.exe"
         MsgBox "Process Finished"
      End Sub


Press the F5 key to run the application.

Using the mouse, click the Form1 window. At this point the Notepad application is shelled.
0
 

Author Comment

by:feuch
ID: 1431124
Thanks for your prompt response.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

863 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

21 Experts available now in Live!

Get 1:1 Help Now