Sign in to follow this  
Followers 0
gcue

multiple conditions met within a function?

7 posts in this topic

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

Share this post


Link to post
Share on other sites



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.

You can use elseif as many times as you like :D

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

when i did.. it breaks the FOR / NEXT loop

You can use elseif as many times as you like :D

Share this post


Link to post
Share on other sites

when i did.. it breaks the FOR / NEXT loop

Where's the next keyword?

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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]

Share this post


Link to post
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

Share this post


Link to post
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
Sign in to follow this  
Followers 0