Solved

RE: IF Else Statement using VBS

Posted on 2007-03-27
7
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 143

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 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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

729 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