Results 1 to 7 of 7

Thread: System.Diagnostics.Process.Start _ from %homepath%

  1. #1

    Thread Starter
    Addicted Member condonethis's Avatar
    Join Date
    Apr 2010
    Location
    TX
    Posts
    133

    Question System.Diagnostics.Process.Start _ from %homepath%

    Hello all,

    I am trying to execute .bat files from a location that can be modified by all users so have chosen the %homepath% dir, but have thus far been unable to find a way to launch the .bat from this location any help???

    Looking for something to the effect of this:

    System.Diagnostics.Process.Start _
    ("%homepath%\batlaunch\meditech.bat")

    Version 2008


    Any help greatly appreciated!!
    Chad

  2. #2
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: System.Diagnostics.Process.Start _ from %homepath%

    You should look up the "SHGetFolderPath" function.

    Also, what programming language are you using, VB.Net, C#...?

  3. #3
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: System.Diagnostics.Process.Start _ from %homepath%

    Quote Originally Posted by baja_yu View Post
    You should look up the "SHGetFolderPath" function.
    In VB6 maybe but in .NET its easier to just use Environment.ExpandEnvironmentVariables like so:
    vb.net Code:
    1. Environment.ExpandEnvironmentVariables("%HOMEPATH%")
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  4. #4

    Thread Starter
    Addicted Member condonethis's Avatar
    Join Date
    Apr 2010
    Location
    TX
    Posts
    133

    Question Re: System.Diagnostics.Process.Start _ from %homepath%

    Quote Originally Posted by chris128 View Post
    In VB6 maybe but in .NET its easier to just use Environment.ExpandEnvironmentVariables like so:
    vb.net Code:
    1. Environment.ExpandEnvironmentVariables("%HOMEPATH%")

    Using Visual Basic 2008 Express Edition

    Been googling the ExpandEnvironmentVariables command, but not had much success. How can input the executable path into a button to launch an application in the User directory using this command? How do I orchestrate this, got this so far

    Environment.ExpandEnvironmentVariables("%HOMEPATH%")

    System.Diagnostics.Process.Start _
    ("%homepath%\batlaunch\meditech.bat")

    Also, what area of the form would I place that ExpandEnvironment command?

    Thanks!

  5. #5
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: System.Diagnostics.Process.Start _ from %homepath%

    you have to integrate the ExpandEnvironmentVariables into your file path like so:

    Code:
    System.Diagnostics.Process.Start(Environment.ExpandEnvironmentVariables("%HOMEPATH%") & "\batlaunch\meditech.bat")
    but you should really also use IO.Path.Combine to combine two paths, as I dont know if your HOMEPATH variable will already have the "\" at the end of it.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  6. #6

    Thread Starter
    Addicted Member condonethis's Avatar
    Join Date
    Apr 2010
    Location
    TX
    Posts
    133

    Resolved Re: System.Diagnostics.Process.Start _ from %homepath%

    Quote Originally Posted by chris128 View Post
    you have to integrate the ExpandEnvironmentVariables into your file path like so:

    Code:
    System.Diagnostics.Process.Start(Environment.ExpandEnvironmentVariables("%HOMEPATH%") & "\batlaunch\meditech.bat")
    but you should really also use IO.Path.Combine to combine two paths, as I dont know if your HOMEPATH variable will already have the "\" at the end of it.
    Works like a charm!! Thanks so much!

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: System.Diagnostics.Process.Start _ from %homepath%

    You would more likely do it like this:
    Code:
    System.Diagnostics.Process.Start(Environment.ExpandEnvironmentVariables("%HOMEPATH%\batlaunch\meditech.bat"))
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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