#72950 - 2003-02-19 10:30 PM
Re: FindMe KiXform
|
JimRobinson
Fresh Scripter
Registered: 2003-01-10
Posts: 42
Loc: Tempe, AZ
|
Here is an update. I incorporated (stole) Radimus' idea to find the WINS server automagically. Then it is set as the initial IP address value, all the easier to see if you have a configuration problem.
A couple other things: I made the 'Find Me' button the default and set focus in the username text box so you can just type a name and hit enter. Also the Cancel property on the Exit button is enabled, so you can Esc yourself out. Lastly, the C$ button is disabled unless the found IP/name responds to a ping.
Is turning the form code into a function bad form (no pun intended)? Hope someone can use it besides me.
$INfile = "@ScriptDir\winscl.txt" $OUTfile = "@ScriptDir\winsout.txt" $PINGfile = "@ScriptDir\pingout.txt" $WSVRfile = "@ScriptDir\WINSsvr.txt"
GetWINSsvr() BuildForm() $form.show $txtUser.SetFocus $txtUser.SelText = "Username"
While $form.visible $=execute($form.doevents) Loop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function BuildForm() $form = createobject("kixtart.form") $form.width = 435 $form.height = 90 $form.caption = "Where am I?"
$txtUser = $form.textbox $txtUser.width = 130 $txtUser.height = 20 $txtUser.left = 10 $txtUser.top = 30 $txtUser.FontName = MS Shell Dlg $txtUser.FontSize = 10
$txtIP = $form.textbox $txtIP.width = 130 $txtIP.height = 20 $txtIP.left = 150 $txtIP.top = 30 $txtIP.text = "$WINSserver" $txtIP.FontName = MS Shell Dlg $txtIP.FontSize = 10
$txtHost = $form.textbox $txtHost.width = 130 $txtHost.height = 20 $txtHost.left = 290 $txtHost.top = 30 $txtHost.text = "HOSTNAME" $txtHost.FontName = MS Shell Dlg $txtHost.FontSize = 10
$cmdFindMe = $form.CommandButton $cmdFindMe.width = 60 $cmdFindMe.height = 20 $cmdFindMe.left = 10 $cmdFindMe.top = 5 $cmdFindMe.caption = "Find Me" $cmdFindMe.FontName = MS Shell Dlg $cmdFindMe.FontSize = 8 $cmdFindMe.OnClick = "cmd_FindMe()" $cmdFindMe.Default = 1
$cmdExit = $form.CommandButton $cmdExit.width = 60 $cmdExit.height = 20 $cmdExit.left = 80 $cmdExit.top = 5 $cmdExit.caption = "Exit" $cmdExit.FontName = MS Shell Dlg $cmdExit.FontSize = 8 $cmdExit.OnClick = "GoodBye()" $cmdExit.Cancel = 1
$cmdCopyIP = $form.CommandButton $cmdCopyIP.width = 60 $cmdCopyIP.height = 20 $cmdCopyIP.left = 185 $cmdCopyIP.top = 5 $cmdCopyIP.caption = "Copy IP" $cmdCopyIP.FontName = MS Shell Dlg $cmdCopyIP.FontSize = 8 $cmdCopyIP.OnClick = 'cmd_CopyIP()'
$cmdCDollar = $form.CommandButton $cmdCDollar.width = 60 $cmdCDollar.height = 20 $cmdCDollar.left = 255 $cmdCDollar.top = 5 $cmdCDollar.caption = "C$" $cmdCDollar.FontName = MS Shell Dlg $cmdCDollar.FontSize = 8 $cmdCDollar.OnClick = "cmd_CDollar()" $cmdCDollar.Enabled = 0
$cmdCopyHost = $form.CommandButton $cmdCopyHost.width = 60 $cmdCopyHost.height = 20 $cmdCopyHost.left = 325 $cmdCopyHost.top = 5 $cmdCopyHost.caption = "Copy Host" $cmdCopyHost.FontName = MS Shell Dlg $cmdCopyHost.FontSize = 8 $cmdCopyHost.OnClick = "cmd_CopyHost()" EndFunction
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function GetWINSsvr() If Not $WINSserver Shell '%comspec% /c ipconfig /all | find "Primary WINS">$WSVRfile' If Open (1, $WSVRfile, 2) = 0 $line = ReadLine(1) If InStr($line, "Primary WINS") $WINSserver = Trim(Split($line,':')[1]) Else $WINSserver = "No WINS Server" EndIf Else $WINSserver = "No WINS Server" EndIf Endif $X = Close(1) Del $WSVRfile EndFunction
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function cmd_FindMe() Del $INfile $cmdCDollar.Enabled = 0 $txtHost.Text = "HOSTNAME" $txtIP.Text = "0" $X = Open (1, "$INfile", 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)
Shell '%comspec% /c "winscl.exe T nome<$INfile >$OUTfile"' If Open (1, $OUTfile,2) = 0 $line = ReadLine(1) While @error = 0 Select Case InStr($line,"Address is (") <> 0 $txtIP.Text = Split(Split($line,'(')[1],')')[0] Case InStr($line,"Member is (") <> 0 $txtIP.Text = Split(Split($line,'(')[2],')')[0] EndSelect $line = ReadLine(1) Loop If $txtIP.Text = "0" $txtIP.Text = "Not Found" EndIf EndIf $X = close(1)
If $txtIP.Text <> "Not Found" $IP = $txtIP.Text shell '%comspec% /c ping -n 1 $IP |find "Reply">NUL' If @Error = 0 $cmdCDollar.Enabled = 1 Shell '%comspec% /c nbtstat -A $IP |find "<00> UNIQUE" >$PINGfile' If Open (1, "$PINGfile",2) = 0 $line = ReadLine(1) While @error = 0 If InStr($line,"<00> UNIQUE") <> 0 $txtHost.Text = Trim(split($line,"<")[0]) EndIf $line = ReadLine(1) Loop If $txtHost.Text = "HOSTNAME" or $txtHost.Text = $IP $txtHost.Text = "Not Found" Endif Else $txtHost.Text = "FileError" EndIf $X = close(1) EndIf Else $txtHost.Text = "Not Found" EndIf EndFunction
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function cmd_CopyIP() $txtIP.SelStart = 0 $txtIP.SelLength = -1 $txtIP.Copy EndFunction
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function cmd_CDollar() $Host = $txtIP.Text Run "%COMSPEC% /c start \\$Host\c$" EndFunction
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function cmd_CopyHost() $txtHost.SelStart = 0 $txtHost.SelLength = -1 $txtHost.Copy EndFunction
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Function GoodBye() Del $INfile Del $OUTfile Del $PINGfile Quit() EndFunction
_________________________
Jim --------------------
|
Top
|
|
|
|
#72956 - 2003-03-15 10:29 AM
Re: FindMe KiXform
|
Jochen
KiX Supporter
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
|
Top
|
|
|
|
#72957 - 2003-03-18 01:32 AM
Re: FindMe KiXform
|
JimRobinson
Fresh Scripter
Registered: 2003-01-10
Posts: 42
Loc: Tempe, AZ
|
Jochen, You got the mention because of this topic: http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=12;t=000098#000002
Which modified Jens' IsInArray() UDF to return a pointer to the array index, if found. I just modified your modification so that an exact match was not required for success: Compare IsInArray() -
code:
function IsInArray ($v, $a) if vartype($a) > 8192 for $i = 0 to ubound($a) if $v = $a[$i] $IsInArray = $i exit () endif next endif $IsInArray = -1 endfunction
With InStrArray() - code:
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
I removed InStrArray() from my 'final' version I think because of some problem I had with consoles and wkix. They were most likely all self inflicted problems (aren't most?) that I could have solved, but Hey, temp files work too.
I intend to change this again using Shane's 'net send username ""' syntax, (best only on 2k+ networks), which may work better for krabourn, but time has not permitted. It's prime visitor season where I am, don't you know
_________________________
Jim --------------------
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 369 anonymous users online.
|
|
|