Page 2 of 2 <12
Topic Options
#32178 - 2002-11-18 08:56 PM Re: Determine which user is logged on a remote machine
Radimus Moderator Offline
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 ]
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#32179 - 2002-11-19 09:40 AM Re: Determine which user is logged on a remote machine
Schuliebug Offline
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
#32180 - 2002-11-21 11:52 AM Re: Determine which user is logged on a remote machine
Schuliebug Offline
Hey THIS is FUN
*****

Registered: 2002-01-18
Posts: 379
Loc: Netherlands
Can anybody tell me what dependencies there are for:
code:
CreateObject("Wbemscripting.SWbemLocator")

Do i need extra software on the target machine, what services have to run ? I do have administrator rights on the W2P machines, but cannot contact the (W2P) workstation (sorry for my previous posts where i said i could).

I get on my WXP workstation, when running the code:
'SWbemLocator - The RPC server is unavailable.'
_________________________
Kind regards,

Top
#32181 - 2002-11-21 11:32 PM Re: Determine which user is logged on a remote machine
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
WMI must be running. Does it work if you query your local computer?
_________________________
There are two types of vessels, submarines and targets.

Top
#32182 - 2002-11-23 10:50 PM Re: Determine which user is logged on a remote machine
Schuliebug Offline
Hey THIS is FUN
*****

Registered: 2002-01-18
Posts: 379
Loc: Netherlands
Yep, also for DC's or member servers in the domain [Frown] I still have to disable the SecEdit we're using to see if security is causing the problem [Wink] Will report monday..
_________________________
Kind regards,

Top
Page 2 of 2 <12


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

Who's Online
0 registered and 962 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.985 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

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