Results 1 to 11 of 11

Thread: [RESOLVED] shell problem

  1. #1

    Thread Starter
    Lively Member chxxangie's Avatar
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    79

    Resolved [RESOLVED] shell problem

    Code:
            file_path = "C:\aaa.txt"
    how to use SHELL to open the file_path?

  2. #2
    New Member
    Join Date
    Mar 2007
    Posts
    2

    Re: shell problem

    There are 4 arguments - the executable path/filename, command line arguments to pass to the exe, how the window will be displayed, and whether or not you want your app to wait on the shelled program to finish before returning. Assuming you have pasted it into a bas module, you can put the following code in your button click event. This will just open up notepad and then return to your program.

    Private Sub Command1_Click()
    Call ShellExe("notepad.exe", "", Normal, False)
    End Sub


    By adding a command line argument such as the filename, this will open up a file in notepad much the same as double clicking on a text file.

    Private Sub Command1_Click()
    Call ShellExe("notepad.exe", " C:\boot.ini", Normal, False)
    End Sub
    Last edited by hrtj; Mar 8th, 2007 at 02:33 AM.

  3. #3
    New Member
    Join Date
    Mar 2007
    Posts
    2

    Re: shell problem

    ok? hopfully that helps

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: shell problem

    Or the more powerful ShellExecute API. It will open the file in its default associatted program. .txt will be Notepad, .htm will be the default browser, .xls will be Excel (if installed), etc.
    vb Code:
    1. Option Explicit
    2.  
    3. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
    4.                     ByVal hwnd As Long, _
    5.                     ByVal lpOperation As String, _
    6.                     ByVal lpFile As String, _
    7.                     ByVal lpParameters As String, _
    8.                     ByVal lpDirectory As String, _
    9.                     ByVal nShowCmd As Long) As Long
    10.  
    11. Private Const SW_HIDE As Long = 0
    12. Private Const SW_SHOWNORMAL As Long = 1
    13. Private Const SW_SHOWMAXIMIZED As Long = 3
    14. Private Const SW_SHOWMINIMIZED As Long = 2
    15.  
    16. Private Sub Command1_Click()
    17.     ShellExecute Me.hwnd, "Open", "C:\MyFile.txt", vbNullString, "C:\", SW_SHOWNORMAL
    18. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Lively Member chxxangie's Avatar
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    79

    Re: shell problem

    the above code can support only for those files inside the C drive....if the files is not in the C Drive?

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: shell problem

    Just change the filepath/filename. It works anywhere.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Lively Member chxxangie's Avatar
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    79

    Re: shell problem

    because my system is allowed user to save files at everywhere....
    but i don't know which drive will be used to save files.....
    may be C,D,E drive......

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: shell problem

    Then are you also coding in that part too? If so then just set a string variable when the do the save. Then when you want to do the open you will have the filepath already.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    Lively Member chxxangie's Avatar
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    79

    Re: shell problem

    thanks for teaching.....

  10. #10
    New Member
    Join Date
    May 2007
    Posts
    4

    Re: [RESOLVED] shell problem

    Hi

    I am new to VB6 programming.

    I am stuck with Shell command. I want to run a EXE with command line arguments i.e.

    Shell ("c:\myapplication.exe argument1 argument2")

    but it does not work.

    When i run it without any arguments it works.

    and when itype the same is Windows Start-Run as c:\myapplication.exe argument1 argument2 then it works fine.


    Please help ASAP.

    regards

    SAM

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] shell problem

    Please dont hijack other members threds. I see you also have your own thread so its best for any replies to your post to be posted here - http://vbforums.com/showthread.php?t=468295
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width