Execute exe on remote machine

前端 未结 4 684
孤城傲影
孤城傲影 2020-12-07 03:55

I\'m trying to execute notepad.exe on a remote machine, but it\'s not working now. What am I missing?

var ui = new ImpersonateUser();
    //the process to re         


        
相关标签:
4条回答
  • 2020-12-07 04:13

    Running an interactive program such as notepad.exe doesn't always open a visible window on the target PC. Try opening Task Manager on the target PC while you run the code and see if notepad.exe appears in the list of running processes.

    I'd suggest trying to run psexec from the command line first before attempting to call it via code.

    psexec \\serverName "notepad.exe"
    

    You may also want to use the "interactive" flag so it can interact with the desktop on the target.

    psexec \\serverName "notepad.exe" -i
    
    0 讨论(0)
  • 2020-12-07 04:13

    Your UNC path does not look good.

    After the string concatenation, it will look something like

      "\\serverNameC:\WINDOWS\notepad.exe"
    

    Try to print it out. See documentation about UNC on MSDN, and some examples here (or google about UNC Path)

    If you have only the default shares, it should be something like

      "\\serverName\C$\WINDOWS\notepad.exe"
    

    OR psexec let you use a different notation, but you have to be careful with double quotes there

      psexec \\serverName"c:\WINDOWS\notepad.exe"
    

    Also, ensure that the "Server" service is running on the target machine.

    PsExec starts an executable on a remote system and controls the input and output streams of the executable's process so that you can interact with the executable from the local system. PsExec does so by extracting from its executable image an embedded Windows service named Psexesvc and copying it to the Admin$ share of the remote system. PsExec then uses the Windows Service Control Manager API, which has a remote interface, to start the Psexesvc service on the remote system.

    The Admin$ share is created and managed by the "Server" service, so you need it running for psexec to work (http://windowsitpro.com/systems-management/psexec).

    0 讨论(0)
  • 2020-12-07 04:14

    Just to extend current version of answer. There could be a problem of execution psexec due to OS policy, to enable remote control you need to modify registry:

    reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\system /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1 /f
    

    You can check this: Remote UAC LocalAccountTokenFilterPolicy

    0 讨论(0)
  • 2020-12-07 04:22

    The answer was a combination from your replies. But the whole correct solution was:

            ProcessStartInfo info = new ProcessStartInfo("C:\\PsTools");
            info.FileName = @"C:\PsTools\psexec.exe";
            info.Arguments = @"\\" + serverName + @" -i C:\WINDOWS\notepad.exe";
            info.RedirectStandardOutput = true;
            info.UseShellExecute = false;
            Process p = Process.Start(info);
    
    0 讨论(0)
提交回复
热议问题