Python 2.7:wmi 模块:在远程系统上创建交互式进程

发布于 2024-12-28 02:09:19 字数 1378 浏览 1 评论 0原文

为可能的远程系统创建一个安装程序,这样如果他们没有安装某些东西,它将在他们的桌面上启动 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

简单 2025-01-04 02:09:19

这是 < 的限制Create 方法href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa394372%28v=vs.85%29.aspx" rel="nofollow">Win32_Process WMI 类

出于安全原因,Win32_Process.Create 方法不能用于
远程启动交互过程。

Windows 2000 Professional SP2 及更早版本、Windows NT 和 Windows 98/95

Win32_Process.Create可以创建交互式进程
远程。

This is a limitation of the Create method of the Win32_Process WMI class

For security reasons the Win32_Process.Create method cannot be used to
start an interactive process remotely.

Windows 2000 Professional with SP2 and earlier, Windows NT, and Windows 98/95

Win32_Process.Create can create an interactive process
remotely.

影子的影子 2025-01-04 02:09:19

不幸的是,PSEXEC 看起来像是这里唯一可行的解​​决方案......尽管我讨厌调用第 3 方工具,但它效果很好。

import subprocess
import getpass

Oracle = r'\\server\z$\deploy\Install\Oracle\Oracle9i_Disk1\Oracle9i_Disk1\autorun\autorun.exe'

def Craft_Startup(COMPUTER, COMMAND):
    UNAME="DOMAIN\\"+getpass.getuser()
    PASSWD = getpass.getpass()
    subprocess.Popen("psexec -u "+ UNAME +" -p " + PASSWD + " \\\\"+COMPUTER+" -i " + COMMAND)


if __name__ == '__main__':
    COMPUTER = 'P04213'
    COMMAND = Oracle
    Craft_Startup(COMPUTER, 'cmd.exe /c start ' + COMMAND)

所以这里有必要将 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.

import subprocess
import getpass

Oracle = r'\\server\z$\deploy\Install\Oracle\Oracle9i_Disk1\Oracle9i_Disk1\autorun\autorun.exe'

def Craft_Startup(COMPUTER, COMMAND):
    UNAME="DOMAIN\\"+getpass.getuser()
    PASSWD = getpass.getpass()
    subprocess.Popen("psexec -u "+ UNAME +" -p " + PASSWD + " \\\\"+COMPUTER+" -i " + COMMAND)


if __name__ == '__main__':
    COMPUTER = 'P04213'
    COMMAND = Oracle
    Craft_Startup(COMPUTER, 'cmd.exe /c start ' + COMMAND)

So the necessity here is to put psexec in the system32 folder or... specify the path if you'd like

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文