Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. ShellExecute API

ShellExecute API

Scheduled Pinned Locked Moved Visual Basic
helpjson
12 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S shinay

    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

    L Offline
    L Offline
    Lisana
    wrote on last edited by
    #3

    NO, it still doesn't do anything. I don't know what's wrong with it. Lisa

    S 1 Reply Last reply
    0
    • L Lisana

      NO, it still doesn't do anything. I don't know what's wrong with it. Lisa

      S Offline
      S Offline
      shinay
      wrote on last edited by
      #4

      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

      S 1 Reply Last reply
      0
      • S shinay

        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

        S Offline
        S Offline
        shinay
        wrote on last edited by
        #5

        I meant at least you can launch notepad. If using Windows2000, you have to specified C:\WINNT\SYSTEM32\NOTEPAD.exe

        L 1 Reply Last reply
        0
        • S shinay

          I meant at least you can launch notepad. If using Windows2000, you have to specified C:\WINNT\SYSTEM32\NOTEPAD.exe

          L Offline
          L Offline
          Lisana
          wrote on last edited by
          #6

          it still doesn't work. it didn't open the notepad..and I'm using window2000.. Lisa

          S 1 Reply Last reply
          0
          • L Lisana

            it still doesn't work. it didn't open the notepad..and I'm using window2000.. Lisa

            S Offline
            S Offline
            shinay
            wrote on last edited by
            #7

            VB6 or VB.net? I am with VB6.

            L 1 Reply Last reply
            0
            • S shinay

              VB6 or VB.net? I am with VB6.

              L Offline
              L Offline
              Lisana
              wrote on last edited by
              #8

              I'm using VB.NET Lisa

              S 1 Reply Last reply
              0
              • L Lisana

                I'm using VB.NET Lisa

                S Offline
                S Offline
                shinay
                wrote on last edited by
                #9

                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.

                L 1 Reply Last reply
                0
                • L Lisana

                  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

                  M Offline
                  M Offline
                  Mitch F
                  wrote on last edited by
                  #10

                  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

                  L 1 Reply Last reply
                  0
                  • S shinay

                    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.

                    L Offline
                    L Offline
                    Lisana
                    wrote on last edited by
                    #11

                    both won't work in the VB.NET Lisa

                    1 Reply Last reply
                    0
                    • M Mitch F

                      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

                      L Offline
                      L Offline
                      Lisana
                      wrote on last edited by
                      #12

                      Thanks, it works.. Lisa

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups