#72910 - 2003-02-06 01:47 AM
FindMe KiXform
|
JimRobinson
Fresh Scripter
Registered: 2003-01-10
Posts: 42
Loc: Tempe, AZ
|
My assignment: Steal as much code and as many ideas as I possibly can and put a GUI on a KiX script that will query WINS and return an IP and computername given a username. See is there a "RemoteComputerFromUser" UDF...
So, thanks to jpols and sealeapord for the base of InStrArray(), Chris S. for WshPipe(), and Shawn, et al for Kixforms, I got this.
It is a little crowded (but I wanted to keep it small), and I don't think the Copy buttons are all that worthwile, since you need to select the text first anyway, but I don't think it's too bad.
I may change one of the Copy buttons to one that would start an Explorer session on the root share of the computername, since that's what I need the info for usually.
What do you think?
;Change this IP address to that of your local WINS server $WINSserver = "YOUR_WINS_SERVER_ADDRESS" $file = "@ScriptDir\winscl.txt"
;KiXforms Designer Code Output
;***** Main Form Properties *****
$form = createobject("kixtart.form") $form.width = 355 $form.height = 87 $form.center $form.caption = "Locate"
;***** Control Properties *****
$lblUser = $form.Label $lblUser.width = 60 $lblUser.height = 20 $lblUser.left = 25 $lblUser.top = 48 $lblUser.caption = "User Name" $lblUser.FontName = MS Shell Dlg $lblUser.FontSize = 8
$lblIP = $form.Label $lblIP.width = 60 $lblIP.height = 20 $lblIP.left = 130 $lblIP.top = 48 $lblIP.caption = "IP Address" $lblIP.FontName = MS Shell Dlg $lblIP.FontSize = 8
$lblHost = $form.Label $lblHost.width = 60 $lblHost.height = 20 $lblHost.left = 250 $lblHost.top = 48 $lblHost.caption = "Hostname" $lblHost.FontName = MS Shell Dlg $lblHost.FontSize = 8
$txtUser = $form.textbox $txtUser.width = 100 $txtUser.height = 20 $txtUser.left = 5 $txtUser.top = 25 $txtUser.FontName = MS Shell Dlg $txtUser.FontSize = 8 $txtUser.text = "USERNAME"
$txtIP = $form.textbox $txtIP.width = 102 $txtIP.height = 20 $txtIP.left = 109 $txtIP.top = 25 $txtIP.text = "000.000.000.000" $txtIP.FontName = MS Shell Dlg $txtIP.FontSize = 9
$txtHost = $form.textbox $txtHost.width = 130 $txtHost.height = 20 $txtHost.left = 215 $txtHost.top = 25 $txtHost.text = "HOSTNAME" $txtHost.FontName = MS Shell Dlg $txtHost.FontSize = 8
$btnFindMe = $form.CommandButton $btnFindMe.width = 60 $btnFindMe.height = 20 $btnFindMe.left = 25 $btnFindMe.top = 1 $btnFindMe.caption = "Find Me" $btnFindMe.FontName = MS Shell Dlg $btnFindMe.FontSize = 8 $btnFindMe.OnClick = "btn_FindMe()"
$btnCopyIP = $form.CommandButton $btnCopyIP.width = 60 $btnCopyIP.height = 20 $btnCopyIP.left = 130 $btnCopyIP.top = 1 $btnCopyIP.caption = "Copy" $btnCopyIP.FontName = MS Shell Dlg $btnCopyIP.FontSize = 8 $btnCopyIP.OnClick = "btn_CopyIP()"
$btnCopyHost = $form.CommandButton $btnCopyHost.width = 60 $btnCopyHost.height = 20 $btnCopyHost.left = 250 $btnCopyHost.top = 1 $btnCopyHost.caption = "Copy" $btnCopyHost.FontName = MS Shell Dlg $btnCopyHost.FontSize = 8 $btnCopyHost.OnClick = "btn_CopyHost()"
;***** Show the form ***** $form.show ;***** While Loop to display the form ***** while $form.visible $=execute($form.doevents) loop ;***** End of Form *****
;***** User Defined Functions ***** ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; function btn_CopyHost() $txtHost.SetFocus $txtHost.Copy EndFunction
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; function btn_CopyIP() $txtIP.SetFocus $txtIP.Copy EndFunction
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; function btn_FindMe() $ShortOffset = Len($WINSserver) $LongOffset = ($ShortOffset+25) del $file
;Write the command file used by winscl.exe and output the username $X = open (1, "$file", 5) $X = writeline(1, "$WINSserver" + @CRLF) $X = writeline(1, "QN" + @CRLF) $X = writeline(1, $txtUser.text + @CRLF) $X = writeline(1, "1" + @CRLF) $X = writeline(1, "03" + @CRLF) $X = writeline(1, "0" + @CRLF) $X = writeline(1, "EX" + @CRLF) $X = Close(1)
$WINSarray=WshPipe("%comspec% /c winscl.exe T NOME< winscl.txt",1) del $file $X = InStrArray("Address is (", $WINSarray) $Y = InStrArray("Member is (", $WINSarray) Select Case $X <> -1 $SrchLen = (LEN($WINSarray[$x])-($ShortOffset+1)) $IP = SubStr($WINSarray[$x],$ShortOffset, $SrchLen ) $txtIP.text = $IP Case $Y <> -1 $SrchLen = (LEN($WINSarray[$y])-($LongOffset+1)) $IP = SubStr($WINSarray[$y],$LongOffset, $SrchLen ) $txtIP.text = $IP Case 1 $txtIP.text = "IP Not Found" EndSelect
$HostArray = WshPipe("%comspec% /c ping -a -n 1 $IP",1) $X = InStrArray("Pinging", $HostArray) if $X <> -1 $YArray = Split($HostArray[1],"") if $YArray[1] = $IP $txtHost.text = "Not Resolved" else $txtHost.text = $YArray[1] ? endif else $txtHost.text = "Not Found in WINS" ? endif EndFunction
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; function InStrArray($string, $array) if vartype($array) >= 8192 for $i = 0 to ubound($array) if instr($array[$i],$string) $InStrArray = $i return endif next endif $InStrArray = -1 return endfunction
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function WshPipe($ShellCMD, OPTIONAL $NoEcho) Dim $WshShell, $oExec, $AllOutput, $Exit, $WshExitCode $WshErrorMsg="" $WshShell=CreateObject("WScript.Shell") $oExec=$WshShell.Exec($ShellCMD) While $Exit<>1 Dim $Output Select Case Not $oExec.StdOut.AtEndOfStream $Output=$oExec.StdOut.ReadAll Case Not $oExec.StdErr.AtEndOfStream $Output=$oExec.StdErr.ReadAll $WshErrorMsg = $Output Case 1 $Output=-1 EndSelect If $Output=-1 If $oExec.Status=1 $Exit=1 Endif Else If $NoEcho<>1 ? $Output Endif $AllOutput = $AllOutput + $Output Endif Loop $WshExitCode=$oExec.ExitCode $WshPipe=split($AllOutput,chr(10)) Exit($WshExitCode) EndFunction
Jim
_________________________
Jim --------------------
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 538 anonymous users online.
|
|
|