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

我试图在Windows上使用wmi模块远程运行可执行文件。 它build立了连接,但我认为我的stream程线是不正确的,因为当我检查服务器时,可执行文件肯定没有运行。 你们可以帮我在这个语法?

import wmi, time ip = '10.12.62.186' username = "administrator" password = "CLARiiON!" 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) 

Solutions Collecting From Web of "Python:使用wmi远程启动可执行文件"

看看Tim Golden的教程 。 您没有使用Win32_Process.Create方法返回的信息。

 process_id, result = c.Win32_Process.Create( CommandLine="notepad.exe", ProcessStartupInformation=process_startup ) 

因此,您可能会错过进程ID和启动该远程进程的结果。

 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的帮助)创建一个批处理文件,运行我需要的一切,把它放在桌面上,然后运行它。