Page 3 of 3 <123
Topic Options
#72950 - 2003-02-19 10:30 PM Re: FindMe KiXform
JimRobinson Offline
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$WSVRfile2) = 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
#72951 - 2003-03-14 04:07 PM Re: FindMe KiXform
Schuliebug Offline
Hey THIS is FUN
*****

Registered: 2002-01-18
Posts: 379
Loc: Netherlands
Somehow on WXP i get the error: The procedure entry point WinsCheckAccess could not be located in the dynamic link library WINSRPC.DLL. The file mentioned is on my system in the same directory as winscl.exe, what am i doing wrong ?
_________________________
Kind regards,

Top
#72952 - 2003-03-14 06:24 PM Re: FindMe KiXform
krabourn Offline
Hey THIS is FUN
*****

Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
If anyone ever posts this to the UDF forum, make sure to mention that you need admin access to the WINS server.

I am not in charge of the WINS servers and I recieve this.
quote:
*** You have No access to this server ***
_________________________
Kelly

Top
#72953 - 2003-03-14 09:34 PM Re: FindMe KiXform
Schuliebug Offline
Hey THIS is FUN
*****

Registered: 2002-01-18
Posts: 379
Loc: Netherlands
krabourn,

I have access (at least i can administer the WINS server by using Winsmngr on my XP-pro workstation) so access rights shouldn't be the problem.. Somehow i can't start winscl.exe, maybe it's XP...
_________________________
Kind regards,

Top
#72954 - 2003-03-14 11:25 PM Re: FindMe KiXform
Schuliebug Offline
Hey THIS is FUN
*****

Registered: 2002-01-18
Posts: 379
Loc: Netherlands
It works for me as i place the winsrpc.dll found on W2K server in the same directory as winscl.exe. I had a WinsRPC.dll on my system, but an old version!
_________________________
Kind regards,

Top
#72955 - 2003-03-14 11:43 PM Re: FindMe KiXform
krabourn Offline
Hey THIS is FUN
*****

Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
Well I tried the GUI and I still get access denied. I am glad ntname works for me. [Cool]
_________________________
Kelly

Top
#72956 - 2003-03-15 10:29 AM Re: FindMe KiXform
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Jim,

ummm ... totally missed this one [Eek!]

Hmmm.. first of all I didn't know that I have to be honoured for a UDF called InStrArray() [Confused]

However, as I have now found the post and do understand that there is one part of it retriving IP-adresses from 'names' you may want to have a look at one of my udfs which is there for along time now : Ping() - checks for reply , or returns ip-address of remote host which has no other dependencies than using Kixtart 4.x plus supports all OS' from NT upwards [Wink]

Maybe after you considered it I was worth to be mentioned [Big Grin]

{edit} Oh yeah ! For the case I missed the subject you may then want to look at REVPING() - Resolve IP address to Hostname which is basically the same adapted by Waltz [Smile]
{/edit}

[ 15. March 2003, 10:34: Message edited by: jpols ]
_________________________



Top
#72957 - 2003-03-18 01:32 AM Re: FindMe KiXform
JimRobinson Offline
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 [Wink]
_________________________
Jim
--------------------

Top
Page 3 of 3 <123


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 369 anonymous users online.
Newest Members
rrosell, PatrickPinto, Raoul, Timothy, Jojo67
17877 Registered Users

Generated in 0.062 seconds in which 0.015 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org