Results 1 to 28 of 28

Thread: Shellexecute not working?

  1. #1

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Shellexecute not working?

    If im right here, using shellexecute with parameters is just like creating a shortcut and adding it right there?

    so using this code:
    VB Code:
    1. ShellExecute me.hwnd, vbNullString, app.path & "\yay.exe", " -time 12", vbNullString, 1
    is the same as right clicking yay.exe and adding into the properties bar -time 12?

    Well ive never had a problem until now, and the exe i have is crashing. I cant post it because of copyright etc etc...Hoping someone here knows a resolution to it?

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Shellexecute not working?

    I don't know if vbNullString works for an action, but you are right about the command line arguments. They are the same as they would be if you added them to the properties of the icon or shortcut to the icon. I always used OPEN, EDIT, or PRINT, which I suppose are actions based on the file type.

  3. #3

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Shellexecute not working?

    on other shellexecute's ive used it, so i guess it would work. What other paramater should i pass instead?

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Shellexecute not working?

    I always used OPEN, EDIT, or PRINT, which I suppose are actions based on the file type.
    I added that after I posted.

  5. #5

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Shellexecute not working?

    So any other ideas? i cant use shell because the path has spaces in it.. : (

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

    Re: Shellexecute not working?

    Shellexecute is a good option but try your parameters from the run dialog box. It may be the space between the items for you params - " -time 12".
    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
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Shellexecute not working?

    if i even try it without paramaters it crashes?? i dont get it!

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Shellexecute not working?

    You could use GetShortPathName API, but I have used things like this:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.   Dim Netshare$, DirectoryName$
    5.   Netshare = "David"
    6.   DirectoryName = "d:\david"
    7.   Shell ("C:\Windows\System32\cmd.exe /c  C:\Windows\System32\net share " & Netshare & "=" & DirectoryName), vbNormalFocus
    8. End Sub

    and this:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
    4. ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    5.  
    6. Private Const SW_SHOWNORMAL As Long = 1
    7. Private Const SW_HIDE As Long = 0
    8.  
    9. Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
    10.  
    11. Dim sSave As String, Ret As Long
    12.  
    13. Private Sub Form_Load()
    14.     'KPD-Team 1998
    15.     'URL: [url]http://www.allapi.net/[/url]
    16.     'E-Mail: [email][email protected][/email]
    17.     Dim sSave As String, Ret As Long
    18.     'Create a buffer
    19.     sSave = Space(255)
    20.     'Get the system directory
    21.     Ret = GetSystemDirectory(sSave, 255)
    22.     'Remove all unnecessary chr$(0)'s
    23.     sSave = Left$(sSave, Ret)
    24. End Sub
    25.  
    26. Private Sub Command1_Click()
    27.     ShellExecute Me.hwnd, "Open", sSave & "CMD.exe", " /c dir c: > D:\Myfile.txt", "D:\", SW_SHOWNORMAL
    28. End Sub

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

    Re: Shellexecute not working?

    Then its your exe and not the parameters? Post your code for the Startup procedure.
    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

  10. #10

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Shellexecute not working?

    i can run the exe normally and i can run a shortcut with the parameters i want. What do you mean the code for my startup procedure rd?

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

    Re: Shellexecute not working?

    The exe's Form_Load code or Sub Main.
    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

  12. #12

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Shellexecute not working?

    It isnt my .exe, so i dont have any of that stuff mate

    I just dont get why shellexecute is causing errors. Can i wrap the shell() command with quotes for use with spaces? shell("""c:\yay ay\yay.exe""") ?

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

    Re: Shellexecute not working?

    Correct.

    I do think it has something to do with the space inbetween your argument though.
    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

  14. #14

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Shellexecute not working?

    right rob, but if i take out the arguments it still has errors as i said before

    Code:
    ShellExecute me.hwnd, vbNullString, app.path & "\yay.exe", vbnullstring, vbNullString, 1
    i think that will clarify better

  15. #15
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Shellexecute not working?

    Maybe it needs to start in that directory? Pass the app.path as the last argument. I've seen that happen when you want to read a file in.

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

    Re: Shellexecute not working?

    You need to specify the verb and other parameters as they are important.
    VB Code:
    1. ShellExecute me.hwnd, "Open", app.path & "\yay.exe", vbnullstring, "C:\", 1
    The "C:\" is your working directory which is very important. If your working dir is not matching what the exe needs then that could cause it to fail depending on your exe. Change it to what the shortcut properties specify as the working dir.
    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

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

    Re: Shellexecute not working?

    Also, if your running in the IDE the app.path is the path to VB6.
    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

  18. #18
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Shellexecute not working?

    Not if you open a vbp file that has been saved in a different folder. Then app.path works fine in the IDE.

  19. #19

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Shellexecute not working?

    Quote Originally Posted by RobDog888
    You need to specify the verb and other parameters as they are important.
    VB Code:
    1. ShellExecute me.hwnd, "Open", app.path & "\yay.exe", vbnullstring, "C:\", 1
    The "C:\" is your working directory which is very important. If your working dir is not matching what the exe needs then that could cause it to fail depending on your exe. Change it to what the shortcut properties specify as the working dir.
    i wish i had known about "Open" before, ill try it before. Also, i thought i could leave out C:\ because it will always be different, i thought this was the advantage of shellexecute?

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

    Re: Shellexecute not working?

    Maybe I should be more clear. Make sure your exe is in the expected directory.
    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

  21. #21

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Shellexecute not working?

    VB Code:
    1. ShellExecute Servers.hwnd, "Open", app.path & "\yay.exe", vbNullString, "C:\", 1

    still getting the same error! i dont understand this stupid thing

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

    Re: Shellexecute not working?

    Ok, is "C:\" the directory where your exe resides?

    Try it with a different exe?
    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

  23. #23
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Shellexecute not working?

    I meant something like this:

    VB Code:
    1. ShellExecute Servers.hwnd, "Open", app.path & "\yay.exe", vbNullString, app.path, 1

  24. #24

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Shellexecute not working?

    app.path is just an example, its dynamic depending on user input

  25. #25
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Shellexecute not working?

    Well, change the second example to the actual folder, and see if it works.

  26. #26

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Shellexecute not working?

    yeah that works..i guess ill just have to figure a way to get the path from the .exe path..i dont get why we need that 2nd path though

  27. #27
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Shellexecute not working?

    You'll like the second one

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal lBuffer As Long) As Long
    4. Private Declare Function GetFullPathName Lib "kernel32" Alias "GetFullPathNameA" (ByVal lpFileName As String, ByVal nBufferLength As Long, ByVal lpBuffer As String, ByVal lpFilePart As String) As Long
    5.  
    6. Public Function GetShortPath(strFileName As String) As String
    7.     'KPD-Team 1999
    8.     'URL: [url]http://www.allapi.net/[/url]
    9.     'E-Mail: [email][email protected][/email]
    10.     Dim lngRes As Long, strPath As String
    11.     'Create a buffer
    12.     strPath = String$(165, 0)
    13.     'retrieve the short pathname
    14.     lngRes = GetShortPathName(strFileName, strPath, 164)
    15.     'remove all unnecessary chr$(0)'s
    16.     GetShortPath = Left$(strPath, lngRes)
    17. End Function
    18.  
    19. Function GetFullPath() As String
    20.     'KPD-Team 2000
    21.     'URL: [url]http://www.allapi.net/[/url]
    22.     'E-Mail: [email][email protected][/email]
    23.     Dim Buffer As String, Ret As Long
    24.     'create a buffer
    25.     Buffer = Space(255)
    26.     'copy the current directory to the buffer and append "Project1.vbp"
    27.     Ret = GetFullPathName("Project1.vbp", 255, Buffer, "")
    28.     'remove the unnecessary chr$(0)'s
    29.     GetFullPath = Left(Buffer, Ret)

    Oops. that may not work if it's not your app. The second one is the start-in folder that is needed so Windows knows were to read ini files, and the like.

  28. #28

    Thread Starter
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Shellexecute not working?

    all i did was use instrrev and find \ and then used mid to get the rest of it. Thanks alot guys, i would never have gotten that!

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