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. Shell Or Other command to open a file.

Shell Or Other command to open a file.

Scheduled Pinned Locked Moved Visual Basic
linuxtutorial
6 Posts 2 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.
  • J Offline
    J Offline
    jlizardo
    wrote on last edited by
    #1

    Hi I want to open any document without the .exe file to open it. Example. If I using shell("c:\program files\microsoft office\office\winword.exe c:\temp\mydoc.doc") I dont't wanna that. How i can only put Shell("c:\temp\mydoc.doc") or other command to open it. Johnny Lizardo

    J 1 Reply Last reply
    0
    • J jlizardo

      Hi I want to open any document without the .exe file to open it. Example. If I using shell("c:\program files\microsoft office\office\winword.exe c:\temp\mydoc.doc") I dont't wanna that. How i can only put Shell("c:\temp\mydoc.doc") or other command to open it. Johnny Lizardo

      J Offline
      J Offline
      jlizardo
      wrote on last edited by
      #2

      The reason is clear.. Many PC have differents office version and I can't specify the path correctly.

      N 1 Reply Last reply
      0
      • J jlizardo

        The reason is clear.. Many PC have differents office version and I can't specify the path correctly.

        N Offline
        N Offline
        Niels Penneman
        wrote on last edited by
        #3

        use ShellExecute (API); verb is "open" greetz ;-) *Niels Penneman*


        Software/Dev Site
        Personal Site


        J 1 Reply Last reply
        0
        • N Niels Penneman

          use ShellExecute (API); verb is "open" greetz ;-) *Niels Penneman*


          Software/Dev Site
          Personal Site


          J Offline
          J Offline
          jlizardo
          wrote on last edited by
          #4

          Hi Look, i don't know.. but this don't works. This is a command for vb.net?. Or give me more info about that. Johnny Lizardo

          N 1 Reply Last reply
          0
          • J jlizardo

            Hi Look, i don't know.. but this don't works. This is a command for vb.net?. Or give me more info about that. Johnny Lizardo

            N Offline
            N Offline
            Niels Penneman
            wrote on last edited by
            #5

            VB5/6 declaration:

            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

            or better (but only for 2000/XP) the unicode function:

            Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteW" (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

            VB.NET declaration:

            Declare Auto Function ShellExecute Lib "shell32.dll" (ByVal hwnd As IntPtr, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Integer) As Integer

            nShowCmd & return value constants declaration:

            Public Const SW_HIDE = 0
            Public Const SW_MAXIMIZE = 3
            Public Const SW_MINIMIZE = 6
            Public Const SW_RESTORE = 9
            Public Const SW_SHOW = 5
            Public Const SW_SHOWDEFAULT = 10
            Public Const SW_SHOWMAXIMIZED = 3
            Public Const SW_SHOWMINIMIZED = 2
            Public Const SW_SHOWMINNOACTIVE = 7
            Public Const SW_SHOWNA = 8
            Public Const SW_SHOWNOACTIVATE = 4
            Public Const SW_SHOWNORMAL = 1
            Public Const ERROR_FILE_NOT_FOUND = 2&
            Public Const ERROR_PATH_NOT_FOUND = 3&
            Public Const ERROR_BAD_FORMAT = 11&
            Public Const SE_ERR_ACCESSDENIED = 5
            Public Const SE_ERR_ASSOCINCOMPLETE = 27
            Public Const SE_ERR_DDEBUSY = 30
            Public Const SE_ERR_DDEFAIL = 29
            Public Const SE_ERR_DDETIMEOUT = 28
            Public Const SE_ERR_DLLNOTFOUND = 32
            Public Const SE_ERR_FNF = 2
            Public Const SE_ERR_NOASSOC = 31
            Public Const SE_ERR_OOM = 8
            Public Const SE_ERR_PNF = 3
            Public Const SE_ERR_SHARE = 26

            VB5/6 example

            Private Sub OpenFile(ByVal File As String)
            ShellExecute(Me.hWnd, "open", File, 0, 0, SW_NORMAL)
            End Sub

            See ShellExecute Function on MSDN Hope this helps you out :-) greetz ;-) *Niels Penneman*


            Software/Dev Site
            Personal Site


            J 1 Reply Last reply
            0
            • N Niels Penneman

              VB5/6 declaration:

              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

              or better (but only for 2000/XP) the unicode function:

              Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteW" (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

              VB.NET declaration:

              Declare Auto Function ShellExecute Lib "shell32.dll" (ByVal hwnd As IntPtr, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Integer) As Integer

              nShowCmd & return value constants declaration:

              Public Const SW_HIDE = 0
              Public Const SW_MAXIMIZE = 3
              Public Const SW_MINIMIZE = 6
              Public Const SW_RESTORE = 9
              Public Const SW_SHOW = 5
              Public Const SW_SHOWDEFAULT = 10
              Public Const SW_SHOWMAXIMIZED = 3
              Public Const SW_SHOWMINIMIZED = 2
              Public Const SW_SHOWMINNOACTIVE = 7
              Public Const SW_SHOWNA = 8
              Public Const SW_SHOWNOACTIVATE = 4
              Public Const SW_SHOWNORMAL = 1
              Public Const ERROR_FILE_NOT_FOUND = 2&
              Public Const ERROR_PATH_NOT_FOUND = 3&
              Public Const ERROR_BAD_FORMAT = 11&
              Public Const SE_ERR_ACCESSDENIED = 5
              Public Const SE_ERR_ASSOCINCOMPLETE = 27
              Public Const SE_ERR_DDEBUSY = 30
              Public Const SE_ERR_DDEFAIL = 29
              Public Const SE_ERR_DDETIMEOUT = 28
              Public Const SE_ERR_DLLNOTFOUND = 32
              Public Const SE_ERR_FNF = 2
              Public Const SE_ERR_NOASSOC = 31
              Public Const SE_ERR_OOM = 8
              Public Const SE_ERR_PNF = 3
              Public Const SE_ERR_SHARE = 26

              VB5/6 example

              Private Sub OpenFile(ByVal File As String)
              ShellExecute(Me.hWnd, "open", File, 0, 0, SW_NORMAL)
              End Sub

              See ShellExecute Function on MSDN Hope this helps you out :-) greetz ;-) *Niels Penneman*


              Software/Dev Site
              Personal Site


              J Offline
              J Offline
              jlizardo
              wrote on last edited by
              #6

              Men.. You're the men,. Thankk a lottt. Johnny Lizardo

              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