问题推出的System.Diagnostics.Process在Windows 7下 [英] Problem launching a System.Diagnostics.Process under Windows 7

查看:108
本文介绍了问题推出的System.Diagnostics.Process在Windows 7下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图启动一个应用程序(操作系统,我的应用程序,我想启动应用程序都是32位),从.NET 3.51。

I’m trying to launch an application (Operating System, My Application and the application I want to launch are all 32 bits), from .NET 3.51.

在code的启动过程用于其他应用程序,但有一个是给我们一个头痛的问题。如果我们双击的应用程序的图标,它按预期工作,这意味着它工作正常,在计算机的应用程序。双击直接点击.exe文件,同样适用。

The code that launches the Process is used for other applications, but there’s one that is giving us a headache. If we "double click" on the application’s icon, it works as expected, meaning that it works fine as an application in the computer. Double clicking the .exe directly, also works.

该操作系统是Windows 7 32位(家庭和/或专业)。

The operating system is Windows 7 32Bits (Home and/or Professional).

我们的.NET应用程序编译使用x86,以避免出现问题。

Our .NET application is compiled with x86 to avoid problems.

在code,会启动进程位于由我们做了一个DLL(也是32位)内,基本上它是一个简单的DLL,它拥有一些普遍code一刀切,常用的方法,函数和东西我们用我们的整个code。其中的一个方法是这样的:

The code that launches "Processes" is located inside a DLL (also 32 bits) made by us, basically it’s a simple DLL that holds some "Common Code" across the board, common methods, functions and stuff we use throughout our code. One of those methods look like this:

public static bool FireUpProcess( Process process, string path, bool enableRaisingEvents,
        ProcessWindowStyle windowStyle, string arguments )
    {
        if ( process != null )
        {
            try
            {
                process.StartInfo.FileName = @path;
                if ( arguments != null )
                {
                    if ( arguments != String.Empty )
                    {
                        process.StartInfo.Arguments = arguments;
                    }
                }
                process.StartInfo.WindowStyle = windowStyle;
                process.EnableRaisingEvents = enableRaisingEvents;
                process.Start();
            }
            catch
            {
                try
                {
                    process.Kill();
                }
                catch ( InvalidOperationException )
                {
                } // The process is not even created

                return false;
            }
        }
        else
        {
            return false;
        }
        return true;
    }

我不知道是谁写了这个方法,但它已经工作了大约6年,不同的应用程序,因此,我认为这是正常。但是,我们有将不通过这样的说法时,通过推出一个软件客户。

I don’t know who wrote this method, but it has been working for roughly six years with different applications, therefore I assume it’s "ok". However, we have a customer with a piece of software that won’t launch when passed through that argument.

的参数是

  1. 过程是一个简单的创建一个的System.Diagnostics.Process新工艺();
  2. 路径是一个完整路径中的.exeC:/path/to/my.exe。
  3. enableRaisingEvents 为假
  4. windowStyle 的最大化(但都试过其他)。
  1. process is a System.Diagnostics.Process created with a simple "new Process();"
  2. path is a full path to the .exe "c:/path/to/my.exe".
  3. enableRaisingEvents is false
  4. windowStyle is Maximized (but have tried others).

这给出了一个糟糕的消息框......这是我高兴地永生。这是在西班牙,但翻译应该是简单的:

It gives a crappy MessageBox… which I have happily immortalized. It’s in spanish but the translation ought to be easy:

它说:

应用程序错误 意外发生了异常的程序(0x0eedfade)在...

Application Error An unexpected exception has occurred for the program (0x0eedfade) at …

谷歌搜索的0x0eedfade给出一个奇怪的结果,看起来吓人,但事实是,如果我去了,我尝试推出.exe文件并双击它,它完美的作品。

Googling that 0x0eedfade gives strange results that look scary, but the truth is, if I go to the .exe that I’m trying to launch and double click it, it works perfectly.

的记录的:如果我尝试推出其他的事情(即:Notepad.exe的,Adobe Acrobat Reader软件),它的工作原理,但是 Firefox不公开,没有按'T显示错误。

For The Record: If I try to launch other things (I.e.: Notepad.exe, Adobe Acrobat Reader) it works, but Firefox doesn’t open and doesn’t show an error.

这一些工作,有的不的行为使我相信,有可能是与Windows 7安全机制的问题或类似的,我不知道。

This "some work, some doesn’t" behavior leads me to believe that there might be a problem with a Windows 7 security mechanism or similar that I don’t know.

我在想什么或者做错了吗?

What am I missing or doing wrong?

更新:确定;我已经得到该软件的副本。这是一个混乱的软件,但它的工作原理。现在,我可以调试,我看到节目的时候给我的 FireUpProcess 方法展开了错误。

UPDATE: Ok; I’ve gotten a copy of the software. It’s a messy software but it works. Now that I can debug, I see that the program gives an error when launched with my FireUpProcess method.

作为建议我增加了WorkingDirectory code,但这里的code:

As suggested I added the WorkingDirectory code, but here’s the code:

    public static bool FireUpProcess(Process process, string path, bool enableRaisingEvents, ProcessWindowStyle windowStyle)
    {
        if (process != null)
        {
            try
            {
                if ( !String.IsNullOrEmpty(@path) )
                {
                    process.StartInfo.FileName = @path;
                    process.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(@path);
                    process.StartInfo.WindowStyle = windowStyle;
                    // Suscribe to the exit notification
                    process.EnableRaisingEvents = enableRaisingEvents;
                    // Disable to prevent multiple launchs
                    Framework.Check.LogWarning("LAUNCHING EXTERNAL DEVICE WITH PATH: " + path);
                    process.Start(); // HERE The program reports the following:

这意味着,程序无法启动,因为ddip.dll丢失...尝试重新安装喇嘛喇嘛。

That means, "The program could not be started because ddip.dll is missing… try reinstalling bla bla".

的事情是,如果我执行的命令行一样@path,该程序打开完美的:

The thing is, if I execute the same @path from the command line, the program opens perfectly:

打开的程序。如果我点击快捷方式,它的位置在程序菜单同样的情况。有没有在该快捷方式的任何参数,它的可执行文件,一个简单的调用。

That opens the program. And the same happens if I click on the "shortcut" that it’s located in the "programs" menu. There aren’t any parameters in that shortcut, it’s a simple call to the executable file.

所以,现在的问题是:?之间我code和其他方法的区别是什么

So the question is now: What is the difference between my code and the other methods?

目前已经得到了是导致我的程序不启动不同的东西。

There has got to be something different that causes my process not to start.

任何想法?

更新和解决方案

我把它通过下面提供的答案中的一个工作。事实证明,没有直接向我指出了解决方案,但他们都给了我很好的想法在这里和那里。

I made it work by using one of the below provided answers. Turns out that none directly pointed me to the solution, but they all gave me good ideas here and there.

我添加一个应用程序清单到的我们的应用程序(应该因为Vista的时代了吧,不知道为什么这是不存在的第一名)。该应用程序清单,我添加使用VStudio 2008加载文件 - >应用程序清单。

I added an app manifest to our application (should have had it since the age of vista, don’t know why it wasn’t there in the 1st place). The app manifest I added by using VStudio 2008 add file -> app manifest.

在这,我确信我们有这样的:

In it, I made sure we have this:

<requestedExecutionLevel level="asInvoker" uiAccess="false" />

我们并不需要管理员之类的东西,但显然Vista / 7系统需要知道这一点。

We don’t need admin or anything like that, but apparently Vista/7 need to know it.

这加入后,处理被正确启动。

After that was added, the process is correctly launched.

注意的:UseShellExecute是真正默认情况下(如有些),你必须明确地将其设置为false,如果这就是你想要的。

note: UseShellExecute is true by default (as suggested by some), you have to explicitly turn it to false if that’s what you want.

推荐答案

如果该exe有一个清单,你应该设置UseShellExecute为true进程对象上调用开始之前。这不是在任何情况下,一个坏主意。

If the exe has a manifest, you should set UseShellExecute to true on the process object before you call Start. It's not a bad idea in any case.

这篇关于问题推出的System.Diagnostics.Process在Windows 7下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆