Jump to content
Sign in to follow this  
gcue

help with conditional logic

Recommended Posts

gcue

trying to handle several scenarios at the same time.

essentially i am querying an account name (Guictrlread($initials)) against a novell server and a domain server (we run both in our environment)

if the accountname isnt found in the domain/novell context there's a msgbox error for each

but if the name is found in either of them then the Full name is compared between each (bc sometimes they're different)

and because the last part of the script attaches the full name as part of a url, i needed to create a url link for each one

i get array errors if i dont put in these conditions (of course because it cant find full names in the text files cause the text files are blank).

heres what im trying to do:

if the query on the domain fails, i still want it to try novell.

if the domain query fails, i dont want it to try to find the full name in the text file output

if the novell query fails, i dont want it to try to find the full name in the text file output

i want it to create the url for each full name it does find

ok i know this is alot but hopefully someone out there gets it

Func By_User2()

$initials_AD_file = ($toolsdir & "\Account_Info\" & GUICtrlRead($initials) & "\" & GUICtrlRead($initials) & "_DOMAIN.txt")
$initials_NDS_file = ($toolsdir & "\Account_Info\" & GUICtrlRead($initials) & "\" & GUICtrlRead($initials) & "_NOVELL.txt")

RunWait(@ComSpec & " /c " & "net user " & GUICtrlRead($initials) & " /domain > " & $initials_AD_file)

RunWait(@ComSpec & " /c " & "cx " & $npath & " /r")
RunWait(@ComSpec & " /c " & "nlist user=" & GUICtrlRead($initials) & " /d /s > " & $initials_NDS_file)


$error=0
$String = FileRead($initials_AD_file)
$dname = StringRegExp($string,"(?:Full Name.\s+)(.*),.(.*)\r\n",3)

If @error Then
    $error="D"
    FileDelete($initials_AD_file)
    msgbox(0,"Account Info", GUICtrlRead($initials) & " was not found in Domain.")
EndIf

If $error=0 Then
If IsArray($dname) Then
    For $X = 0 to Ubound($dname)-1
        ConsoleWrite($dname[$X] & @CRLF)
    Next
EndIf
EndIf

$string2 = FileRead($initials_NDS_file)
$nname = StringRegExp($string2,"(?:(?:Given Name|Last Name):.)(.*)\r\n",3)

If @error Then
    $error="N"
    FileDelete($initials_NDS_file)
    msgbox(0,"Account Info", GUICtrlRead($initials) & " was not found in Novell, are you sure you have the right context?")
EndIf

If $error=0 Then
    If $nname[0] <> $dname[1] OR $nname[1] <> $dname[0] Then
    MsgBox(0, "Account Info", "Discrepancy in names"&@CRLF & _
                ''&@CRLF & _
                'Domain Name:'&@CRLF & _
                $dname[1] & " " & $dname[0] &@CRLF & _
                ''&@CRLF & _
                'Novell Name:'&@CRLF & _
                $nname[0] & " " & $nname[1]&@CRLF & _
                ''&@CRLF & _
                'Notes links were created for each name - 1 of the sets should work.')
    EndIf



$scexe = @ProgramFilesDir & "\intern~1\iexplore.exe"

$sc1arg = "http://invlaolns01.capgroup.com/names.nsf/85255e01001356a8852556d4006ca21c?SearchView&&SearchOrder=4&Query=FIELD+Members=" & $nname[0] & "%20" & $nname[1]
$sc1dest = $toolsdir & "\Account_Info\" & GUICtrlRead($initials) & "\" & GUICtrlRead($initials) & "_NOTES-GROUP-MEMBERSHIP2.lnk"

$sc2arg = "http://invlaolns01.capgroup.com/names.nsf/People/?SearchView&Query=" & $nname[0] & "%20" & $nname[1] & "&SearchWV=true&Start=1&Count=-1"
$sc2dest = $toolsdir & "\Account_Info\" & GUICtrlRead($initials) & "\" & GUICtrlRead($initials) & "_NOTES-SERVER2.lnk"

FileCreateShortcut( $scexe, $sc1dest, "", $sc1arg)
FileCreateShortcut( $scexe, $sc2dest, "", $sc2arg)

$scexe = @ProgramFilesDir & "\intern~1\iexplore.exe"

$sc1arg = "http://invlaolns01.capgroup.com/names.nsf/85255e01001356a8852556d4006ca21c?SearchView&&SearchOrder=4&Query=FIELD+Members=" & $dname[1] & "%20" & $dname[0]
$sc1dest = $toolsdir & "\Account_Info\" & GUICtrlRead($initials) & "\" & GUICtrlRead($initials) & "_NOTES-GROUP-MEMBERSHIP.lnk"

$sc2arg = "http://invlaolns01.capgroup.com/names.nsf/People/?SearchView&Query=" & $dname[1] & "%20" & $dname[0] & "&SearchWV=true&Start=1&Count=-1"
$sc2dest = $toolsdir & "\Account_Info\" & GUICtrlRead($initials) & "\" & GUICtrlRead($initials) & "_NOTES-SERVER.lnk"

FileCreateShortcut( $scexe, $sc1dest, "", $sc1arg)
FileCreateShortcut( $scexe, $sc2dest, "", $sc2arg)

Run(@WindowsDir & "\explorer.exe " & $toolsdir & "\Account_Info")
GUIDelete($user_child)
EndFunc;Account_Info\User2
Edited by gcue

Share this post


Link to post
Share on other sites
enaiman

I might have a go to help you but I will need some more info:

- what is the meaning of querry failed?

- does it happen here?

RunWait(@ComSpec & " /c " & "net user " & GUICtrlRead($initials) & " /domain > " & $initials_AD_file)

- or here?

$dname = StringRegExp($string,"(?:Full Name.\s+)(.*),.(.*)\r\n",3)

If @error Then

I'm sure I can figure a logic but I will need this info first.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites
gcue

this utility's purpose is to query different servers for network account information.

if the user inputs an account that doesnt exist, then the output text file does not contain any information, so the search strings fail.

I might have a go to help you but I will need some more info:

- what is the meaning of querry failed?

- does it happen here?

RunWait(@ComSpec & " /c " & "net user " & GUICtrlRead($initials) & " /domain > " & $initials_AD_file)

- or here?

$dname = StringRegExp($string,"(?:Full Name.\s+)(.*),.(.*)\r\n",3)

If @error Then

I'm sure I can figure a logic but I will need this info first.

Share this post


Link to post
Share on other sites
enaiman

So, if that user is not on a server the results file would be empty?


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites
gcue

yes the results file would be emtpy so i dont want it to try to read the empty file ;-)

Share this post


Link to post
Share on other sites
enaiman

OK, this is what I've got:

Func By_User2()

$initials_AD_file = ($toolsdir & "\Account_Info\" & GUICtrlRead($initials) & "\" & GUICtrlRead($initials) & "_DOMAIN.txt")
$initials_NDS_file = ($toolsdir & "\Account_Info\" & GUICtrlRead($initials) & "\" & GUICtrlRead($initials) & "_NOVELL.txt")

RunWait(@ComSpec & " /c " & "net user " & GUICtrlRead($initials) & " /domain > " & $initials_AD_file)

RunWait(@ComSpec & " /c " & "cx " & $npath & " /r")
RunWait(@ComSpec & " /c " & "nlist user=" & GUICtrlRead($initials) & " /d /s > " & $initials_NDS_file)

$error=0

Select
    Case FileGetSize($initials_AD_file) = 0 And FileGetSize($initials_NDS_file) = 0
        msgbox(0,"Account Info", GUICtrlRead($initials) & " was not found.")
        SetError(1)
        Return
    Case FileGetSize($initials_AD_file) <> 0 And FileGetSize($initials_NDS_file) = 0
        _AD_process()
        _CreateLinks("AD")
    Case FileGetSize($initials_AD_file) = 0 And FileGetSize($initials_NDS_file) <> 0    
        _Novell_process()
        _CreateLinks("Novell")
    Case Else
        _AD_process()
        _Novell_process()
        _CreateLinks("AD")
        _CreateLinks("Novell")
        If $nname[0] <> $dname[1] OR $nname[1] <> $dname[0] Then
            MsgBox(0, "Account Info", "Discrepancy in names"&@CRLF & _
                    ''&@CRLF & _
                    'Domain Name:'&@CRLF & _
                    $dname[1] & " " & $dname[0] &@CRLF & _
                    ''&@CRLF & _
                    'Novell Name:'&@CRLF & _
                    $nname[0] & " " & $nname[1]&@CRLF & _
                    ''&@CRLF & _
                    'Notes links were created for each name - 1 of the sets should work.')
        EndIf
EndSelect

Run(@WindowsDir & "\explorer.exe " & $toolsdir & "\Account_Info")
GUIDelete($user_child)
EndFunc;Account_Info\User2

Func _CreateLinks($option)
    Switch $option
        Case "AD"
            $scexe = @ProgramFilesDir & "\intern~1\iexplore.exe"

            $sc1arg = "http://invlaolns01.capgroup.com/names.nsf/85255e01001356a8852556d4006ca21c?SearchView&&SearchOrder=4&Query=FIELD+Members=" & $dname[1] & "%20" & $dname[0]
            $sc1dest = $toolsdir & "\Account_Info\" & GUICtrlRead($initials) & "\" & GUICtrlRead($initials) & "_NOTES-GROUP-MEMBERSHIP.lnk"

            $sc2arg = "http://invlaolns01.capgroup.com/names.nsf/People/?SearchView&Query=" & $dname[1] & "%20" & $dname[0] & "&SearchWV=true&Start=1&Count=-1"
            $sc2dest = $toolsdir & "\Account_Info\" & GUICtrlRead($initials) & "\" & GUICtrlRead($initials) & "_NOTES-SERVER.lnk"

            FileCreateShortcut( $scexe, $sc1dest, "", $sc1arg)
            FileCreateShortcut( $scexe, $sc2dest, "", $sc2arg)
        Case "Novell"
            $scexe = @ProgramFilesDir & "\intern~1\iexplore.exe"

            $sc1arg = "http://invlaolns01.capgroup.com/names.nsf/85255e01001356a8852556d4006ca21c?SearchView&&SearchOrder=4&Query=FIELD+Members=" & $nname[0] & "%20" & $nname[1]
            $sc1dest = $toolsdir & "\Account_Info\" & GUICtrlRead($initials) & "\" & GUICtrlRead($initials) & "_NOTES-GROUP-MEMBERSHIP2.lnk"

            $sc2arg = "http://invlaolns01.capgroup.com/names.nsf/People/?SearchView&Query=" & $nname[0] & "%20" & $nname[1] & "&SearchWV=true&Start=1&Count=-1"
            $sc2dest = $toolsdir & "\Account_Info\" & GUICtrlRead($initials) & "\" & GUICtrlRead($initials) & "_NOTES-SERVER2.lnk"

            FileCreateShortcut( $scexe, $sc1dest, "", $sc1arg)
            FileCreateShortcut( $scexe, $sc2dest, "", $sc2arg)
        Case Else
            ;error message
    EndSwitch
EndFunc

Func _AD_process()
    $String = FileRead($initials_AD_file)
    $dname = StringRegExp($string,"(?:Full Name.\s+)(.*),.(.*)\r\n",3)

    If @error Then
        $error="D"
        FileDelete($initials_AD_file)
        msgbox(0,"Account Info", GUICtrlRead($initials) & " was not found in Domain.")
    Else
        If IsArray($dname) Then
            ConsoleWrite("Domain Names found" & @CRLF)
            For $X = 0 to Ubound($dname)-1
                ConsoleWrite($dname[$X] & @CRLF)
            Next
        EndIf
    EndIf
EndFunc

Func _Novell_process()
    $string2 = FileRead($initials_NDS_file)
    $nname = StringRegExp($string2,"(?:(?:Given Name|Last Name):.)(.*)\r\n",3)

    If @error Then
        $error="N"
        FileDelete($initials_NDS_file)
        msgbox(0,"Account Info", GUICtrlRead($initials) & " was not found in Novell, are you sure you have the right context?")
    Else
        If IsArray($nnamename) Then
            ConsoleWrite("Novell Names found" & @CRLF)
            For $X = 0 to Ubound($nname)-1
                ConsoleWrite($nname[$X] & @CRLF)
            Next
        EndIf
    EndIf
EndFunc

Give it a go.

I haven't tested it (I can't) so you will have to test it first. It may contain errors (maybe I didn't put something at the correct place) but the conditional logic is in there and you would be able to fix whatever I might have done wrong.

I broke your function in a couple more to make it code-effective.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.