Paul_Schroeder
asked on
Execute a schedule task from a remote Server
How do you execute a scheduled task from a remote server?
Can you do in WMI Service?
Thanks
Can you do in WMI Service?
Thanks
ASKER
No, what I want to do is not to have a particular schedule, but execute from a vbscript or via WMI service. I was able to schedule a new task remotely with WMI Service, but I am having problems getting the right time value because it is the UTC date. Also I when creating the task it would not set the runas or password so it would not run.
The bottom line is: I would like to be able to execute a .vbs script on a remote server somehow. That is what I am trying to do. If you know a way to do it that would be great.
I tryed doing using the WMI Service but I could not get the script to run doing the createProcess, but the schedule task would work. Here is the script that I am testing.
Function Main()
dim objAccessApp,process
dim objWMIService,objStartup,o bjConfig
dim StrComputer,strSec,strHour ,strMin
strComputer = "AAA93"
if len(hour(now)) = 1 then
strHour = "0" & hour(now)
else
strHour = hour(now)
end if
if len(minute(now)) = 1 then
strMin = "0" & (Cint(Minute(now)) + 1)
else
strMin = Cint(Minute(now)) + 1
end if
if len(second(now)) = 1 then
strSec = "0" & second(now)
else
strSec = Second(now)
end if
Set objwmiLocator = CreateObject("WbemScriptin g.SWbemLoc ator")
Set objwmiService = objwmiLocator.ConnectServe r("AAA93" , "root\cimv2", "user", "password", , , iSecurityFlags = 128)
objwmiLocator.Security_.Im personatio nLevel = 3
'Set objStartup = objWMIService.Get("Win32_P rocessStar tup")
'Set objConfig = objStartup.SpawnInstance_
Set objNewJob = objWMIService.Get("Win32_S cheduledJo b")
schTime = "********" & strHour & StrMin & strSec & ".000000-000"
errJobCreated = objNewJob.Create("C:\Confi g\rptDenta Max.vbs", schTime, False , , , True, JobID)
'Set objProcess = GetObject("winmgmts:root\c imv2:Win32 _Process")
'errReturn = objProcess.Create("\Config \rptDentam ax.vbs", null,objConfig, intProcessID)
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
Const ForReading = 1, ForWriting = 2, ForAppending = 8
log_location = "\\AAA93\Config\NEW"
Set errors = fso.OpenTextFile(log_locat ion & "_diskrpt_wmi_exceptions.l og", ForWriting, True)
Main = DTSTaskExecResult_Success
End Function
The bott
The bottom line is: I would like to be able to execute a .vbs script on a remote server somehow. That is what I am trying to do. If you know a way to do it that would be great.
I tryed doing using the WMI Service but I could not get the script to run doing the createProcess, but the schedule task would work. Here is the script that I am testing.
Function Main()
dim objAccessApp,process
dim objWMIService,objStartup,o
dim StrComputer,strSec,strHour
strComputer = "AAA93"
if len(hour(now)) = 1 then
strHour = "0" & hour(now)
else
strHour = hour(now)
end if
if len(minute(now)) = 1 then
strMin = "0" & (Cint(Minute(now)) + 1)
else
strMin = Cint(Minute(now)) + 1
end if
if len(second(now)) = 1 then
strSec = "0" & second(now)
else
strSec = Second(now)
end if
Set objwmiLocator = CreateObject("WbemScriptin
Set objwmiService = objwmiLocator.ConnectServe
objwmiLocator.Security_.Im
'Set objStartup = objWMIService.Get("Win32_P
'Set objConfig = objStartup.SpawnInstance_
Set objNewJob = objWMIService.Get("Win32_S
schTime = "********" & strHour & StrMin & strSec & ".000000-000"
errJobCreated = objNewJob.Create("C:\Confi
'Set objProcess = GetObject("winmgmts:root\c
'errReturn = objProcess.Create("\Config
Set fso = CreateObject("Scripting.Fi
Const ForReading = 1, ForWriting = 2, ForAppending = 8
log_location = "\\AAA93\Config\NEW"
Set errors = fso.OpenTextFile(log_locat
Main = DTSTaskExecResult_Success
End Function
The bott
Using the "schtasks" you can specify user/password. Is this good enough?
ASKER
How do you set the user/Password? What is "schtasks" is it a different object?
If I can set the user/password that would be good.
No sorry this is a command line tool available in windows xp (I'm not sure if it's available in 2k too).
Type "schtasks /create /?" from the command line for more info
Type "schtasks /create /?" from the command line for more info
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
lbertacco's solution works fine on xp machine.. my solution was a generic one..
a split would be a good option
Have Fun!
Pratap
a split would be a good option
Have Fun!
Pratap
OR
you want to schedule a new task from a remote server?