通过wmi使用计划任务启动批量远程win7系统的某个应用程序
本帖最后由 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 你这个小神都没折?那你怎么往下写?
不外乎 C-S模式
这种就好处理,不麻烦
或者以管理员登录远程计算机执行命令。
这种就要看远程计算机的设置,或许没开远程服务,或者更换了密码用户名,失效
或者7788的设置,软件导致不能连接等等 回复 2# nivisde
在考虑用wmi,因为菜啊所以先来问问经验啊,远程计算机我都可以设置,机房都是我管 回复 3# cj-reggie
论坛有个WMI的例子,但是没有开源,你批量在一个电脑上跑一个应用程序?能说说你的具体用途吗?可能我能帮得到你 一同学习了。
我用WEB实现过,就是有点麻烦。 回复 4# 502762378
是在一台机器上批量的远程运行多台机器中的同一个应用程序 自己顶起求思路啊,process.create能做到么? 自己顶起求思路啊,process.create能做到么? 自己顶起求思路啊,process.create能做到么? 回复 9# cj-reggie
简单点的话还是客户端,服务端,这样比较稳妥! 回复 10# xms77
这样的如果客户端被干掉就失效了 回复 11# cj-reggie
当然客户端保护也要做的,比如进程影藏,提升进程或者双进程保护。我用的就是双进程保护,两个进程都有检测对方进程是否存在,如果不存在就运行对方进程,有点类似互锁一样。一般很难同时干掉两个进程的吧! 回复 12# xms77
现有的就是双进程保护,进程名也是系统进程的,taskkill级别杀不掉的进程 顶上去啊,求大神指点一下思路 本帖最后由 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]
2