chiche115
asked on
Adding exe file
How can i execute a exe file from a buttom.
Shell + F1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here's a function you can use to start a .exe file..
You can use it with code like..
Call Run(exefilename)
Add this to the (declaration) part..
Private 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
And here's the function code..
Function Run(strFilePath As String, Optional strParms As String, Optional strDir As String) As String
Const SW_SHOW = 5
'Run the Program and Evaluate errors
Select Case ShellExecute(0, "Open", strFilePath, strParms, strDir, SW_SHOW)
Case 0
Run = "Insufficent system memory or corrupt program file"
Case 2
Run = "File not found"
Case 3
Run = "Invalid path"
Case 5
Run = "Sharing or Protection Error"
Case 6
Run = "Seperate data segments are required for each task"
Case 8
Run = "Insufficient memory to run the program"
Case 10
Run = "Incorrect Windows version"
Case 11
Run = "Invalid program file"
Case 12
Run = "Program file requires a different operating system"
Case 13
Run = "Program requires MS-DOS 4.0"
Case 14
Run = "Unknown program file type"
Case 15
Run = "Windows program does not support protected memory mode"
Case 16
Run = "Invalid use of data segments when loading a second instance of a program"
Case 19
Run = "Attempt to run a compressed program file"
Case 20
Run = "Invalid dynamic link library"
Case 21
Run = "Program requires Windows 32-bit extensions"
Case Else
Run = ""
End Select
End Function
You can use it with code like..
Call Run(exefilename)
Add this to the (declaration) part..
Private 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
And here's the function code..
Function Run(strFilePath As String, Optional strParms As String, Optional strDir As String) As String
Const SW_SHOW = 5
'Run the Program and Evaluate errors
Select Case ShellExecute(0, "Open", strFilePath, strParms, strDir, SW_SHOW)
Case 0
Run = "Insufficent system memory or corrupt program file"
Case 2
Run = "File not found"
Case 3
Run = "Invalid path"
Case 5
Run = "Sharing or Protection Error"
Case 6
Run = "Seperate data segments are required for each task"
Case 8
Run = "Insufficient memory to run the program"
Case 10
Run = "Incorrect Windows version"
Case 11
Run = "Invalid program file"
Case 12
Run = "Program file requires a different operating system"
Case 13
Run = "Program requires MS-DOS 4.0"
Case 14
Run = "Unknown program file type"
Case 15
Run = "Windows program does not support protected memory mode"
Case 16
Run = "Invalid use of data segments when loading a second instance of a program"
Case 19
Run = "Attempt to run a compressed program file"
Case 20
Run = "Invalid dynamic link library"
Case 21
Run = "Program requires Windows 32-bit extensions"
Case Else
Run = ""
End Select
End Function
ASKER