开发者

WPF Application crashes on WIndows 7 when command executable.Start() is run

开发者 https://www.devze.com 2023-04-12 06:50 出处:网络
I\'ve got a tiny Portal I´m writing, and this portal is supposed to launch installers on button click. I´m developing on VS2010 on a WinXP SP3 station, and on this machine, even fter compilation and

I've got a tiny Portal I´m writing, and this portal is supposed to launch installers on button click. I´m developing on VS2010 on a WinXP SP3 station, and on this machine, even fter compilation and publishing, everything works as expected. However, when i run the compiled application in Windows 7, it crashes...The application work, it just crashes when i click a button for program installation.

The programming looks like this:

    private void button_access_Click(object sender, RoutedEventArgs e)
    {


        Process executable = new Process();
        string executablePath = "D:\\Visual Studio 2010\\SAFE_P开发者_如何学运维ortal1\\SAFE_Portal1\\Extra Programs\\AccessRT2003.exe";
        executable.StartInfo.FileName = executablePath;
        executable.Start();


    }

It specifically crashes on thr button_access_Click procedure...

Any ideas as to why this could be? I`ve tried looking around here in Stackoverflow, and in other forums, but to no avail...

Any help or direction is ganz welcome!


Try this:

try
{
     Process executable = new Process();
     string executablePath = "D:\\Visual Studio 2010\\SAFE_Portal1\\SAFE_Portal1\\Extra Programs\\AccessRT2003.exe";
     executable.StartInfo.FileName = executablePath;
     executable.Start();
 }
 catch (Exception msg)
 {
     MessageBox.Show(msg.Message);
 }

What message are you getting?

Are you sure you want to use fixed paths in your application? If so you should at least check if the file you try to start exists beforehand. Otherwise an exception will be thrown which could be the problem here.

if (File.Exists(executablePath))
{
    ...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号