#72920 - 2003-02-06 11:40 PM
Re: FindMe KiXform
|
JimRobinson
Fresh Scripter
Registered: 2003-01-10
Posts: 42
Loc: Tempe, AZ
|
Here is the latest (not yet including Radimus') modifications.
I discovered that the name resolution is an issue with XP's ping. Winscl would find the IP address, and the host would respond to a ping, but I could not resolve any name. It must be written to use Microsoft's Active DNS or something. 2k's ping however, works on XP and does resolve names correctly.
Radimus, was your screenshot taken from XP? It looks like I just need to make the form and textboxes bigger to accomodate that. NT and 2k display OK. And I had increased the form.height to 100 to resolve the label falling off the bottom in XP.
I'm still not sure about the "(" in the IP that LLigetfa noticed. I queried a server with a shorter address than my primary, which should have shortened the substr offset to the left, but I still got correct results. I can't find one with a longer address, so I will have to play around with it some more using redirected files.
And I added a button to open an Explorer window on the resolved hosts' C$ share, I'm kinda liking this. But how can I make the 'Find Me' button keep focus, so that I can type a username and hit enter, instead of needing to hit the 'Find Me' button? (That's me being lazy. I'll find out sooner or later, just figured I'd get someone that knew right off the top of their head).
break on ;Change this IP address to that of your local WINS server $WINSserver = "YOUR_WINS_SERVER_ADDRESS_HERE" $file = "@ScriptDir\winscl.txt"
;KiXforms Designer Code Output ;***** Main Form Properties *****
$form = createobject("kixtart.form") $form.width = 355 $form.height = 100 $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()"
$btnCDollar = $form.CommandButton $btnCDollar.width = 60 $btnCDollar.height = 20 $btnCDollar.left = 250 $btnCDollar.top = 1 $btnCDollar.caption = "C$" $btnCDollar.FontName = MS Shell Dlg $btnCDollar.FontSize = 8 $btnCDollar.OnClick = "btn_CDollar()"
;***** 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_FindMe() ;*********Clear the form, write winscl.txt********** $IP = "" $txtIP.text = "" $txtHost.text = "" $ShortOffset = Len($WINSserver) $LongOffset = ($ShortOffset+25) del $file $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) ;*********Find the IP********** $WINSarray=WshPipe("%comspec% /c winscl.exe T NOME< winscl.txt",1) $X = InStrArray("Address is (", $WINSarray) $Y = InStrArray("Member is (", $WINSarray) Select Case $X <> -1 $SrchLen = (LEN($WINSarray[$x])-($ShortOffset+1)) $txtIP.text = SubStr($WINSarray[$x],$ShortOffset, $SrchLen ) Case $Y <> -1 $SrchLen = (LEN($WINSarray[$y])-($LongOffset+1)) $txtIP.text = SubStr($WINSarray[$y],$LongOffset, $SrchLen ) Case 1 $txtIP.text = "IP Not Found" EndSelect if $txtIP.text = "IP Not Found" return endif $IP = $txtIP.text ;*********Resolve the hostname********** $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 $Host = $txtHost.text EndFunction ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function btn_CDollar() Run "%COMSPEC% /c start \\$Host\c$" 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.
|
|
|