Solved

RE: IF Else Statement using VBS

Posted on 2007-03-27
7
198 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
Comment Utility
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]
Comment Utility
explanation: checking against null value can only be done using the function IsNull()
0
 

Author Comment

by:Manfredtoo
Comment Utility
angelIII: Hiya, it didnt managed to add in...
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
?
0
 

Author Comment

by:Manfredtoo
Comment Utility
angelIII: the schedule didnt manage to add in. despite its null
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

763 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

9 Experts available now in Live!

Get 1:1 Help Now