Manfredtoo
asked on
RE: IF Else Statement using VBS
Hi Guys
i need some help... its more one IF Else statement part.... im trying to add a schedule in it, just double check as in i do not wan t to add additional schedule task in it. therefore if the schedule tasks is null then i will add the task in... but im facing problem with the empty schedule task while testing. it will not add in any task at all. thanks inadvance...
strComputer = "."
Set objWMI = GetObject("winmgmts:" _
& "{impersonationLevel=imper sonate}!\\ " & strComputer & "\root\cimv2")
Set objNewJob = objWMI.Get("Win32_Schedule dJob")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper sonate}!\\ " & strComputer & "\root\cimv2")
Set colScheduledJobs = objWMIService.ExecQuery _
("SELECT * FROM Win32_ScheduledJob")
For Each objJob in colScheduledJobs
If objJob.JobID = null Then
err = objNewJob.Create ("cmd /c defrag c: -f", "********003300.000000-420 ", _
True , 32 , JobID)
Else
Wscript.Echo "An error occurred: " & errJobCreated
End If
Next
i need some help... its more one IF Else statement part.... im trying to add a schedule in it, just double check as in i do not wan t to add additional schedule task in it. therefore if the schedule tasks is null then i will add the task in... but im facing problem with the empty schedule task while testing. it will not add in any task at all. thanks inadvance...
strComputer = "."
Set objWMI = GetObject("winmgmts:" _
& "{impersonationLevel=imper
Set objNewJob = objWMI.Get("Win32_Schedule
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=imper
Set colScheduledJobs = objWMIService.ExecQuery _
("SELECT * FROM Win32_ScheduledJob")
For Each objJob in colScheduledJobs
If objJob.JobID = null Then
err = objNewJob.Create ("cmd /c defrag c: -f", "********003300.000000-420
True , 32 , JobID)
Else
Wscript.Echo "An error occurred: " & errJobCreated
End If
Next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
explanation: checking against null value can only be done using the function IsNull()
ASKER
angelIII: Hiya, it didnt managed to add in...
?
ASKER
angelIII: the schedule didnt manage to add in. despite its null
honestly, I am not sure what you are trying to accomplish.
actually, jobid cannot be null AFAIK, so your code will never add a schedule.
>but im facing problem with the empty schedule task while testing.
what do you defined an empty scheduled task to be?
actually, jobid cannot be null AFAIK, so your code will never add a schedule.
>but im facing problem with the empty schedule task while testing.
what do you defined an empty scheduled task to be?
ASKER
angelIII: hmmm ok... sorry for the confusion... im trying accomplish, to add the schedule task err = objNewJob.Create ("cmd /c defrag c: -f", "********003300.000000-420 ", _
True , 32 , JobID) once to prevent the addition of the duplicate schedule again if i run the script again.....
True , 32 , JobID) once to prevent the addition of the duplicate schedule again if i run the script again.....