gpt4 book ai didi

Python:使用 wmi 远程启动可执行文件

转载 作者:可可西里 更新时间:2023-11-01 10:55:54 29 4
gpt4 key购买 nike

我正在尝试使用 wmi 模块在 Windows 上远程运行可执行文件。它建立了连接,但我认为我的进程线不正确,因为当我检查服务器时,可执行文件肯定没有运行。你们能帮我解决这个问题的语法吗?

import wmi, time
ip = 'xx.xx.xx.xxx'
username = "user"
password = "password!"
from socket import *
print "Establishing connection to %s" %ip
connection = wmi.WMI(ip, user=username, password=password)
print "Connection established"
print "Starting IO"
connection.Win32_Process.Create(CommandLine='cmd.exe C:\Users\Public\Desktop\Auto_IOX.exe')
time.sleep(60)

最佳答案

import wmi, time
ip = 'xx.xx.xx.xxx'
username = "user"
password = "password!"
SW_SHOWNORMAL = 1
from socket import *
print "Establishing connection to %s" %ip
c = wmi.WMI(ip, user=username, password=password)
process_startup = c.Win32_ProcessStartup.new()
process_startup.ShowWindow = SW_SHOWNORMAL
process_id, result = c.Win32_Process.Create(CommandLine="C:\User\Administrator\Desktop\runIOX_auto.bat",ProcessStartupInformation=process_startup)
if result == 0:
print "Process started successfully: %d" % process_id
else:
raise RuntimeError, "Problem creating process: %d" % result

我设法弄清楚了(在 DDay 的帮助下),方法是创建一个批处理文件来运行我需要的所有内容并将其放在桌面上然后运行它。

关于Python:使用 wmi 远程启动可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29659469/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com