Results 1 to 7 of 7

Thread: Shell Problem with command line arguments VB6

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    4

    Angry Shell Problem with command line arguments VB6

    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. Project runs but nothing happens.

    When i run it without any arguments i.e.
    Shell ("c:\myapplication.exe") it works.

    Please help ASAP and tell me a way out Please.

    regards

    SAM

    PS:And if I run it in Windows->Start->Run as c:\myapplication.exe argument1 argument2 the also it works fine.

  2. #2
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Shell Problem with command line arguments VB6

    I don't think the Shell function supports arguments maybe try using the ShellExecute API.

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    4

    Re: Shell Problem with command line arguments VB6

    Thanks

    Do u have any codes that can solve my problem ?

    thanks

  4. #4
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Shell Problem with command line arguments VB6

    vb Code:
    1. 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
    2.  
    3. Private Sub Button1_Click()
    4. ShellExecute "app.path  and file ....... arguments etc...."
    5. End Sub

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2007
    Posts
    4

    Re: Shell Problem with command line arguments VB6

    Thanks a lot for the code but it somehow didnt work. I am sure i am putting some wrong syntax.

    When I tried is as below then it didn't work
    ShellExecute "c:\myapplication.exe argument1 argument2 "

    Could uou please write a proper syntax for it.
    I want to run exactly like this i.e.

    c:\myapplication.exe argument1 argument2

    Many thanks

    Sam

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Shell Problem with command line arguments VB6

    Have a look at this article.

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

    Re: Shell Problem with command line arguments VB6

    Its best if you add some kind of delimiter to your arguments.
    Code:
    Option Explicit
    
    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 Const SW_HIDE As Long = 0
    Private Const SW_SHOWNORMAL As Long = 1
    Private Const SW_SHOWMAXIMIZED As Long = 3
    Private Const SW_SHOWMINIMIZED As Long = 2
    
    Private Sub Command1_Click()
        ShellExecute Me.hwnd, "runas", "C:\MyFile.exe", "/Arg1 /Arg2", "C:\", SW_SHOWNORMAL
    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

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