Page 1 of 2 12>
Topic Options
#67070 - 2002-06-14 05:10 PM need method of detemining username of remotely logged on user.
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
Wouldn't WMI be able to do this???
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#67071 - 2002-06-14 05:18 PM Re: need method of detemining username of remotely logged on user.
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
So, in other words, you would like to have a list of users that are connected to a specific computer?
Hmm, I know that you can get the list in the Server Manager so it must come from somewhere.

[ 14 June 2002, 17:21: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#67072 - 2002-06-14 05:20 PM Re: need method of detemining username of remotely logged on user.
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
no.. I need to determine who is the local user on a remote PC.
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#67073 - 2002-06-14 05:24 PM Re: need method of detemining username of remotely logged on user.
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Oh, that's easy if you're talking about Windows NT. For example, the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Netlogon\DefaultUsername might help you out. Or take a look at LoggedinUsers(), that might work for you, too.
_________________________
There are two types of vessels, submarines and targets.

Top
#67074 - 2002-06-14 05:25 PM Re: need method of detemining username of remotely logged on user.
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
I hate answering my own question...

http://81.17.37.55/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000167&p=
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#67075 - 2002-06-14 05:28 PM Re: need method of detemining username of remotely logged on user.
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Hmm, I guess the correct answer for this might be STFL [Wink]

[ 14 June 2002, 17:30: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#67076 - 2002-06-14 05:48 PM Re: need method of detemining username of remotely logged on user.
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
$u=WMIQuery("username","Win32_ComputerSystem","$remotePC")

code:
FUNCTION WMIQuery($what,$where, optional $computer)
dim $strQuery, $objEnumerator, $value
if not $computer $computer="@WKSTA" endif
$strQuery = "Select $what From $where"
$SystemSet = GetObject("winmgmts:{impersonationLevel=impersonate}!//$computer")
$objEnumerator = $SystemSet.ExecQuery($strQuery)
For Each $objInstance in $objEnumerator
If @Error = 0 and $objInstance <> ""
$=execute("$$value = $$objInstance.$what")
$WMIQuery="$value"+"|"+"$WMIQuery"
EndIf
Next
$WMIQuery=left($WMIQuery,len($WMIQuery)-1)
exit @error
ENDFUNCTION

_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#67077 - 2002-06-14 05:58 PM Re: need method of detemining username of remotely logged on user.
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Nice. I like this one more than my kludgy solution. But I have to say in my defence that when I wrote my UDF, I haven't yet had deployed ADSI and WMI to my client PCs.
_________________________
There are two types of vessels, submarines and targets.

Top
#67078 - 2002-06-14 06:04 PM Re: need method of detemining username of remotely logged on user.
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Or you can simply check the remote NetBIOS name cache: nbtstat -a computername

If a user is logged on the account name will be cached.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#67079 - 2002-06-14 06:09 PM Re: need method of detemining username of remotely logged on user.
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
HB,
We've danced that one before. The problem is when one user logs on to multiple machines. WINS can hold only one. I use a util called NetUsers from www.systemtools.com but not from KiX.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#67080 - 2002-06-14 06:19 PM Re: need method of detemining username of remotely logged on user.
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
and wins caches... user could have logged off 10 minutes ago.

I used netuser also, but this makes it much more scriptable. (and if WMIQuery() is in your library already...)

Note... I had to modify it to work against remote PCs. I have already updated the UDF in the forum
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#67081 - 2002-06-14 06:39 PM Re: need method of detemining username of remotely logged on user.
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Rad,

As I remember this, Alex H. and myself were to get together on this.. I have dropped the ball as we were going to look into the use of LDAP.

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#67082 - 2002-06-14 08:28 PM Re: need method of detemining username of remotely logged on user.
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Assuming that your searching when your certain the user is logged on, i.e. during login, you can check:

code:
 
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName

This lists the last user logged in which is also your current user in this case, also assuming you have not disabled the "List Last Logged On User" at CTRL-ALT-DEL policy.

-Jim
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#67083 - 2002-06-14 08:33 PM Re: need method of detemining username of remotely logged on user.
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
That might tell you who was logged on...
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#67084 - 2002-06-14 08:43 PM Re: need method of detemining username of remotely logged on user.
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
That's what I said.
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#67085 - 2002-06-14 08:46 PM Re: need method of detemining username of remotely logged on user.
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
the WMIQuery handles it just fine...

(within the limitations of WMI in general)
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#67086 - 2002-06-15 01:36 AM Re: need method of detemining username of remotely logged on user.
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Does this get you want you want? It reports all accounts that are currently locally logged into the (NT or Higher) local or remote computer .

Requires ADsSecurity.dll on the computer running this script. ADsSecurity.DLL can be obtained at this WebPage

{edited} Updated code required 4.10 rc2
{edited} Updated code to use 4.02
code:
Break On
For Each $key In fEnumKey("ComputerName", "HKEY_USERS")
If Left($key,3) = "S-1" and Instr($key,"_") = 0
? GetAdsPathFromHexSid(StrSidToHexSid($key))
Endif
Next
exit 0


;FUNCTION GetAdsPathFromHexSid($HexSid)
;
;AUTHOR Howard A. Bullock (hbullock@comcast.net)
;
;ACTION Uses ADsSecurity.DLL to translate a Hex Sid into the
; objects AdsPath.
;
;SYNTAX GetAdsPathFromHexSid($HexSid)
;
;PARAMETERS $HexSid (Required) - String value
;
;REMARKS ADsSecurity.Dll required
;
;RETURNS String - ADsPath path of object represented by a Hex Sid.
;
;DEPENDENCIES KiXtart 4.02
;
;EXAMPLES
; GetAdsPathFromHexSid("010500000000000515000000BC2E7001633DBD3D0E6D055C79050000")
;
Function GetAdsPathFromHexSid($HexSid)
Dim $oADsSid
$GetAdsPathFromHexSid = ""
$oADsSid = CreateObject("ADsSid")
If VarTypeName($oADsSid) = 'Object'
$oADsSid.SetAS(1,$HexSid)
If @Error <> 0
? "Failed: SetAS(1,$HexSid) @Error @Serror"
Exit 1
Endif
$GetAdsPathFromHexSid=$oADsSid.GetAS(5)
If @Error <> 0
? "Failed: GetAS(5) @Error @Serror"
Exit 1
Endif
Else
? "CreateObject('ADsSid') Failed. @Error @Serror"
? "AdsSecurity.DLL required."
Exit 1
Endif
Exit 0
Endfunction


;FUNCTION fEnumKey($Computer, $Key)
;
;AUTHOR Howard A. Bullock (hbullock@comcast.net)
;
;ACTION Enumerates registries keys on the specified computer.
;
;SYNTAX fEnumKey($Computer, $Key)
;
;PARAMETERS $Computer (Required) - String value
; $Key (Required) - String value
;
;REMARKS Do not prefix the computer name with "\\"'s.
;
;RETURNS Array of keys names.
;
;DEPENDENCIES KiXtart 4.02
;
;EXAMPLES fEnumKey("", "HKEY_USERS")
; fEnumKey("Remote1", "HKEY_USERS")
;
Function fEnumKey($Server, $Key)
Dim $Index, $Error
$Index = 0
Dim $KeyName[$Index]
If $Server <> ""
$Key = "\\" + $Server + "\" + $Key
Endif

If KeyExist($Key)
Do
$KeyName[$Index] = ENUMKEY($Key, $Index)
$Error = @Error
If NOT $Error
$Index = $Index + 1
ReDim PRESERVE $KeyName[$Index]
Else
$Index = $Index - 1
ReDim PRESERVE $KeyName[$Index]
Endif
Until $Error
Else
$KeyName[0] = ""
Exit 2
Endif
$fEnumKey = $KeyName
Exit 0
Endfunction

;FUNCTION StrSidToHexSid($StringSid)
;
;AUTHOR Howard A. Bullock (hbullock@comcast.net)
;
;ACTION Converts a Sid in string (S-1-5-21-...) format to Hex format.
;
;SYNTAX StrSidToHexSid($StringSid)
;
;PARAMETERS $StringSid (Required) - String value
;
;REMARKS Do not prefix the computer name with "\\"'s.
;
;RETURNS String
;
;DEPENDENCIES KiXtart 4.02
;
;EXAMPLES StrSidToHexSid("S-1-5-21-24129212-1035812195-1543859470-1401")
; returns "010500000000000515000000BC2E7001633DBD3D0E6D055C79050000"
;
Function StrSidToHexSid($StringSid)
dim $i, $j, $Parts, $Sac, $Sid, $x

$Sid = ""
If Left($StringSid,4) = "S-1-"
$Parts = split($StringSid, "-")

For $i=1 to 2
$Sid = $Sid + PadStr(DecToHex($Parts[$i]),0,2)
Next

$Sac = Ubound($Parts) - 2
$Sid = $Sid + PadStr($Sac,0,12)

For $i=1 to $Sac
$x = PadStr(DecToHex($Parts[$i+2]),0,8)
For $j=7 to 1 Step -2
$Sid = $Sid + Substr($x,$j,2)
Next
Next
Else
? "StrSidToHexSid - Invalid input"
Exit 1
Endif
$StrSidToHexSid = $Sid
Exit 0
Endfunction

;FUNCTION PadStr($Input,$Pad,$Length)
;
;AUTHOR Howard A. Bullock (hbullock@comcast.net)
;
;ACTION Left or Right pad a string.
;
;SYNTAX PadStr($Input,$Pad,$Length)
;
;PARAMETERS $Input (Required) - String value
; $Pad (Required) - String value
; $Length (Required) - Integer (Max length of padded string)
; $PadSide (Optional) - String [L|R] Default is "L"
;
;REMARKS The $Pad can be one or more characters. If the Padding exceeds
; the specified maximum length then the resulting string is trimmed
; preserving the original data.
;
;RETURNS String
;
;DEPENDENCIES KiXtart 4.02 or higher
;
;EXAMPLES PadStr("401","0",8) result "00000401"
; PadStr("401","0",8,"R") result "40100000"
;
Function PadStr($Input, $Pad, $Length, optional $PadSide)
Dim $i, $x
$PadStr = ""
$Input = "" + $Input
$Pad = "" + $Pad
$Length = 0 + $Length
If $PadSide="" or Len($PadSide)>1 or Instr("LR",$PadSide)= 0
$PadSide = "L"
Endif

$x = Len($Input)

For $i=$x to $Length - 1 Step Len("$Pad")
If $PadSide = "L"
$Input = $Pad + $Input
Else
$Input = $Input + $Pad
Endif
Next
If $PadSide = "L"
$Input = Right($Input, $Length)
Else
$Input = Left($Input, $Length)
Endif
$PadStr = $Input
Exit 0
Endfunction



[ 18 June 2002, 03:34: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#67087 - 2002-06-18 02:59 AM Re: need method of detemining username of remotely logged on user.
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Well, I am rather confused. After reviewing this thread again, all I see are responses from regulars. Where is the the person that requested this functionality? Also, do any of the regulars see any problem with my approach? I would have thought that this would have spurred more discussion.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#67088 - 2002-06-18 03:25 AM Re: need method of detemining username of remotely logged on user.
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
I'm the one that requested it...

the WMIQuery handles it fine and is much more 'efficient' within my environment (all win2k)

and doesn't require additional dlls to be installed
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#67089 - 2002-06-18 03:31 AM Re: need method of detemining username of remotely logged on user.
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Sorry. I just saw your first post as a rhetorical question. Thinking that some people may not have WMI in their environment, I went on with an alternative approach.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
Page 1 of 2 12>


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

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

Generated in 0.074 seconds in which 0.027 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