6

How can I start another application from within C# code? I can't get this piece to work correctly

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

Edit: Wow I was dumb and just noticed what I forgot in the filepath. Thanks for the answers though they helped teach me some other useful things.

Rumel
  • 917
  • 1
  • 9
  • 21

2 Answers2

10

I don't think Process.Start expands environment variables for you. Try this:

var path = Environment.ExpandEnvironmentVariables(@"%userprofile%\AppData\Local\Google\Application\chrome.exe");
Process.Start(path);
ChrisWue
  • 18,612
  • 4
  • 58
  • 83
2

try this link for starting external program Also try this Similar Question on stackoverFlow

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 on top where all the using namespaces are listed

        using System.Diagnostics;
        using System;

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

Community
  • 1
  • 1
PresleyDias
  • 3,657
  • 6
  • 36
  • 62