简体   繁体   中英

DirectX app unable to load through Process.Start on Windows Server 2012 R2, works fine through CMD or on local machine

I have an app that runs DirectX 11 that plays a scene and generates an mp4. I am trying to launch it through Process.Start so that I can manage the process and force it to timeout if it crashed or doesn't close correctly.

When I test the function on my local Win10 machine it works perfectly, and when I run it through CL or a.BAT file on the WinServ2012R2 machine it works perfectly too. However when I try to run it through the Process.Start function on the server machine it fails to open DirectX

var startInfo = new System.Diagnostics.ProcessStartInfo($"{AppLocation}", $"{Parameters}")
{
   WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal,
   UseShellExecute = false,
   RedirectStandardOutput = true,
   CreateNoWindow = false,
   WorkingDirectory = $"{DirectoryName}",
   Verb = "runas"
};

var loop = 0;
while (!System.IO.File.Exists($"{FileLocation}"))
{
   loop++;
   using (var p = System.Diagnostics.Process.Start(startInfo))
   {
      Logger.Info("Process Running....");
      if (!p.WaitForExit(300000))
      {
         p.Kill();
      }
      if (loop >= 5)
         break;
    }
}

Edit: The DirectX error is: DXGI_ERROR_NOT_CURRENTLY_AVAILABLE 0x887A0022

It's probably something about the environment.

If the parent process is a normal Win32 console or GUI app running inside a desktop of that server, put something like Sleep( 60000 ); in the first line of your main() or WinMain function, and use Process Explorer to find differences between manual launch which works, and programmatic launch which fails. Check the “Image”, “Security” and “Environment” tabs of the processes.

If the parent process is a system service, it's more complicated. Services generally run under another user account and you gonna need some setup to allow the service, or a child process launched by the service, to access GPU.

Another possible reason is anti-virus or anti-malware breaking things.

PS Note you have minor bugs in your code.

One thing, when you detect timeouts, Process.Kill is asynchronous , you need to wait afterwards.

Another one, you specifying RedirectStandardOutput = true but you don't consume that stream. If the child process prints a lot of text it will eventually stall waiting for the parent process to consume the data buffered in that pipe. If you don't care about output, don't redirect these streams. If you do care, redirect and consume the data as soon as it printed, either on a separate thread or with async/await.

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