ShellExecute API
-
I'm using the ShellExecute API, but it is not opening any file with its associated program. here is my coding: 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 Public Sub RunProgram(ByVal strProgram As String) Dim lRet As Long lRet = ShellExecute(vbNull, "Open", strProgram, "", "", 1) If lRet <= 32 Then MsgBox("Error Running Program") End If End Sub Public Sub btmView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnview.Click RunProgram(file_location) end sub It doesn't give me the error either. PLEASE HELP! Lisa
-
I'm using the ShellExecute API, but it is not opening any file with its associated program. here is my coding: 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 Public Sub RunProgram(ByVal strProgram As String) Dim lRet As Long lRet = ShellExecute(vbNull, "Open", strProgram, "", "", 1) If lRet <= 32 Then MsgBox("Error Running Program") End If End Sub Public Sub btmView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnview.Click RunProgram(file_location) end sub It doesn't give me the error either. PLEASE HELP! Lisa
It perfectly works in my pc. You might wanna check what is inside of the strProgram variable.( maybe there is a space in side?) try with the note pad like the following if it works. 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 Private Sub Command1_Click() Dim lRet As Long lRet = ShellExecute(vbNull, "Open", "C:\WINDOWS\SYSTEM32\notepad.exe", "C:\mytext.txt", "", 1) If lRet <= 32 Then MsgBox ("Error Running Program") End If End Sub
-
It perfectly works in my pc. You might wanna check what is inside of the strProgram variable.( maybe there is a space in side?) try with the note pad like the following if it works. 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 Private Sub Command1_Click() Dim lRet As Long lRet = ShellExecute(vbNull, "Open", "C:\WINDOWS\SYSTEM32\notepad.exe", "C:\mytext.txt", "", 1) If lRet <= 32 Then MsgBox ("Error Running Program") End If End Sub
-
Can you just create a new project with VB and copy & paste the following code. In the form, you just add one button called "Command1"(by default). Compile and run. it should work. 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 Public Sub RunProgram(ByVal strProgram As String) Dim lRet As Long lRet = ShellExecute(vbNull, "Open", strProgram, "", "", 1) If lRet <= 32 Then MsgBox ("Error Running Program") End If End Sub Private Sub Command1_Click() RunProgram "c:\windows\system32\notepad.exe" End Sub
-
Can you just create a new project with VB and copy & paste the following code. In the form, you just add one button called "Command1"(by default). Compile and run. it should work. 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 Public Sub RunProgram(ByVal strProgram As String) Dim lRet As Long lRet = ShellExecute(vbNull, "Open", strProgram, "", "", 1) If lRet <= 32 Then MsgBox ("Error Running Program") End If End Sub Private Sub Command1_Click() RunProgram "c:\windows\system32\notepad.exe" End Sub
-
I meant at least you can launch notepad. If using Windows2000, you have to specified C:\WINNT\SYSTEM32\NOTEPAD.exe
-
I'm using the ShellExecute API, but it is not opening any file with its associated program. here is my coding: 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 Public Sub RunProgram(ByVal strProgram As String) Dim lRet As Long lRet = ShellExecute(vbNull, "Open", strProgram, "", "", 1) If lRet <= 32 Then MsgBox("Error Running Program") End If End Sub Public Sub btmView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnview.Click RunProgram(file_location) end sub It doesn't give me the error either. PLEASE HELP! Lisa
Hello, In VB .Net, you can use:
Process.Start( <insert your parameters here> )
Hope this helps, Mitch My sig: "And it is a professional faux pas to pay someone else to destroy your computer when you are perfectly capable of destroying it yourself." - Roger Wright My CodeProject Blog Most recent blog post: April 3 -
Try to use Shell or ShellExecuteEx to run from VB.NET instead of ShellExecute Since I don't have it installed, i can't test.
-
Hello, In VB .Net, you can use:
Process.Start( <insert your parameters here> )
Hope this helps, Mitch My sig: "And it is a professional faux pas to pay someone else to destroy your computer when you are perfectly capable of destroying it yourself." - Roger Wright My CodeProject Blog Most recent blog post: April 3