?
Solved

RE: IF Else Statement using VBS

Posted on 2007-03-27
7
Medium Priority
?
213 Views
Last Modified: 2010-04-16
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
0
Comment
Question by:Manfredtoo
  • 4
  • 3
7 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 1500 total points
ID: 18798714
If isnull(objJob.JobID ) Then
  err = objNewJob.Create ("cmd /c defrag c: -f", "********003300.000000-420", _
        True , 32 , JobID)
Else
    Wscript.Echo "An error occurred: " & errJobCreated
End If
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18798716
explanation: checking against null value can only be done using the function IsNull()
0
 

Author Comment

by:Manfredtoo
ID: 18798730
angelIII: Hiya, it didnt managed to add in...
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18798732
?
0
 

Author Comment

by:Manfredtoo
ID: 18798747
angelIII: the schedule didnt manage to add in. despite its null
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18798804
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?
0
 

Author Comment

by:Manfredtoo
ID: 18800366
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.....
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question