Login | |
|
 |
help with Win32_ScheduleJob and WMI - 1/11/2007 8:54:49 AM
|
|
 |
|
| |
Juggz675
Posts: 8
Score: 0
Joined: 12/14/2006
Status: offline
|
Hi all, I'm trying to schedule a task to execute, but I have some missing or incorrect syntax. I can schedule it, but it is for the next day. I would like to be able to run it once the task is scheduled. Here is the code. It needs some clean up , I just want to make it work correctly. dim WshShell set WshShell = WScript.CreateObject("WScript.Shell") strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set objNewJob = objWMIService.Get("Win32_ScheduledJob") 'get time to run dim ttm ttm = Time() 'Strip out the seconds Dim TimePart TimePart = Left(ttm, Len(ttm) -3) 'strip out the time stuff dim myhour dim min dim sec myhour = left(TimePart, 2) WScript.Echo("first Occ :-: " & instr( 1, TimePart, ":") ) myhour = left( TimePart, instr(1, TimePart, ":") -1) if myhour < 10 then myhour = "0" & myhour end if TimePart = right(TimePart, len(TimePart) - instr( 1, TimePart, ":") ) min = left( TimePart, instr(1, TimePart, ":") -1) TimePart = right(TimePart, len(TimePart) - instr( 1, TimePart, ":") ) sec = TimePart'left( TimePart, instr(1, TimePart, ":") -1) TimeToRun = myhour & min+1 & sec Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") dim time_constraint time_constraint = "********" & TimeToRun & ".000000-420" Set objNewJob = objWMIService.Get("Win32_ScheduledJob") errJobCreated = objNewJob.Create _ ("sysocmgr /i:C:\Windows\inf\sysoc.inf /u:C:\Rescue21\install\reinsnmp.txt /r", _ time_constraint, True , , , , JobID) Wscript.Echo errJobCreated Any help is greatly appreciated.
|
|
| |
|
|
|
 |
RE: help with Win32_ScheduleJob and WMI - 1/12/2007 1:12:04 AM
|
|
 |
|
| |
SAPIENScripter
Posts: 276
Score: 2
Joined: 11/1/2006
From: SAPIEN Technologies
Status: offline
|
Another approach, especially if you want the task to show up in Scheduled Tasks and be modifiable, is to simply call SCHTASKS.EXE from your VBScript (assuming you are running XP or 2003). I think it's much easier than working with the WMI class. Run schtasks /create /? to see the syntax.
_____________________________
Jeffery Hicks Windows PowerShell MVP SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com Follow Me: http://www.twitter.com/JeffHicks
|
|
| |
|
|
|
 |
RE: help with Win32_ScheduleJob and WMI - 1/12/2007 5:14:57 AM
|
|
 |
|
| |
Juggz675
Posts: 8
Score: 0
Joined: 12/14/2006
Status: offline
|
I've tried using the schtasks command. It logs the task, but does not run correctly, ie, reinstalling snmp. hummmmm As I posted earlier, I can run the script locally and it is fine, using WMI. I believe it is a security permission from the remote entry, which has the problem. But not sure how to check the permissions...
|
|
| |
|
|
|
 |
RE: help with Win32_ScheduleJob and WMI - 1/15/2007 9:09:50 AM
|
|
 |
|
| |
Juggz675
Posts: 8
Score: 0
Joined: 12/14/2006
Status: offline
|
Thanks for the input. I'll give it a try. It appears to be a permission thing. I can uninstall the service, start/stop the service, but when it comes time to reinstall it, forget it. I believe when I try to connect to the remote host and run the script, I'm not being granted admin or system rights. So maybe that is what I need to pursue.
|
|
| |
|
|
|
 |
RE: help with Win32_ScheduleJob and WMI - 1/15/2007 10:02:29 AM
|
|
 |
|
| |
dm_4ever
Posts: 2722
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
|
One thing to remember when creating a scheduled task with WMI is that it will run it under "System". SCHTASKS.EXE (like SapienScripter suggested) will let you specify a username and password under which to run the scheduled task. See the options available by typing the following at the command prompt: schtasks /create /?
< Message edited by dm_4ever -- 1/16/2007 2:56:40 AM >
_____________________________
dm_4ever My philosophy: K.I.S.S - Keep It Simple Stupid Read Me: http://www.visualbasicscript.com/m_24727/tm.htm Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: help with Win32_ScheduleJob and WMI - 1/15/2007 4:59:08 PM
|
|
 |
|
| |
gdewrance
Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
|
quote:
I can uninstall the service, start/stop the service, but when it comes time to reinstall it, forget it. Are you creating a Service or a Scheduled Job?
|
|
| |
|
|
|
 |
RE: help with Win32_ScheduleJob and WMI - 1/16/2007 8:36:48 AM
|
|
 |
|
| |
Juggz675
Posts: 8
Score: 0
Joined: 12/14/2006
Status: offline
|
quote:
schtasks /create /? Already tried this also. It does not want to run the command. Trying to create a scheduled job, that only needs to run once. Is there a difference between a scheduled task or scheduled job when running once?
< Message edited by Juggz675 -- 1/16/2007 8:38:36 AM >
|
|
| |
|
|
|
|
|