Results 1 to 6 of 6

Thread: [SORTED]Shell Exe help..

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Resolved [SORTED]Shell Exe help..

    Out of pure boredom I just tried this:

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim PFEnvironVar As String
    3. Dim FilePath As String
    4. PFEnvironVar = Environ$("PROGRAMFILES")
    5. FilePath = PFEnvironVar & "\MSN Messenger\mailtmpl.txt"
    6. MsgBox FilePath
    7. Shell FilePath, vbNormalFocus
    8. End Sub

    FilePath produces the right directory and everything, but the shell doesn't seem to work... Would like to know what i'm doing wrong

    Thanks

    Edit: I'm getting "File not found" but I know it exists...
    Last edited by BefunMunkToloGen; May 8th, 2005 at 02:10 PM.

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

    Re: Shell Exe help..

    Use the SHGetSpecialFolderLocation API instead.

    Also, Shell doesnt like spaces in the path.
    Use ShellExecute API for best results.
    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

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Re: Shell Exe help..

    So it doesn't work purely because of the spaces...? I don't really want to use API's either.. I've used SHGetFolderLocation before. I'm trying to get this to work

    Cheers

  4. #4
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: Shell Exe help..

    Quote Originally Posted by BefunMunkToloGen
    Out of pure boredom I just tried this:

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim PFEnvironVar As String
    3. Dim FilePath As String
    4. PFEnvironVar = Environ$("PROGRAMFILES")
    5. FilePath = PFEnvironVar & "\MSN Messenger\mailtmpl.txt"
    6. MsgBox FilePath
    7. Shell FilePath, vbNormalFocus
    8. End Sub

    FilePath produces the right directory and everything, but the shell doesn't seem to work... Would like to know what i'm doing wrong

    Thanks


    I do not think Shell likes spaces in its function's perameters, try this:

    VB Code:
    1. Private Const SW_SHOWNORMAL = 1
    2. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
    3.     ByVal hwnd As Long, _
    4.     ByVal lpOperation As String, _
    5.     ByVal lpFile As String, _
    6.     ByVal lpParameters As String, _
    7.     ByVal lpDirectory As String, _
    8.     ByVal nShowCmd As Long) As Long
    9.  
    10. Dim strPFEnvironVar As String
    11. Dim strFilePath As String
    12. strPFEnvironVar = Environ$("PROGRAMFILES")
    13. strFilePath = strPFEnvironVar & "\MSN Messenger\mailtmpl.txt"
    14. ShellExecute Me.hwnd, vbNullString, strFilePath, vbNullString, "C:\", SW_SHOWNORMAL

    Cheers,


    RyanJ
    My Blog.

    Ryan Jones.

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

    Re: [SORTED]Shell Exe help..

    Just about the only way to get it to work without using APIs is to double up on the double quotes around the spaces.

    Also, you shouldnt rely on the Environ variable since it can be changed or deleted.
    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

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Re: [SORTED]Shell Exe help..

    Sorted thank you

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