Leung King Tim
Leung King Tim

Reputation: 76

Win32Exception when using Process.Start()

How Do I open google chrome using c#?

It shows System.ComponentModel.Win32Exception: 'The system cannot find the file specified'

I'd triedProcess.Start("C:\\Program Files(x86)\\Google\\Chrome\\Application\\chrome.exe"); too, but it shows the same exception

using System;

using System.Diagnostics;

namespace tempTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Process.Start("chrome.exe");
        }
    }
}

Upvotes: 1

Views: 663

Answers (1)

xiangbin.pang
xiangbin.pang

Reputation: 319

The chrome application path can be read from the registry. You can try following codes:

            var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe", false);

            if(key != null)
            {
                var path = Path.Combine(key.GetValue("Path").ToString(), "chrome.exe");

                if(File.Exists(path))
                {
                    Process.Start(path);
                }
            }

Upvotes: 2

Related Questions