#72930 - 2003-02-07 03:13 PM
Re: FindMe KiXform
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
almost more trouble than it is worth... even for basic stuff
code:
Function MidStr($string,$leftchar,$rightchar,optional $trim) if not instr($string,$leftchar) or not instr($string,$rightchar) exit 1 return endif $MidStr = split(split($string,$leftchar)[1],$rightchar)[0] if $trim $MidStr=Trim($MidStr) endif endif
|
Top
|
|
|
|
#72931 - 2003-02-07 03:19 PM
Re: FindMe KiXform
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
BTW...
more functions used to provide equivalent results...
break on
$w=WinsResolve('username') $l=lookup($w)
? $w ? $l
Function WinsResolve($username,optional $winsserver) dim $winsserver, $ipconfig, $line, $wins1, $wins2, $file, $WINSarray, $ip if not $winsserver $return=WSHPipe('%comspec% /c ipconfig /all| find "Primary WINS Server"',1)[0] if instr($return,"Primary WINS Server") $WinsServer=trim(split($return,':')[1]) endif endif if not $winsserver exit 1 return endif
$file='c:\winscl.txt' del $file $parameters="$WINSserver","QN",$username,"1","03","0","EX" $X = open (1, "$file", 5) for each $param in $parameters $X = writeline(1, $param + @CRLF) next $X = Close(1)
$WINSarray=WshPipe("%comspec% /c winscl.exe T NOME< $file",1) del $file for each $line in $WinsArray if instr($line,'Address is (') $IP = split(split($line,'(')[1],')')[0] endif next if $ip $WinsResolve='$ip' else exit 1 return endif endfunction
Function Lookup($ip) Dim $return $return=WSHPipe('%comspec% /c nslookup $ip | find "Name:"',1)[0] if instr($return,"Name:") $lookup=trim(split($return,':')[1]) else exit 1 $lookup="" endif 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
|
Top
|
|
|
|
#72935 - 2003-02-08 06:13 PM
Re: FindMe KiXform
|
krabourn
Hey THIS is FUN
Registered: 2000-12-11
Posts: 244
Loc: San Antonio, Texas, USA
|
I am confused. I am trying to figure out how this is better than using NTNAME. I have been using this for several years to find a logged on user's computer. If the user is logged on more than once, it will only find one computer. I think the solution you are working on has the same problem. If it can find all the computers, then this may be worth it. NTNAME just appears to much easier than using winscl.exe.
At the company I work at we have probably about 140,000 computers, not counting any kind of servers. We probably have about 100 domains. I don't have admin rights to all those domains. I do not have any admin rights to the wins servers. Will this cause any problems using winscl.exe? I also could not find this as a download from Microsoft's site, so I assume that you will have to buy the reskit. Not a problem for me, but something to remember.
I have not been able to test what this thread is currently working on. I am at home recovering from a hernia operation. So I may have missed a point along the way. If this was using some sort of COM method, I probably would have jumped on it. As I said at the begining, I am just trying to understand.
Well, here is some sample code. You could probably wrap this inside wshPipe udf.
code:
$ScriptDir = @CurDir $UserID = 'Name' $Who = fnFindUser($UserID) ? 'Error: ' + @Error ? 'Who: ' + $Who
QUIT 1
FUNCTION fnFindUser($User) ;--- This function will find what computer a person is on. DIM $Temp, $Reply, $FindUserError $Temp = '%temp%\' + $User + '.tmp' DEL $Temp SHELL '%Comspec% /C ' + $ScriptDir + '\ntname.exe ' + $User + ' > ' + $Temp $Nul = Open (10, $Temp, 2) $FindUserError = @Error IF $FindUserError = 0 $fnFindUser = ReadLine (10) ENDIF $Nul = Close (10) DEL $Temp EXIT $FindUserError ENDFUNCTION
_________________________
Kelly
|
Top
|
|
|
|
#72945 - 2003-02-11 07:28 PM
Re: FindMe KiXform
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
It actually seems to work the same way for me when sending from NT server. Try this.
code:
? 'Enter a username : ' Gets $User $IPTempFile = "%Temp%\TempFile.xxx" $NameTempFile = "%Temp%\TempFile.yyy"
If Exist ("$IPTempFile") Del $IPTempFile Endif If Exist ("$NameTempFile") Del $NameTempFile Endif
shell '%comspec% /c nbtstat -R' shell '%comspec% /c net send $User ""' shell '%comspec% /c nbtstat -c > $IPTempFile'
$filehandle = Freefilehandle() If Open ($filehandle, $IPTempFile) = 0 $line = ReadLine ($filehandle) While @Error = 0 $type = Trim (SubStr ($line, InStr ($line, ">")+1)) If InStr ($type, "unique") $IPSTRING = Trim (SubStr ($type, InStr ($type, " ")+1)) $IPSTRING = SubStr ($IPSTRING, 1, InStr ($IPSTRING, " ")-1) ? $IPSTRING Endif $line = ReadLine ($filehandle) Loop Endif $null = Close ($filehandle)
If $IPSTRING shell '%comspec% /c ping -a $IPSTRING > $NameTempFile' $filehandle = Freefilehandle() If Open ($filehandle, $NameTempFile) = 0 $line = ReadLine ($filehandle) While @Error = 0 $type = SubStr ($line, 1, 7) If $type = "Pinging" $NAMESTRING = SubStr ($line, InStr ($line, " ")+1) $NAMESTRING = SubStr ($NAMESTRING, 1, InStr ($NAMESTRING, " ")-1) ? $NAMESTRING Endif $line = ReadLine ($filehandle) Loop Endif $null = Close ($filehandle) Endif
If Exist ("$IPTempFile") Del $IPTempFile Endif If Exist ("$NameTempFile") Del $NameTempFile Endif
? 'DONE' get $
"EDIT" - Changed code to search for > instead of a certain amount of chars. [ 11. February 2003, 20:01: Message edited by: CitrixMan ]
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 421 anonymous users online.
|
|
|