skip to Main Content

I want to start process with arguments but it throws me an error

no file in directory found
heres code:

Process.Start(@"inject.exe example.dll example_process")

This is a bit modified code just for "showcase"
first argument is a DLL and second one is process name
basically whole code "works" (I mean it doesn’t throw errors in visual studio) but also doesn’t work as it throws exception with message file not found or something like that

2

Answers


  1. Looks like inject.exe is not in the executable folder. If you are not providing the fully qualified path to the process that you want to execute, then the path is assumed to be relative to the working folder of the current executable.

    You can work around this by including the folder path that inject.exe is located in, in the PATH environment variable.

    You can debug this by checking for the existence of the file first:

    string processPath = "inject.exe";
    Console.WriteLine("File: {0} Exists: {1}",
        System.IO.Path.GetFullPath(processPath),
        System.IO.File.Exists(processPath)
    );
    

    Parameterizing your process path will help debugging:

    string processPath = "C:CoolFolderinject.exe";
    if (System.IO.File.Exists(processPath))
        Process.Start(@"{processPath} example.dll example_process");
    else
        throw new ApplicationException(@"Inject not found: {processPath}");
    
    Login or Signup to reply.
  2. Replace "inject.exe" with the C:PathToinject.exe.
    If the "C:PathToinject.exe" file is not located in the specified directory, you may encounter a "file not found" exception in ex.Message.
    Also, the arguments must have the correct format for inject.exe.

    string exePath = @"C:PathToinject.exe";
    string arguments = "example.dll example_process";
    
    try
    {
        Process.Start(exePath, arguments);
    }
    catch (Exception ex)
    {
       String Err=ex.Message;  
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search