Problem starting System.Diagnostics.Process on Windows 7

I am trying to run an application (operating system, my application and the application I want to run, all 32 bits) from .NET 3.51.

The code that starts Process is used for other applications, but one that gives us a headache. If we double-click the application icon, it works as expected, which means that it works great as an application on a computer. Double-clicking .exe directly also works.

Operating system - Windows 7 32Bits (home and / or professional).

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

The code that starts the "Processes" is inside the DLL (also 32 bits) that we made, basically it is a simple DLL that contains some "common code" in all directions, common methods, functions, etc. that we use throughout our the code. One of these methods is as follows:

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

I don’t know who wrote this method, but it has been working for about six years with different applications, so I assume that it is “good”. However, we do have a client with a piece of software that does not start when passing this argument.

Arguments :

  • a process is System.Diagnostics.Process, created using a simple "new process ();"
  • path is the full path to the .exe "c: /path/to/my.exe".
  • enableRaisingEvents
  • windowStyle ( ).

crappy MessageBox... . , :

alt text

:

(0x0eedfade) ...

Googling, 0x0eedfade , , , , .exe, Im , .

: (I.e.: Notepad.exe, Adobe Acrobat Reader), , , Firefox .

" , " , Windows 7 , .

- ?

: Ok; Ive . , . , , , FireUpProcess.

, WorkDirectory, :

    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:

alt text

, " - ddip.dll... bla bla".

, @path , :

alt text

. , "", "". , .

, : ?

- , .

?

. , , .

( , , 1- ). , VStudio 2008 add file → application manifest.

, :

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

- , , , Vista/7 .

.

note: UseShellExecute ( ), false, , .

+5
6

exe , Start UseShellExecute true . .

+5

process.StartInfo.WorkingDirectory. , , , EXE. , :

 process.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(@path);

. .

+8

, "" , , UseShellExecute true. , ShellExecute.

, UAC Windows (Vista, 7, 2008,...), , runas , .

.NET :

if (System.Environment.OSVersion.Version.Major >= 6)  // UAC around...
{
   processStartInfo.Verb = "runas";
}
+3

. , cmd :

public static bool FireUpProcess(Process process, string path, bool enableRaisingEvents, ProcessWindowStyle windowStyle) 
{ 
    //if path contains " ", surround it with quotes.
    //add /c and the path as parameters to the cmd process. 
    //Any other parameters can be added after the path.

    ProcessStartInfo psi = new ProcessStartInfo("cmd", "/c" + path ));            
    psi.WorkingDirectory = System.IO.Path.GetDirectoryName(@path);          
    psi.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(); ...}
+1

, Process Monitor Sysinternals. (5 ). . , "" ( ), " " ( "" ) . , , . exectuable NAME NOT FOUND. , , . dll, Ctrl + F, , . .

, PATH ? , . ( ) dll. ? , Programm Files, ( ). Windows . . , , , , , "", UAC. , , , Program Files, .

+1

, . , , , ddip.dll exe . , . , GAC AssemblyResolve. , , . exe, AssemblyResolve. , , , .

Since you get an exception for a missing DLL, I have little confidence in answers to problems with path separators. However, you have application code, so make sure it references ddip.dll. This will give you great confidence that you are actually referencing the correct .exe, and therefore this is not just a command line path separator problem (EG misinterpreted spaces).

0
source

All Articles