Results 1 to 16 of 16

Thread: Shell [RESOLVED]

  1. #1

    Thread Starter
    Junior Member davism's Avatar
    Join Date
    Jan 2004
    Location
    Rotherham, UK
    Posts
    30

    Resolved Shell [RESOLVED]

    Hi,

    Is there a way to shell a program from the directory you are within instead of typing out the whole directory.
    eg:

    Shell "Setup.exe"

    Instead of

    Shell "D:\Setup.exe"

    I would like to know as some computers don't have there default drive set as D:

    Thanx
    Last edited by davism; Feb 5th, 2009 at 04:01 PM.

  2. #2
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,713
    You could do a
    VB Code:
    1. Shell App.Path & "\Setup.exe", vbNormalFocus
    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
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959
    To avoid the extra \ if the program is in the root dir then you can use,

    VB Code:
    1. Private Function Apath() As String
    2.  
    3.     If Right$(App.Path, 1) <> "\" Then
    4.         Apath = App.Path & "\"
    5.     Else
    6.         Apath = App.Path
    7.     End If
    8.  
    9. End Function
    10.  
    11. Private Sub Form_Load()
    12.  
    13.     Shell Apath & "Setup.exe", vbNormalFocus
    14.  
    15. End Sub

  4. #4
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    The extra slashes is never a problem. You can put a hundred of them there and it should still work.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  5. #5
    Fanatic Member daydee's Avatar
    Join Date
    Jun 2001
    Location
    Canada
    Posts
    560
    Originally posted by BuggyProgrammer
    The extra slashes is never a problem. You can put a hundred of them there and it should still work.
    As long as you're not in a root dir that is, otherwise I'm sure you'll get a "Path not found" error
    Give your music collection a whole new life with PartyTime Jukebox

  6. #6
    Hyperactive Member StreaksAthlete's Avatar
    Join Date
    Sep 2004
    Posts
    348

    This Is How

    VB Code:
    1. Shell App.Path & "\" & "Setup.exe"

  7. #7
    Fanatic Member daydee's Avatar
    Join Date
    Jun 2001
    Location
    Canada
    Posts
    560
    Give your music collection a whole new life with PartyTime Jukebox

  8. #8

    Thread Starter
    Junior Member davism's Avatar
    Join Date
    Jan 2004
    Location
    Rotherham, UK
    Posts
    30
    Thanks Loads guys it has been loads of help to me. I have got my app to run setup.exe on any drive it is put in. Now could you tell me how to change this to a resolved Post??

  9. #9
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Originally posted by daydee
    As long as you're not in a root dir that is, otherwise I'm sure you'll get a "Path not found" error
    This works in XP:
    VB Code:
    1. Msgbox Dir("C:\\\/\/\/\/\\\\\\\\\\\\\\\/////////////////////////////////////////////\\\\\\\\\\\\\\\\\\/\//////////\autoexec.bat")
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  10. #10
    Addicted Member
    Join Date
    Jul 2004
    Location
    uk liverpool
    Posts
    238

    I can do that ye ha

    Go to your first post and click Edit and in the post subject next to .. Shell ..........type [Resolved]

    Shell [Resolved]

  11. #11
    Fanatic Member daydee's Avatar
    Join Date
    Jun 2001
    Location
    Canada
    Posts
    560
    Originally posted by BuggyProgrammer
    This works in XP:
    VB Code:
    1. Msgbox Dir("C:\\\/\/\/\/\\\\\\\\\\\\\\\/////////////////////////////////////////////\\\\\\\\\\\\\\\\\\/\//////////\autoexec.bat")
    Just tried it on Win 98 and I got run-time error --> '52' (Bad file name or number)
    Also tried shelling an exe with this line:
    VB Code:
    1. Shell App.Path & "\Myapp.exe", vbNormalFocus
    from my root dir and got that "File not found" error!

    Just as expected...
    Give your music collection a whole new life with PartyTime Jukebox

  12. #12
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,713
    daydee, remember that if you are running an un-saved vb project
    and you use app.path that is the application path of visual basic.
    So you may get a file not found error.

    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

  13. #13
    Fanatic Member daydee's Avatar
    Join Date
    Jun 2001
    Location
    Canada
    Posts
    560
    Originally posted by RobDog888
    daydee, remember that if you are running an un-saved vb project
    and you use app.path that is the application path of visual basic.
    So you may get a file not found error.

    LOL I knew that...
    I'm not going to try to convince you once more that this problem is real. Just read for yourselves!
    A simple search on google turned these up, but you'll find a lot more than the ones I posted here....
    Cheers!

    http://www.buygold.net/v02n10/v02n10.html
    VB has a minor inconsistency. If App.Path is a root directory then VB returns the path with a backslash [c:\]. If App.Path is not a root directory then VB returns the path without a backslash [c:\myfolder\data].
    http://www.codeoftheweek.com/issues/0016.html
    This issue shows how to manipulate the backslash on path names. It is most useful for processing the path name returned from App.Path. It might come as a surprise to some readers, but the App.Path property does not always return a path name without a backslash as most people expect.
    If the application is installed in the root of a drive, such as W:\, App.Path will return W:\. If it is installed in a directory it will return something like C:\APPDIR, without the backslash.
    For your programs to work correctly you must account for both situations. The two functions introduced in this issue provide an easy way to do this.
    http://www.avdf.com/nov96/art_apath.html
    One thing to be aware of is that the App.Path property may or may not have a trailing backslash. In most cases, it will not have a trailing backslash; however, if the program is run from the root directory of a drive, then it will have the trailing backslash. You might think that it is unlikely that your users will install into a root directory, but it is possible - indeed, in the case of a LAN, it is quite common to map a drive letter directly to an application's home directory.
    http://vbcity.com/forums/topic.asp?tid=77654
    To to touch more on App.Path

    While it is true that for the most part it does not include the \ in the retrieved folder name so for the most part you need to say:

    debug.print app.path & "\yourfile.txt"
    That is not 100% always that way.
    It does NOT return a \ when it is any given subfolder off any drive
    ie:
    C:\FOLDER
    C:\PROGRAM FILES\FOLDER
    etc..

    But if the app.path is on the ROOT of any given drive it will return a backslash:

    ie:

    C:/
    D:/
    Z:/
    A:/
    etc... (note those are supposed to be \ marks...but vbCity kept chaning them to emoticons)

    So what does this mean. It means if ever your program is ran from a root drive (like a CD or floppy drive) your code will fail because you will be adding a backslash to a string that already had one.

    The best thing to do is go and write a simple little function like GetAppPath() as String that will return App.Path after checking for a \ and you can decide weather or not to always include one or never...then use that function in your code elsewhere and follow the rules that you decided on the \ issue.
    Give your music collection a whole new life with PartyTime Jukebox

  14. #14
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,713
    I am not disputing the issue of app.path and root directories.

    VB Code:
    1. Shell App.Path & "\Myapp.exe", vbNormalFocus
    from my root dir and got that "File not found" error!
    So where is your vb app located? also in the root next to the file
    you are shelling? If so then that is strange, but if not then its a
    correct error. When you use app.path the shelled file is expected
    to be in the same directory as the application otherwise you need
    to incluude the hardcoded complete path.


    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

  15. #15
    Fanatic Member daydee's Avatar
    Join Date
    Jun 2001
    Location
    Canada
    Posts
    560
    Originally posted by RobDog888
    I am not disputing the issue of app.path and root directories.
    I knew you guys were just pulling my leg.
    So where is your vb app located? also in the root next to the file
    you are shelling? If so then that is strange, but if not then its a
    correct error. When you use app.path the shelled file is expected
    to be in the same directory as the application otherwise you need
    to incluude the hardcoded complete path
    Didn't even bother running it in IDE since my project wasn’t located in the root dir of my C drive.
    All I did was compiled Project1.exe to my C:\ root directory and simply tried shelling another app with it (this one - > Myapp.exe) which was also located on C:\ The exact line I used was the same one I mentioned earlier.
    VB Code:
    1. Shell App.Path & "\Myapp.exe", vbNormalFocus
    Of course this generates (as expected) a "file not found" error since vb's App.Path adds the extra backslash in there following the drive letter.

    I had actually made that very same mistake in one of my app long ago.
    This app didn’t need to be installed and some folks were throwing it on their C drives in the root directory and executing it from there.
    A hard lesson learned…

    Cheers!
    Give your music collection a whole new life with PartyTime Jukebox

  16. #16
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,713
    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