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

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

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.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值