PsExec hang while being executed from a very simple c# or c++ gui program compiled as “windows application”

前端 未结 6 720
日久生厌
日久生厌 2021-01-18 12:04

I am experiencing PsExec hang while being executed from a very simple c# or c++ gui program compiled as \"windows application\" (not as \"console application\"). Under sect

相关标签:
6条回答
  • 2021-01-18 12:10

    Please also set the WorkingDirectory property on startInfo, as Sysinternals utilities use run-time unpacking of files and the kernel is unable to find the unpacked (real) exectutable file.

    0 讨论(0)
  • 2021-01-18 12:11

    Build a generic Console Application which runs PsExec & PsKill and all of their friends. Call this ConsoleApp through your code instead of calling the NotWorkingPsExec method, and it'll work just fine.

    0 讨论(0)
  • 2021-01-18 12:12

    PSExec was hanging for me too randomly. I haven't put the effort into recreating the issue your way, but I have avoided my troubles by using "PAExec", a seemingly worthy successor in spirit: http://www.poweradmin.com/PAExec/

    0 讨论(0)
  • 2021-01-18 12:12

    Synchronous read on the stream works:

            ProcessStartInfo startInfo = new ProcessStartInfo("psexec.exe", @"\\localhost cmd.exe /c dir c:\windows\*.*");
            startInfo.UseShellExecute = false;
            startInfo.CreateNoWindow = true;
            startInfo.RedirectStandardOutput = true;
            //startInfo.RedirectStandardError = true;
            //startInfo.RedirectStandardInput = true;
    
            Process proc = new Process();
            proc.StartInfo = startInfo;
            //proc.ErrorDataReceived += new DataReceivedEventHandler(DataReceiveHandler);
            //proc.OutputDataReceived += new DataReceivedEventHandler(DataReceiveHandler);
            proc.Start();
            //proc.BeginErrorReadLine();
            //proc.BeginOutputReadLine();
            string output = proc.StandardOutput.ReadToEnd();
            proc.WaitForExit();
            Console.WriteLine(output);
            Console.WriteLine("Exit code = {0}", proc.ExitCode);
    

    Even here, note that the ReadToEnd() should be done before the WaitForExit().

    I believe PSExec always had problems like this. When running under Java service, we used to redirect the output to nul and couldn't get the output of the running process, but can get the output of PSExec itself.

    Refer to below given discussions:

    http://forum.sysinternals.com/psexec-always-hangs-when-run-from-java_topic5013.html

    http://forum.sysinternals.com/unusual-problem-with-psexecexe_topic6655.html

    Edit:

    Note on PSEXESVC cleanup: Delete the PSEXESVC.EXE file at C:\Windows ( or C:\Windows\system32 or both ) after killing the hung PSEXESVC process. Lingering process / file cause more problems.

    0 讨论(0)
  • 2021-01-18 12:17

    I have a simple solution for this,

    1. C# run the process like:

      Process.Start("start run.bat xx.txt");    //call it async
      
      //and then we make some code juse wait xx.txt appear and finish written .
      
    2. run.bat is :

      psexec.bat > %1           //redirect to a text file
      exit
      
    3. psexec.bat is:

      psexec.exe ..........................
       exit
      
    0 讨论(0)
  • 2021-01-18 12:29

    I had a similar problem that was due to the eula, which may be yours:

    Possible reasons:

    1) psiexec.exe shows EULA message during first run.

    2) Permissions

    3) dll function can require user session.

    To avoid these issues please try following scenarios:

    1) with "-accepteula" argument

    2) with "-s" argument

    3) with "-i" argument

    4) > 2 + 3 5) 2 + 3 + 1

    See: http://www.appdeploy.com/messageboards/tm.asp?m=72376&mpage=1&key=𑪸

    Even though I had checked the EULA several times

    0 讨论(0)
提交回复
热议问题