使用PsExec时如何在pythonsub进程中访问stdin和stdout

2024-09-29 19:37:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我在python子进程中运行psexec

import subprocess

prog = subprocess.Popen([
    'C:\\Users\\user\\tools\\PSTools\\PsExec.exe', 
    '-u', 
    'admin', 
    "-p", 
    "pass",
    "cmd.exe"], 
    stdin=subprocess.PIPE, 
    stdout=subprocess.PIPE, 
    stderr=subprocess.PIPE, 
    universal_newlines=True
)

在这样做的过程中,psexec打开了一个新的提升终端窗口,我想问的是,是否有必要通过子流程来控制这个窗口,因为它是最初启动它的?因为目前stdin和stdout似乎只是启动psexec的子进程,而不是psexec生成的终端

抱歉,如果这是个愚蠢的问题,我只是想寻求帮助


Tags: import终端进程stdinstdouttoolsexeusers
1条回答
网友
1楼 · 发布于 2024-09-29 19:37:47

PsExec使用管理共享将文件复制到目标计算机,然后将其作为服务启动,然后该服务启动指定的程序。所以你的程序没有连接

使用COM

Starts execution of a remote script object.

object.Execute

Parameters

object

WshRemote Object

Remarks

The Start event of the WshRemote object is fired when the script starts executing. Do not confuse the Execute method with the Exec method (of the WScript object).

Example

The following example demonstrates how the Execute method is used to create a WshRemote object (start an instance of a remote script).

[VBScript]

Dim Controller, RemoteScript
Set Controller = WScript.CreateObject("WSHController")
Set RemoteScript = Controller.CreateScript("remote1.js")
RemoteScript.Execute

Do While RemoteScript.Status <> 2 
    WScript.Sleep 100
Loop

[JScript]

var Controller = WScript.CreateObject("WSHController");
var RemoteScript = Controller.CreateScript("remote1.js");
RemoteScript.Execute();

while (RemoteScript.Status != 2) {
    WScript.Sleep(100);

来自帮助http://download.microsoft.com/download/winscript56/Install/5.6/W982KMeXP/EN-US/scrdoc56en.exe

相关问题 更多 >

    热门问题