通过python在远程计算机中执行命令

时间:2019-04-25 08:50:02

标签: python subprocess psexec

我尝试通过python远程连接到Windows计算机,以使用“ PsExec.exe”执行命令,但是没有连接,也没有提示。

所以我的代码如下:


computerName = '10.10.0.18'
        commandText = 'PsExec.exe  \\\\' + computerName + ' cmd.exe'
        print(commandText)
        bn = subprocess.Popen(commandText, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        print(bn)

        stdout = bn.communicate()[0]
        stderr = bn.communicate()[1]
        rc = bn.returncode
        print(str(stderr.decode('utf-8')))
        print(str(stdout.decode('utf-8')))

以及stdout的输出:

PsExec v2.2 - Execute processes remotely
Copyright (C) 2001-2016 Mark Russinovich
Sysinternals - www.sysinternals.com

Microsoft Windows [Version 6.1.7601]

以及stderr的输出:

Connecting to 10.10.0.18...


Starting PSEXESVC service on 10.10.0.18...


Connecting with PsExec service on 10.10.0.18...


Starting cmd.exe on 10.10.0.18...



cmd.exe exited on 10.10.0.18 with error code 0.

非常感谢,

0 个答案:

没有答案