Domanda

I have the program unzipping the file to %temp%\myfolder\

I need to run a file from within that location. I have tried both shell and process.start but ultimately I'm looking for:

Process.start("%temp%\myfolder\start.cmd")

Also I looked on msdn on the getenvironmentvariable but nothing has worked. :(

Update: This is what I have in a nutshell

Imports system.diagnostics
Imports system.IO

System.Environment.GetEnvironmentVariable("TEMP")
Dim temp As String = System.IO.Path.GetTempPath

Things I have tried
process.start("%temp%\myfolder\start.cmd")
process.start("temp" & "myfolder\start.cmd")

I get an error code saying "file not found". But if I copy %temp%\myfolder\start.cmd into run or cmd.exe the program runs.

È stato utile?

Soluzione

First set the

Environment.CurrentDirectory = Environment.GetEnvironmentVariable("temp")
' Possible variables include temp, tmp, and windir for examples.

This command will place the current directory as C:\Users\ (currentuser)\appdata\local\temp or which ever the variable is set for. Then run process start. It should look like this:

Environment.CurrentDirectory = Environment.GetEnvironmentVariable("temp")
Process.start("myfolder\start.cmd")
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top