【发布时间】:2014-07-09 03:55:12
【问题描述】:
不幸的是,Python 脚本旨在使用提升的凭据运行
- 它仍然提示我输入密码
- 当我输入正确的密码时它不起作用
这里是 script1,它使用提升的凭据调用 script2
import os
import sys, subprocess, socket, string
import wmi, win32api, win32con
import win32com.shell.shell as sh
ASADMIN = '/user:DOMAIN\username'
os.system('"runas /user:DOMAIN\username "D:/Python27/python.exe script2.py sender-ip=10.10.10.10 < password.txt""')
sys.exit(0)
if sys.argv[-1] != ASADMIN:
script = os.path.abspath(sys.argv[0])
params = ''.join([ASADMIN] + ['D:\Python27\python.exe',script] + sys.argv[1:])
sh.ShellExecuteEx(lpVerb='runas',lpFile=sys.executable,lpParameters=params)
sys.exit(0)
这里是脚本2
导入系统、子进程、套接字、字符串 导入 wmi、win32api、win32con
对于 [item.strip('sender-ip=') 中的 args 对于 sys.argv[1:]] 中的项目:
userIP = args
userloggedon = ""
# perform system lookup of IP address
userIP = "\\\\" + userIP
pst = subprocess.Popen(
["D:\pstools\psloggedon.exe", "-l", "-x", userIP],
stdout = subprocess.PIPE,
stderr = subprocess.PIPE
)
out, error = pst.communicate()
userLoggedOn = out.split('\n')[1].strip()
print 'userId={}'.format(userLoggedOn)
f = open('D:\SymantecDLP\Protect\plugins\output.txt', 'w')
f.write('userId={}'.format(userLoggedOn))
output.txt 未创建
有什么想法吗?
编辑
我也读过这个帖子,How to supply password to runas command when executing it from java
但无论我尝试什么,我都会不断收到错误
Attempting to start c:\test.bat as user "DOMAIN\username" ...
RUNAS ERROR: Unable to run - c:\test.bat
1326: Logon failure: unknown user name or bad password.
【问题讨论】:
-
如果你这样做
print out会得到什么? -
@pss -- 我在哪里保存“打印输出”
-
倒数第五行,即
out, error = pst.communicate()之后 -
He publicado una respuesta, pero si usted publica información sobre el error que se obtiene a partir de la ejecución de su código, se podría mejorar。
标签: python elevated-privileges