Link to home
Start Free TrialLog in
Avatar of Manfredtoo
ManfredtooFlag for Singapore

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=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewJob = objWMI.Get("Win32_ScheduledJob")

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & 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
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
explanation: checking against null value can only be done using the function IsNull()
Avatar of Manfredtoo

ASKER

angelIII: Hiya, it didnt managed to add in...
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?
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.....