#32178 - 2002-11-18 08:56 PM
Re: Determine which user is logged on a remote machine
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
code:
break on call \\server\logon\udf.kix
dim $namearray[2,1] $ip1 ="195.151.234.1" $sn1 ="255.255.255.128" $iparray=IPRange($ip1,$sn1)
$index=0 for each $ip in $iparray ? "$ip " if $ip $hostname=lookup($ip) if not @error "$hostname $index" $namearray[0,$index]=$hostname $namearray[1,$index]=$ip $index=$index+1 redim preserve $namearray[2,$index] else $p=WSHPing($ip) if $p[1]=1 "IP Active" else "No Reply" endif endif endif next
redim preserve $namearray[2,$index-1] :l for $loop=0 to ubound($namearray,2) $computer =$namearray[0,$loop] $ipaddr =$namearray[1,$loop] $ping ="" $remoteuser="" if $computer $p=WSHPing($ipaddr) $ip=$p[0] $ping=$p[1] endif if $ping=1 $remoteuser=wmiquery("UserName","Win32_ComputerSystem",$computer) $color="color b+/n" $bootTime=wmiquery("LastBootUpTime","Win32_OperatingSystem",$computer) if $boottime $boot=ConvertFromWMIDate($boottime) endif endif if $remoteuser="" select case $ip= "0.0.0.0" $remoteuser="unknown " $color="color w/n" case $ping=-1 $remoteuser="Down " $color="color r+/n" case 1 $remoteuser="On-line " $color="color g+/n" endselect endif if len($computer)<8 $computer="$computer " endif if $ip= "0.0.0.0" $ip= "0.0.0.0 " endif $_=execute("? '$$computer $$ip '$color $$remoteuser color w/n' '$$boot") next ? sleep 30 goto l exit
Function IPRange($sIPaddress,$sNetMask) Dim $aiStartRange,$aiMaskBits,$aiEndRange[4],$iHostCount,$i Dim $iOctet1,$iOctet2,$iOctet3,$iOctet4 Dim $tempArray[1]
$iHostCount=1
$aiStartRange=Split($sIPaddress,".") $aiMaskBits=Split($sNetMask,".") Redim Preserve $aiStartRange[4] Redim Preserve $aiMaskBits[4]
For $i = 0 To 3 $aiMaskBits[$i] =Val($aiMaskBits[$i]) & 255 $aiStartRange[$i] =Val($aiStartRange[$i]) & $aiMaskBits[$i] $aiEndRange[$i] =$aiStartRange[$i]+(255-$aiMaskBits[$i]) $iHostCount =$iHostCount*($aiEndRange[$i]-$aiStartRange[$i]+1) Next
redim $temparray[$iHostCount] $i=0 For $iOctet1 = $aiStartRange[0] To $aiEndRange[0] For $iOctet2 = $aiStartRange[1] To $aiEndRange[1] For $iOctet3 = $aiStartRange[2] To $aiEndRange[2] For $iOctet4 = $aiStartRange[3] To $aiEndRange[3] $temparray[$i]="$iOctet1.$iOctet2.$iOctet3.$iOctet4" $i=$i+1 Next Next Next Next $IPRange=$temparray EndFunction
function ConvertFromWMIDate($wmidate) if instr($wmidate,'.') $ConvertFromWMIDate=left($wmidate,4)+'/'+substr($wmidate,5,2)+'/'+substr($wmidate,7,2)+' ' $ConvertFromWMIDate=$ConvertFromWMIDate+substr($wmidate,9,2)+':'+substr($wmidate,11,2)+':'+substr($wmidate,13,2) else $ConvertFromWMIDate='' endif endfunction
[ 18. November 2002, 20:56: Message edited by: Radimus ]
|
|
Top
|
|
|
|
#32179 - 2002-11-19 09:40 AM
Re: Determine which user is logged on a remote machine
|
Schuliebug
Hey THIS is FUN
   
Registered: 2002-01-18
Posts: 379
Loc: Netherlands
|
Sealeopard,
That ReadEventLog() UDF will help for sure. Will dive into it today !! About your question about the code i use the code from the CompPswdAge.kix script. In the function fnCompPswdAge i added some code to check if the Workstation belongs to the same domain as the workstation running the code. If not, i want to connect the workstation with other credentials.
code:
If SubStr($objCom.Name,1,Len($sDomain))=$sDomain $lblStatus.Text='Enumerating $lCount computer accounts (check values)...'
; workstationname.. $Item=$lvwList.Items.Add($objCom.Name) ; username, als workstation niet in domain zit een connectie opzetten ; met een ander ImpersonationLevel.. If $sDomain<>@Domain $ObjWBemScripting=GetObject("Wbemscripting.SWbemLocator") $ObjWBemLocator=$ObjWBemScripting.ConnectServer("$objCom.Name","root\cimv2","$sDomain\SchedAdmin","schedadmin")
$objWMIService=GetObject("winmgmts:\\"+$objCom.Name+"\root\cimv2") Else $objWMIService=GetObject("winmgmts:{ImpersonationLevel=impersonate}!\\"+$objCom.Name+"\root\cimv2") EndIf $objWMIService=GetObject("winmgmts:{ImpersonationLevel=impersonate}!\\"+$objCom.Name+"\root\cimv2") If @Error=0 $colItems=$objWMIService.ExecQuery("Select * from Win32_ComputerSystem") For each $objItem in $colItems $Item.SubItems(1)=$objItem.UserName Next $colItems=$objWMIService.ExecQuery("Select * from Win32_OperatingSystem") For each $objItem in $colItems $Item.SubItems(2).Text=$objItem.Caption+' ('+$objItem.Version+')' Next Else $Item.SubItems(2).Text=$sRole EndIf EndIf
Radimus: will your code also work from one domain to another ? [ 19. November 2002, 11:43: Message edited by: Schuliebug ]
_________________________
Kind regards,
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 884 anonymous users online.
|
|
|