找回密码
 加入
搜索
查看: 14280|回复: 28

[网络通信] 通过wmi使用计划任务启动批量远程win7系统的某个应用程序

 火.. [复制链接]
发表于 2012-6-1 15:46:00 | 显示全部楼层 |阅读模式
本帖最后由 cj-reggie 于 2012-6-27 15:51 编辑

功能需求是使用一台计算机远程启动其他机器win7系统的一个应用程序,有管理员权限,以及ip地址及机器名,求大神给个思路
以上为求思路贴
以下为求助
1.xp下已经搞定,使用计划任务即可,但是win7系统下则不行
2.wmi连接不成功脚本会停止运行,比如相同配置的机器,机器名:F0~F9,F5连接失败(不知道为什么,用户名密码都一样的机器)则F6~F9就不执行了
Func RemoteExecute($top)
    $computer=$top&$i
        dim $objsch,$objinfo,$objtime,$act
        
        for $i=0 to 9
        
        $act=ping($computer)
        if $act then
$objlocator= ObjCreate ("wbemscripting.swbemlocator")
 If @error Then
      ;  MsgBox(0, "Error", "Error: failed to create $$objlocator")
        ContinueLoop
    EndIf
$objWMI=$objlocator.connectserver($computer,"root/cimv2",$Remoteuser,$Remotepass)
 If @error Then
;~         MsgBox(0, "Error", "学生机未开机或未连接网络")
                ;$output[$i]=$computer
        continueloop
    EndIf
$objWMI.Security_.ImpersonationLevel = 3

$objsch = $objWMI.Get("Win32_ScheduledJob")

$objtime=@hour&string(number(@min)+2)

        $objInfo = $objsch.Methods_("Create").InParameters.SpawnInstance_
        $objInfo.Properties_.Item("StartTime") = "********"&$objtime&"00.000000"&"+480"
        $objinfo.command = $strprogtorun
        $objinfo.interactwithdesktop=true
        $objinfo.runrepeatedly=true
        
 $objWMI.ExecMethod("Win32_ScheduledJob", "Create", $objinfo)  
 else
         continueloop
         endif
 next
 EndFunc  
发表于 2012-6-1 16:49:57 | 显示全部楼层
你这个小神都没折?那你怎么往下写?
不外乎 C-S模式
这种就好处理,不麻烦
或者以管理员登录远程计算机执行命令。
这种就要看远程计算机的设置,或许没开远程服务,或者更换了密码用户名,失效
或者7788的设置,软件导致不能连接等等
 楼主| 发表于 2012-6-1 20:50:03 | 显示全部楼层
回复 2# nivisde


    在考虑用wmi,因为菜啊所以先来问问经验啊,远程计算机我都可以设置,机房都是我管
发表于 2012-6-1 21:32:22 | 显示全部楼层
回复 3# cj-reggie


    论坛有个WMI的例子,但是没有开源,你批量在一个电脑上跑一个应用程序?能说说你的具体用途吗?可能我能帮得到你
发表于 2012-6-1 21:37:42 | 显示全部楼层
一同学习了。
我用WEB实现过,就是有点麻烦。
 楼主| 发表于 2012-6-1 22:29:26 | 显示全部楼层
回复 4# 502762378


    是在一台机器上批量的远程运行多台机器中的同一个应用程序
 楼主| 发表于 2012-6-2 12:14:03 | 显示全部楼层
自己顶起求思路啊,process.create能做到么?
 楼主| 发表于 2012-6-2 12:14:10 | 显示全部楼层
自己顶起求思路啊,process.create能做到么?
 楼主| 发表于 2012-6-2 12:14:13 | 显示全部楼层
自己顶起求思路啊,process.create能做到么?
发表于 2012-6-2 13:14:02 | 显示全部楼层
回复 9# cj-reggie
简单点的话还是客户端,服务端,这样比较稳妥!
 楼主| 发表于 2012-6-2 15:15:24 | 显示全部楼层
回复 10# xms77


    这样的如果客户端被干掉就失效了
发表于 2012-6-2 15:36:25 | 显示全部楼层
回复 11# cj-reggie
当然客户端保护也要做的,比如进程影藏,提升进程或者双进程保护。我用的就是双进程保护,两个进程都有检测对方进程是否存在,如果不存在就运行对方进程,有点类似互锁一样。一般很难同时干掉两个进程的吧!
 楼主| 发表于 2012-6-2 15:50:30 | 显示全部楼层
回复 12# xms77


    现有的就是双进程保护,进程名也是系统进程的,taskkill级别杀不掉的进程
 楼主| 发表于 2012-6-4 09:14:36 | 显示全部楼层
顶上去啊,求大神指点一下思路
 楼主| 发表于 2012-6-5 12:33:35 | 显示全部楼层
本帖最后由 cj-reggie 于 2012-6-5 13:20 编辑

从官方论坛上搜到段代码,远程建立进程成功,但是不出gui界面,比如启动记事本程序,进程有不出界面
; From remote pc this works \\mikespc\sharename\DebugAgent.exe
; From remote pc this does not work \\192.168.1.102\sharename\DebugAgent.exe                        ; Fine... doesn't work with IP address spec'ing pc

;RemoteExecute("\\mikespc\c$\AutoITStuff\\agents\DebugAgent.exe")                                   ; This doesn't work - using the full path
;RemoteExecute("\\share\DebugAgent.exe")                                                            ; This doesn't work - using a share
;RemoteExecute("p:\DebugAgent.exe")                                                                 ; This doesn't work - using a drive letter mapped to a share
;RemoteExecute("cmd.exe /c start p:\DebugAgent.exe")                                                ; This launches a process named cmd.exe but there is no window.
;RemoteExecute("cmd.exe /c p:\DebugAgent.exe")                                                      ; This launches a process named cmd.exe but there is no window.

;RemoteExecute("c:\windows\system32\calc.exe")                                                      ; This works - executes on local pc
;RemoteExecute("cmd.exe /c dir c:\windows\system32\calc.exe")                                       ; This does nothing
;RemoteExecute("cmd.exe /c start c:\windows\system32\calc.exe")                                     ; This launches a process named calc.exe but there is no window

; DebugAgent is simply a MsgBox. Thinking that maybe that's 'too interactive' I tried just Sleep(10000) to give long enought to see if anything happens, but no.

;*****************************

; This func runs the passed prog on the remote or local pc spec'ed by $strComputer. Will NOT show gui if remote, but will on local pc.

Func RemoteExecute($strProgToRun)

    Local $objWMIService, $objProcess, $objProgram

    $objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator")
    If Not IsObj($objSWbemLocator) Then
        MsgBox(0, "Error", "Error: failed to create $objSWbemLocator")
        Exit
    EndIf

    $objWMI = $objSWbemLocator.ConnectServer($strComputer, "root\cimv2", $strUsername, $strPassword)    ; This works for remote pc if pass actual credentials and works for local if pass null credentials
    If Not IsObj($objWMI) Then
        MsgBox(0, "Error", "Error: failed to create $objWMI")
        Exit
    EndIf

    $objWMI.Security_.ImpersonationLevel = 3

    $objProcess = $objWMI.Get("Win32_Process")

    $objProgram = $objProcess.Methods_("Create").InParameters.SpawnInstance_
    $objProgram.CommandLine = $strProgToRun

    $objWMI.ExecMethod("Win32_Process", "Create", $objProgram)                                          ; Execute the program now at the command line.

EndFunc

评分

参与人数 1金钱 +30 收起 理由
502762378 + 30

查看全部评分

您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-4 16:34 , Processed in 0.085073 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表