CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Shell command

  1. #1
    Join Date
    May 2001
    Posts
    17

    Shell command

    I am running a VB prog in a folder with two-word name (something like "My Folder").
    When I use the shell command with App.Path :
    Shell(App.Path + "\data\my_exe.exe" I have the problem that
    c:\My Folder\data\my_exe.exe can not be executed.

    Instead you have to type :
    c:\"My Folder"\data\my_exe.exe

    How can I solve this problem?

    Thanks



  2. #2
    Join Date
    May 1999
    Location
    Germany
    Posts
    106

    Re: Shell command

    Hello,

    Try
    Shell("""" & App.Path + "\data\my_exe.exe"""

    The result will be
    "c:\my folder\data\my_exe.exe"

    Bye
    Peter


  3. #3
    Join Date
    Aug 2000
    Location
    England
    Posts
    185

    Re: Shell command

    Hello,

    I am not sure if this will work....but you could try:


    shell ("'" & App.path & "\data\my_exe.exe & "'");




    This would encase the whole string in single quotes, hopefully removing the problem. Or I could just be talking rubbish :-)


  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Shell command

    You canalso use short file name (dos format). Have a look at getshortpathname api
    ie:
    Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal lBuffer As Long) As Long
    Public Function GetShortPath(strFileName As String) As String
    'KPD-Team 1999
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Dim lngRes As Long, strPath As String
    'Create a buffer
    strPath = String$(165, 0)
    'retrieve the short pathname
    lngRes = GetShortPathName(strFileName, strPath, 164)
    'remove all unnecessary chr$(0)'s
    GetShortPath = Left$(strPath, lngRes)
    End Function
    Private Sub Form_Load()
    MsgBox GetShortPath("c:\Program Files\")
    End Sub


    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  5. #5
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    Re: Shell command

    This is wierd. I tried this on mine where I have RGB.EXE in App.Path and my App.Path evaluates to E:\Projects\VB\RGB Generator. Calling Shell(App.Path & "\RGB.EXE") works fine for me. Does it have anything to do with OS? I'm using WIN2K so have not tested this with Win9x.

    -Cool Bizs

    Good Luck,
    -Cool Bizs

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)