PDA

Click to See Complete Forum and Search --> : System.Diagnostics.Process.Start _ from %homepath%


condonethis
Apr 29th, 2010, 02:38 PM
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

baja_yu
Apr 29th, 2010, 04:37 PM
You should look up the "SHGetFolderPath" function.

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

chris128
Apr 29th, 2010, 05:11 PM
You should look up the "SHGetFolderPath" function.


In VB6 maybe but in .NET its easier to just use Environment.ExpandEnvironmentVariables like so:
Environment.ExpandEnvironmentVariables("%HOMEPATH%")

condonethis
May 2nd, 2010, 06:56 PM
In VB6 maybe but in .NET its easier to just use Environment.ExpandEnvironmentVariables like so:
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!

chris128
May 3rd, 2010, 08:08 AM
you have to integrate the ExpandEnvironmentVariables into your file path like so:


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.

condonethis
May 3rd, 2010, 02:35 PM
you have to integrate the ExpandEnvironmentVariables into your file path like so:


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!

jmcilhinney
May 13th, 2010, 01:12 AM
You would more likely do it like this:System.Diagnostics.Process.Start(Environment.ExpandEnvironmentVariables("%HOMEPATH%\batlaunch\meditech.bat"))