Solved

RE: IF Else Statement using VBS

Posted on 2007-03-27
7
199 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 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 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 142

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 142

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 142

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

930 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now