Skip to main content
 首页 » 编程设计

Python 脚本不执行 sysinternals 命令

2025年05月04日6lexus

这是 Invoke pstools in Python script 的跟进

当我打开命令提示符并执行时

D:\pstools\psloggedon.exe -l -x \\10.10.10.10 

我明白了

DOMAIN\user 

但是当我执行脚本的时候

import sys, subprocess, socket, string 
import wmi, win32api, win32con 
 
 
 
pst = subprocess.Popen( 
        ["D:\pstools\psloggedon.exe", "-l", "-x", "\\10.10.10.10"], 
        stdout = subprocess.PIPE, 
        stderr = subprocess.PIPE 
    ) 
 
out, error = pst.communicate() 
 
 
print out, "is output" 

我明白了

Error opening HKEY_USERS for \10.10.10.10 
is output 

如何让子进程将 IP 地址读取为\10.10.10.10 而不是\10.10.10.10

顺便说一下,我尝试添加第三个反斜杠

pst = subprocess.Popen( 
        ["D:\pstools\psloggedon.exe", "-l", "-x", "\\\10.10.10.10"], 
        stdout = subprocess.PIPE, 
        stderr = subprocess.PIPE 
    ) 

输出是

Error opening HKEY_USERS for .0.139.40 
is output 

请您参考如下方法:

正如 lejlot 的评论所建议的,您必须使用“\\”,因为“\”是 python 中的转义字符。