2009年6月7日 星期日

傳送互動式job至用戶端

一般要讓指令碼在用戶端執行~~僅需使用wmi中win32_process處理即可
若要讓指令碼作互動執行,則需透過Win32_ScheduledJob來處理~~
此外尚可透過現成的sysinternal的工具來直接部屬會更快速~~

On Error Resume Next
RemoteHost = "kido"
SendSourceToRemote RemoteHost
InstallScheduleJob RemoteHost

Sub SendSourceToRemote(RemoteHost)
Set WshShell = CreateObject("WScript.Shell")
ScriptPath = Left(WScript.ScriptFullName,Len(WScript.ScriptFullName) - Len(WScript.ScriptName))
SRCFile = ScriptPath & "writeEventLog.vbs"
DestPath = "c$\"
WshShell.Exec("cmd.exe /c xcopy " & SRCFile & " \\" & RemoteHost & "\" & DestPath & " /Y").StdOut.ReadAll
End Sub

Sub InstallScheduleJob(RemoteHost)
Const Delay = 2
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate, authenticationLevel=pktPrivacy}!\\" & RemoteHost & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each obj in colItems
LocalDateTime = obj.LocalDateTime
CurrentTimeZone = obj.CurrentTimeZone
Next
CurrentTime = Mid(LocalDateTime,9,2) & ":" & Mid(LocalDateTime,11,2)
ScheduleTime = "********" & Replace(FormatDateTime(DateAdd("n", Delay ,CurrentTime),4),":","") & "00.000000" & CurrentTimeZone

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
errcode = objNewJob.Create("c:\writeEventLog.vbs", ScheduleTime ,False, 0, , True, JobID)
End Sub

沒有留言: