简体   繁体   中英

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 tried Process.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");
        }
    }
}

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);
                }
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM