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
Solved

Running EXE's in VB6

Posted on 2000-05-11
4
378 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
ID: 2800279
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
ID: 2800319
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
ID: 2800409
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
ID: 2800507
Thanks a lot for your help
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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 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…

808 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