Python:使用wmi远程启动可执行文件 [英] Python: Using wmi to start executable remotely

查看:433
本文介绍了Python:使用wmi远程启动可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用wmi模块在Windows上远程运行可执行文件.它建立了连接,但是我认为我的过程行是不正确的,因为当我检查服务器时,可执行文件始终没有运行.你们可以在语法方面帮助我吗?

Im trying to run an executable file remotely on Windows using the wmi module. it establishes the connection but I think my process line is incorrect, as when I check the server the executable definately has not been run. Can you guys help me on the syntax with this?

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的帮助下),方法是创建一个运行我所需的一切的批处理文件,然后将其放在桌面上,然后运行它.

I managed to figure it out (With help from DDay) by creating a Batch file that ran everything that i needed and put it on the desktop and then ran that instead.

这篇关于Python:使用wmi远程启动可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆