Python 2.7:wmi 模块:在远程系统上创建交互式进程
为可能的远程系统创建一个安装程序,这样如果他们没有安装某些东西,它将在他们的桌面上启动 autorun.exe (当然,给他们链接很容易,他们可以单击开始并运行......但是这个如果为他们做的话会更好 100%!)
这是我一直在使用的模型,我应该提到我正在 Windows 7 和 XP 机器之间进行测试,尽管我认为这没什么大不了的。
import wmi
import win32com.client
def Copy_Program(computer=None, environment="Production"):
Oracle_install = r'\\server1\Install\Oracle\Oracle9i_Disk1\autorun\autorun.exe'
""" BELOW PROCESS SHOWS UP IN TASKMANAGER, but I NEED IT TO BE INTERACTIVE.
wmi = win32com.client.GetObject ("winmgmts:\\\\"+computer+"\\root\\cimv2")
win32_process = wmi.Get ("Win32_Process")
in_parameters = win32_process.Methods_ ("Create").InParameters
in_parameters.Properties_ ('CommandLine').Value = "notepad.exe"
result = win32_process.ExecMethod_ ("Create", in_parameters)
"""
SW_SHOWMINIMIZED = 1
c = wmi.WMI (computer)
startup = c.Win32_ProcessStartup.new (ShowWindow=SW_SHOWMINIMIZED)
pid, result = c.Win32_Process.Create (
CommandLine=Oracle_install,
ProcessStartupInformation=startup
)
if __name__ == '__main__':
Copy_Program(computer = "D02659")
现在,正如蒂姆·戈尔登先生在文档中提到的那样……远程连接到另一台机器非常简单……您只需
c = wmi.WMI("REMOTE_COMPUTER")
离开即可……
从技术上讲,它确实有效,但由于某种原因它不具有交互性……我'我还修改了 SW_SHOWMINIMIZED 值,但我似乎无法理解我做错了什么。我有域管理员,所以这不应该是问题...特别是因为我同时登录两个系统...奇怪。
无论如何,非常感谢您的帮助!
Creating an installer for possible remote systems so that if they do not have something installed, it will start the autorun.exe on their desktop (sure it would be easy to give them the link and they could click start and run... but this would be 100% better if it was done for them!)
Heres the model I have been using and I should mention that I am testing between both a windows 7 and XP machine, although I don't think its too big of a deal.
import wmi
import win32com.client
def Copy_Program(computer=None, environment="Production"):
Oracle_install = r'\\server1\Install\Oracle\Oracle9i_Disk1\autorun\autorun.exe'
""" BELOW PROCESS SHOWS UP IN TASKMANAGER, but I NEED IT TO BE INTERACTIVE.
wmi = win32com.client.GetObject ("winmgmts:\\\\"+computer+"\\root\\cimv2")
win32_process = wmi.Get ("Win32_Process")
in_parameters = win32_process.Methods_ ("Create").InParameters
in_parameters.Properties_ ('CommandLine').Value = "notepad.exe"
result = win32_process.ExecMethod_ ("Create", in_parameters)
"""
SW_SHOWMINIMIZED = 1
c = wmi.WMI (computer)
startup = c.Win32_ProcessStartup.new (ShowWindow=SW_SHOWMINIMIZED)
pid, result = c.Win32_Process.Create (
CommandLine=Oracle_install,
ProcessStartupInformation=startup
)
if __name__ == '__main__':
Copy_Program(computer = "D02659")
Now as Mr Tim Golden had mentioned in the docs... remoting to another machine is pretty simple... you just
c = wmi.WMI("REMOTE_COMPUTER")
and away you go...
and technically it does work, but its not interactive for some reason... I've also tinkered with the SW_SHOWMINIMIZED values, but I can't seem to understand what I'm doing wrong. I have domain admin, so it shouldn't be an issue... especially since I am logged into both systems at the same time... weird.
Anyhow, help is very much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是 < 的限制Create 方法href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa394372%28v=vs.85%29.aspx" rel="nofollow">Win32_Process WMI 类
This is a limitation of the
Create
method of the Win32_Process WMI class不幸的是,PSEXEC 看起来像是这里唯一可行的解决方案......尽管我讨厌调用第 3 方工具,但它效果很好。
所以这里有必要将 psexec 放在 system32 文件夹中或者...如果您愿意,请指定路径
PSEXEC looks like its the only viable solution here unfortunately... as much as I hate to invoke a 3rd party tool, this works well.
So the necessity here is to put psexec in the system32 folder or... specify the path if you'd like