Running another application from C # code

How can I run another application from C # code? I can't get this part to work correctly

System.Diagnostics.Process.Start(@"%userprofile%\AppData\Local\Google\Application\chrome.exe"); 

Edit: Wow, I was dumb and just noticed that I forgot in the file path. Thanks for the answers, although they helped teach me other useful things.

+6
source share
2 answers

I do not think Process.Start extends environment variables for you. Try the following:

 var path = Environment.ExpandEnvironmentVariables(@"%userprofile%\AppData\Local\Google\Application\chrome.exe"); Process.Start(path); 
+10
source

try the link to launch an external program Also try fooobar.com/questions/16851 / ...

this is an example here

  string winpath = Environment.GetEnvironmentVariable("windir"); string path = System.IO.Path.GetDirectoryName( System.Windows.Forms.Application.ExecutablePath); Process.Start(winpath + @"\Microsoft.NET\Framework\v1.0.3705\Installutil.exe", path + "\\MyService.exe"); 

And in your case, write the following at the top, which lists everything using namespaces

  using System.Diagnostics; using System; 

so in your code directly write the code above ...

+2
source

Source: https://habr.com/ru/post/904962/


All Articles