Jump to content

multiple conditions met within a function?


gcue
 Share

Recommended Posts

how can i handle multiple conditions that are met within a function..

for instance.. if the PING fails, i dont want it to try the other REG READS that follow.

i tried ELSEIF, but i think u can only use that once.

any ideas?

For $x = 1 to $assets[0]

$status="1"
$dacs="1"
$usercode="1"

Ping($assets[$x])
If @error Then
$status="OFFLINE"
$user=""
$version=""
$serial=""
EndIf

RegRead ( "\\" & $assets[$x] & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion", "ProgramFilesDir" )
If @error Then
$status="NO_ADMIN_RIGHTS"
$user=""
$version=""
$serial=""
EndIf

RegRead ( "\\" & $assets[$x] & "\HKEY_LOCAL_MACHINE\SOFTWARE\Bloomberg L.P.\Components", "sotr_version")
If @error Then
$status="BLOOMBGER_NOT_INSTALLED"
$user=""
$version=""
$serial=""
EndIf

Dim $status, $user, $version, $serial
If $status = "1" Then
$status = ""
$user =  RegRead("\\" & $assets[$x] & "\HKEY_LOCAL_MACHINE\SOFTWARE\Altiris\Altiris Agent\Inventory", "PrimaryUser")
$version = RegRead("\\" & $assets[$x] & "\HKEY_LOCAL_MACHINE\SOFTWARE\Bloomberg L.P.\Components", "sotr_version")
$serial = RegRead("\\" & $assets[$x] & "\HKEY_LOCAL_MACHINE\SOFTWARE\Bloomberg L.P.\User Info", "Serial Number")
EndIf
Link to comment
Share on other sites

how can i handle multiple conditions that are met within a function..

for instance.. if the PING fails, i dont want it to try the other REG READS that follow.

i tried ELSEIF, but i think u can only use that once.

any ideas?

For $x = 1 to $assets[0]

$status="1"
$dacs="1"
$usercode="1"

Ping($assets[$x])
If @error Then
$status="OFFLINE"
$user=""
$version=""
$serial=""
EndIf

RegRead ( "\\" & $assets[$x] & "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion", "ProgramFilesDir" )
If @error Then
$status="NO_ADMIN_RIGHTS"
$user=""
$version=""
$serial=""
EndIf

RegRead ( "\\" & $assets[$x] & "\HKEY_LOCAL_MACHINE\SOFTWARE\Bloomberg L.P.\Components", "sotr_version")
If @error Then
$status="BLOOMBGER_NOT_INSTALLED"
$user=""
$version=""
$serial=""
EndIf

Dim $status, $user, $version, $serial
If $status = "1" Then
$status = ""
$user =  RegRead("\\" & $assets[$x] & "\HKEY_LOCAL_MACHINE\SOFTWARE\Altiris\Altiris Agent\Inventory", "PrimaryUser")
$version = RegRead("\\" & $assets[$x] & "\HKEY_LOCAL_MACHINE\SOFTWARE\Bloomberg L.P.\Components", "sotr_version")
$serial = RegRead("\\" & $assets[$x] & "\HKEY_LOCAL_MACHINE\SOFTWARE\Bloomberg L.P.\User Info", "Serial Number")
EndIf
Depending on how you structure it, you can use multiple ElseIf entries. But for the sake of readability, you could add a basic error counter to wrap each task section, wherein if an error is detected (per entry in $assets), the following tasks would be skipped for that particular asset entry:

CODE

For $x = 1 to $assets[0]

$iErrorCount = 0

$status="1"

$dacs="1"

$usercode="1"

Ping($assets[$x])

If @error Then

$status="OFFLINE"

$user=""

$version=""

$serial=""

$iErrorCount =+1

EndIf

If $iErrorCount = 0 Then

RegRead...

...

EndIf

If $iErrorCount = 0 Then

RegRead...

...

EndIf

If $iErrorCount = 0 Then

RegRead...

...

EndIf

Next

Edited by Monamo

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Link to comment
Share on other sites

smaaaaaaaaart!

Depending on how you structure it, you can use multiple ElseIf entries. But for the sake of readability, you could add a basic error counter to wrap each task section, wherein if an error is detected (per entry in $assets), the following tasks would be skipped for that particular asset entry:

CODE

For $x = 1 to $assets[0]

$iErrorCount = 0

$status="1"

$dacs="1"

$usercode="1"

Ping($assets[$x])

If @error Then

$status="OFFLINE"

$user=""

$version=""

$serial=""

$iErrorCount =+1

EndIf

If $iErrorCount = 0 Then

RegRead...

...

EndIf

If $iErrorCount = 0 Then

RegRead...

...

EndIf

If $iErrorCount = 0 Then

RegRead...

...

EndIf

Next

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...