Solved

Running EXE's in VB6

Posted on 2000-05-11
4
370 Views
Last Modified: 2008-02-26
Is there any controls, methods or objects or whatever that can actually allow you to run other .exe files in vb6?
0
Comment
Question by:da_dawg88
4 Comments
 
LVL 2

Expert Comment

by:Crin
Comment Utility
Hello,
Try to use this function, it works both on NT/2000 and 95/98 OS.

Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
    ByVal lpParameters As String, ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long


Sincerely yours,

Crin
0
 
LVL 1

Expert Comment

by:4P
Comment Utility
I just wanted to comment that the ShellExecute API call is primarely used to open documents (such as a Word document or an Excel workbook) without knowing where the host application is installed on the end user's computer.

A simpler solution is the use of the Shell function. This is a VB function, very simple to call.

RetVal = Shell(ExePath[, WinStyle])
where
ExePath is the path and name of the application you want to run.
WinStyle determines how to open the application, and it can be one of the following constants: vbHide, vbNormalFocus, vbMinimizedFocus, vbMaximizedFocus, vbNormalNoFocus, vbMinimizedNoFocus.
RetVal is the task ID of the started application.
0
 
LVL 3

Accepted Solution

by:
paulstamp earned 70 total points
Comment Utility
One additional comment - 4P is right - shellexecute is really for opening documents rather than running EXEs, and Shell is VB's built-in way of running EXEs.

The drawback with Shell is that often you want your program to launch another EXE and WAIT until that EXE has finished running before your program resumes. To do this, you need to use something like the following :

(PLACE THE FOLLOWING IN GENERAL DECLARATIONS SECTION OF A STANDARD MODULE)

Public Type PROCESS_INFORMATION
   hProcess As Long
   hThread As Long
   dwProcessId As Long
   dwThreadId As Long
End Type

Public 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

Public Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As Long, ByVal lpCommandLine As String, ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Long, ByVal lpCurrentDirectory As Long, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long



(PLACE THE FOLLOWING SUB ANYWHERE - USUALLY IN A MODULE)

Sub RunCommand(ByVal strCommand As String)

   Const NORMAL_PRIORITY_CLASS = &H20
   
   Dim udtProcessInfo As PROCESS_INFORMATION
   Dim udtStartUpInfo As STARTUPINFO
   Dim lngHandle As Long
   Dim lRC As Long
   
   ' Initialize the STARTUPINFO structure:
   udtStartUpInfo.cb = Len(udtStartUpInfo)

   ' Start the shelled application:
   If CreateProcess(0&, strCommand, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, udtStartUpInfo, udtProcessInfo) <> 0 Then
      ' Save the process handle
      lngHandle = udtProcessInfo.hProcess
   End If

   ' Check to see if Windows was able to start it...
   If lngHandle = 0 Then
      MsgBox "Failed to start "
      Exit Sub
   End If

   ' Wait until done...
   Do Until (WaitForSingleObject(lngHandle, 500&) = 0)
   Loop

   ' Close the handle to the process...
   lRC = CloseHandle(lngHandle)
   
End Sub
0
 

Author Comment

by:da_dawg88
Comment Utility
Thanks a lot for your help
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

763 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

12 Experts available now in Live!

Get 1:1 Help Now