|
-
Sep 6th, 2004, 09:28 AM
#1
Thread Starter
Member
Launching a exe program using VB
hi
i tried to launch a program with the following code but it fails to open the program. i have a module as well to declare all the API stuff:
Private Sub Command3_Click()
Shell sAppPath, vbMinimizedFocus
end sub
Private Sub Form_Load()
sAppName = "Inspections"
sAppPath = "C:\fin_root\access\Inspections.exe"
End Sub
Module CODE:
-
Sep 6th, 2004, 09:41 AM
#2
Frenzied Member
hmm, using the Shell() function shouldn't require API... please post what you have in your module... ANd do a search for ShellExecute on the forums, it might do what you want...
"Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
- Zack de la Rocha
Hear me roar.
-
Sep 6th, 2004, 09:48 AM
#3
Thread Starter
Member
RE:
Here is them module code i got it from somee website builder.com
Option Explicit
'API's Function Declarations
Private Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As Any, _
ByVal lpWindowName As String) As Long
'API Constants
Public Const GWL_STYLE = -16
Public Const WS_DISABLED = &H8000000
Public Const WM_CANCELMODE = &H1F
Public Const WM_CLOSE = &H10
Public Function IsTaskRunning(sWindowName As String) As Boolean
Dim hwnd As Long, hWndOffline As Long
On Error GoTo IsTaskRunning_Eh
'get handle of the application 'if handle is 0 the application is currently not running hwnd = FindWindow(0&, sWindowName) If hwnd = 0 Then IsTaskRunning = False Exit Function Else IsTaskRunning = True End If
IsTaskRunning_Exit:
Exit Function
IsTaskRunning_Eh:
Call ShowError(sWindowName, "IsTaskRunning")
End Function
Public Function EndTask(sWindowName As String) As Integer
Dim X As Long, ReturnVal As Long, TargetHwnd As Long 'find handle of the application TargetHwnd = FindWindow(0&, sWindowName) If TargetHwnd = 0 Then Exit Function If IsWindow(TargetHwnd) = False Then GoTo EndTaskFail Else 'close application If Not (GetWindowLong(TargetHwnd, GWL_STYLE) And WS_DISABLED) Then X = PostMessage(TargetHwnd, WM_CLOSE, 0, 0&) DoEvents End If End If GoTo EndTaskSucceed
EndTaskFail:
ReturnVal = False
MsgBox "EndTask: cannot terminate " & sWindowName & " task"
GoTo EndTaskEndSub
EndTaskSucceed: ReturnVal = True
EndTaskEndSub: EndTask% = ReturnVal
End Function
Public Function ShowError(sText As String, sProcName As String) 'this function displays an error that occurred Dim sMsg As String sMsg = "Error # " & Str(Err.Number) & " was generated by " _ & Err.Source & vbCrLf & Err.Description MsgBox sMsg, vbCritical, sText & Space(1) & sProcName Exit Function
End Function
-
Sep 6th, 2004, 09:52 AM
#4
Frenzied Member
wow - are you even using any of that? Is the only function of your program what you have posted so far? If so, you don't need the declarations in the module...
"Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
- Zack de la Rocha
Hear me roar.
-
Sep 6th, 2004, 09:54 AM
#5
Thread Starter
Member
re
yes thats the only function that i have posted first so you think that i dont need all that garbage in the module
-
Sep 6th, 2004, 10:16 AM
#6
Thread Starter
Member
-
Sep 6th, 2004, 10:20 AM
#7
Frenzied Member
No problem, though I really don't think I did that much
"Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
- Zack de la Rocha
Hear me roar.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|