Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Return computer name

Reply
 
Old 08-18-2009   #1 (permalink)
James


 
 

Return computer name

Is is possible to return the name of the computer an AD user is using if you
only know their user name? If so, any examples or links to example you
could provide would be great. I am looking to use pure vbs, no HTA, no
HTML...if possible.

regards,

James



My System SpecsSystem Spec
Old 08-18-2009   #2 (permalink)
James


 
 

Re: Return computer name

I have found the following code example...

It is along the lines of what I am looking for. All I have to do is input
the user name and it will return some info from AD. I just need it to
return the name or IP address of the computer the user is currently using.
Can that be done?

Option Explicit
Dim strComputer, strUsername, objWMI, colUsers, objUser

strComputer = "."
Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\directory\LDAP")

strUsername = InputBox("Please type the user name")
Set colUsers = objWMI.ExecQuery("SELECT * FROM ds_user where
ds_sAMAccountName = '" & strUsername & "'")

If colUsers.Count > 0 Then
For Each objUser in colUsers
WScript.Echo "First Name: " & objUser.ds_givenName
WScript.Echo "Last Name: " & objUser.ds_sn
Next
Else
WScript.Echo "No users found!"
End If

James


"James" <dontemailme@xxxxxx> wrote in message
news:Oxz19tAIKHA.4436@xxxxxx
Quote:

> Is is possible to return the name of the computer an AD user is using if
> you only know their user name? If so, any examples or links to example
> you could provide would be great. I am looking to use pure vbs, no HTA,
> no HTML...if possible.
>
> regards,
>
> James
>

My System SpecsSystem Spec
Old 08-18-2009   #3 (permalink)
Richard Mueller [MVP]


 
 

Re: Return computer name


"James" <dontemailme@xxxxxx> wrote in message
news:OxOFyQBIKHA.1376@xxxxxx
Quote:

>I have found the following code example...
>
> It is along the lines of what I am looking for. All I have to do is input
> the user name and it will return some info from AD. I just need it to
> return the name or IP address of the computer the user is currently using.
> Can that be done?
>
> Option Explicit
> Dim strComputer, strUsername, objWMI, colUsers, objUser
>
> strComputer = "."
> Set objWMI = GetObject("winmgmts:\\" & strComputer &
> "\root\directory\LDAP")
>
> strUsername = InputBox("Please type the user name")
> Set colUsers = objWMI.ExecQuery("SELECT * FROM ds_user where
> ds_sAMAccountName = '" & strUsername & "'")
>
> If colUsers.Count > 0 Then
> For Each objUser in colUsers
> WScript.Echo "First Name: " & objUser.ds_givenName
> WScript.Echo "Last Name: " & objUser.ds_sn
> Next
> Else
> WScript.Echo "No users found!"
> End If
>
> James
>
>
> "James" <dontemailme@xxxxxx> wrote in message
> news:Oxz19tAIKHA.4436@xxxxxx
Quote:

>> Is is possible to return the name of the computer an AD user is using if
>> you only know their user name? If so, any examples or links to example
>> you could provide would be great. I am looking to use pure vbs, no HTA,
>> no HTML...if possible.
>>
>> regards,
>>
>> James
>>
>
>
Active Directory does not keep track of which user is logged into which
computer. In fact, AD doesn't even keep track if the user is still logged on
at all.

The code snippet you included is new to me, but it appears to query an LDAP
database on the machine, in which case it must be run on a Domain Controller
(or connect to it remotely by assigning the NetBIOS name of the DC to the
variable strComputer). Given the value of the sAMAccountName attribute (the
"pre-Windows 2000 logon name"), it retrieves other attributes of the user
object. However, there are no attributes of user objects indicating which PC
the user is currently logged into. The main purpose of AD is to store
relatively stable information that changes infrequently. Network traffic
would be increased significantly if AD had to replicate new information to
all DC's everytime someone logged on and off.

I believe there are third party tools that attempt to give you the
information you ask for. Someone else may respond with more information
that.

Otherwise, one method I've used in the past, but which is unreliable, uses
the LanmanServer service on a computer to enumerate sessions:
============
Option Explicit
Dim objDC, objSession, strComputer

strComputer = "MyServer"

Set objDC = GetObject("WinNT://" & strComputer & "/LanmanServer")
For Each objSession In objDC.Sessions
Wscript.Echo objSession.Name
Wscript.Echo objSession.User
Wscript.Echo objSession.Computer
Next
=======
This only enumerates active sessions on the one computer. If the user is not
currently doing something on the machine, the session disappears. Plus, you
would need to run this on every DC and member server where a user might be
using network resources.

Otherwise, I have used logon and logoff scripts to keep track of which user
uses which computer. The scripts log the user name, date/time, and computer
name to a shared log file. This file can be copied and opened by a
spreadsheet program where you can filter/sort by user, computer, date, etc.
In principal you can tell which computer a given user was using when you
copied the log file. I have VBScript examples at this link:

http://www.rlmueller.net/Logon5.htm

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 08-18-2009   #4 (permalink)
James


 
 

Re: Return computer name

Thanks again Richard

"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
message news:OtS3B8BIKHA.3708@xxxxxx
Quote:

>
> "James" <dontemailme@xxxxxx> wrote in message
> news:OxOFyQBIKHA.1376@xxxxxx
Quote:

>>I have found the following code example...
>>
>> It is along the lines of what I am looking for. All I have to do is
>> input the user name and it will return some info from AD. I just need it
>> to return the name or IP address of the computer the user is currently
>> using. Can that be done?
>>
>> Option Explicit
>> Dim strComputer, strUsername, objWMI, colUsers, objUser
>>
>> strComputer = "."
>> Set objWMI = GetObject("winmgmts:\\" & strComputer &
>> "\root\directory\LDAP")
>>
>> strUsername = InputBox("Please type the user name")
>> Set colUsers = objWMI.ExecQuery("SELECT * FROM ds_user where
>> ds_sAMAccountName = '" & strUsername & "'")
>>
>> If colUsers.Count > 0 Then
>> For Each objUser in colUsers
>> WScript.Echo "First Name: " & objUser.ds_givenName
>> WScript.Echo "Last Name: " & objUser.ds_sn
>> Next
>> Else
>> WScript.Echo "No users found!"
>> End If
>>
>> James
>>
>>
>> "James" <dontemailme@xxxxxx> wrote in message
>> news:Oxz19tAIKHA.4436@xxxxxx
Quote:

>>> Is is possible to return the name of the computer an AD user is using if
>>> you only know their user name? If so, any examples or links to example
>>> you could provide would be great. I am looking to use pure vbs, no HTA,
>>> no HTML...if possible.
>>>
>>> regards,
>>>
>>> James
>>>
>>
>>
>
> Active Directory does not keep track of which user is logged into which
> computer. In fact, AD doesn't even keep track if the user is still logged
> on at all.
>
> The code snippet you included is new to me, but it appears to query an
> LDAP database on the machine, in which case it must be run on a Domain
> Controller (or connect to it remotely by assigning the NetBIOS name of the
> DC to the variable strComputer). Given the value of the sAMAccountName
> attribute (the "pre-Windows 2000 logon name"), it retrieves other
> attributes of the user object. However, there are no attributes of user
> objects indicating which PC the user is currently logged into. The main
> purpose of AD is to store relatively stable information that changes
> infrequently. Network traffic would be increased significantly if AD had
> to replicate new information to all DC's everytime someone logged on and
> off.
>
> I believe there are third party tools that attempt to give you the
> information you ask for. Someone else may respond with more information
> that.
>
> Otherwise, one method I've used in the past, but which is unreliable, uses
> the LanmanServer service on a computer to enumerate sessions:
> ============
> Option Explicit
> Dim objDC, objSession, strComputer
>
> strComputer = "MyServer"
>
> Set objDC = GetObject("WinNT://" & strComputer & "/LanmanServer")
> For Each objSession In objDC.Sessions
> Wscript.Echo objSession.Name
> Wscript.Echo objSession.User
> Wscript.Echo objSession.Computer
> Next
> =======
> This only enumerates active sessions on the one computer. If the user is
> not currently doing something on the machine, the session disappears.
> Plus, you would need to run this on every DC and member server where a
> user might be using network resources.
>
> Otherwise, I have used logon and logoff scripts to keep track of which
> user uses which computer. The scripts log the user name, date/time, and
> computer name to a shared log file. This file can be copied and opened by
> a spreadsheet program where you can filter/sort by user, computer, date,
> etc. In principal you can tell which computer a given user was using when
> you copied the log file. I have VBScript examples at this link:
>
> http://www.rlmueller.net/Logon5.htm
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
>

My System SpecsSystem Spec
Old 08-18-2009   #5 (permalink)
Richard Mueller [MVP]


 
 

Re: Return computer name

A third party tool that might help is LimitLogin:

http://technet.microsoft.com/en-us/m...spotlight.aspx

The purpose is to limit logins, but to do this it must keep track of users
(and the computers they are logged into). The link explains that most
similar solutions maintain a separate SQL database, but this one creates an
application directory partition in AD for the purpose. The GUI provided may
enable you get the information you want. Or, you probably can use ADO to
query the partition for the user name or the computer name. If you go this
route, this link on using ADO to query AD in VBScript programs should help:

http://www.rlmueller.net/ADOSearchTips.htm

The base of your query would be the new application partition. You could use
ADSI Edit to browse the new partition and determine the objects and
attributes available.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--

"James" <dontemailme@xxxxxx> wrote in message
news:uVbatiCIKHA.1380@xxxxxx
Quote:

> Thanks again Richard
>
> "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
> message news:OtS3B8BIKHA.3708@xxxxxx
Quote:

>>
>> "James" <dontemailme@xxxxxx> wrote in message
>> news:OxOFyQBIKHA.1376@xxxxxx
Quote:

>>>I have found the following code example...
>>>
>>> It is along the lines of what I am looking for. All I have to do is
>>> input the user name and it will return some info from AD. I just need
>>> it to return the name or IP address of the computer the user is
>>> currently using. Can that be done?
>>>
>>> Option Explicit
>>> Dim strComputer, strUsername, objWMI, colUsers, objUser
>>>
>>> strComputer = "."
>>> Set objWMI = GetObject("winmgmts:\\" & strComputer &
>>> "\root\directory\LDAP")
>>>
>>> strUsername = InputBox("Please type the user name")
>>> Set colUsers = objWMI.ExecQuery("SELECT * FROM ds_user where
>>> ds_sAMAccountName = '" & strUsername & "'")
>>>
>>> If colUsers.Count > 0 Then
>>> For Each objUser in colUsers
>>> WScript.Echo "First Name: " & objUser.ds_givenName
>>> WScript.Echo "Last Name: " & objUser.ds_sn
>>> Next
>>> Else
>>> WScript.Echo "No users found!"
>>> End If
>>>
>>> James
>>>
>>>
>>> "James" <dontemailme@xxxxxx> wrote in message
>>> news:Oxz19tAIKHA.4436@xxxxxx
>>>> Is is possible to return the name of the computer an AD user is using
>>>> if you only know their user name? If so, any examples or links to
>>>> example you could provide would be great. I am looking to use pure
>>>> vbs, no HTA, no HTML...if possible.
>>>>
>>>> regards,
>>>>
>>>> James
>>>>
>>>
>>>
>>
>> Active Directory does not keep track of which user is logged into which
>> computer. In fact, AD doesn't even keep track if the user is still logged
>> on at all.
>>
>> The code snippet you included is new to me, but it appears to query an
>> LDAP database on the machine, in which case it must be run on a Domain
>> Controller (or connect to it remotely by assigning the NetBIOS name of
>> the DC to the variable strComputer). Given the value of the
>> sAMAccountName attribute (the "pre-Windows 2000 logon name"), it
>> retrieves other attributes of the user object. However, there are no
>> attributes of user objects indicating which PC the user is currently
>> logged into. The main purpose of AD is to store relatively stable
>> information that changes infrequently. Network traffic would be increased
>> significantly if AD had to replicate new information to all DC's
>> everytime someone logged on and off.
>>
>> I believe there are third party tools that attempt to give you the
>> information you ask for. Someone else may respond with more information
>> that.
>>
>> Otherwise, one method I've used in the past, but which is unreliable,
>> uses the LanmanServer service on a computer to enumerate sessions:
>> ============
>> Option Explicit
>> Dim objDC, objSession, strComputer
>>
>> strComputer = "MyServer"
>>
>> Set objDC = GetObject("WinNT://" & strComputer & "/LanmanServer")
>> For Each objSession In objDC.Sessions
>> Wscript.Echo objSession.Name
>> Wscript.Echo objSession.User
>> Wscript.Echo objSession.Computer
>> Next
>> =======
>> This only enumerates active sessions on the one computer. If the user is
>> not currently doing something on the machine, the session disappears.
>> Plus, you would need to run this on every DC and member server where a
>> user might be using network resources.
>>
>> Otherwise, I have used logon and logoff scripts to keep track of which
>> user uses which computer. The scripts log the user name, date/time, and
>> computer name to a shared log file. This file can be copied and opened by
>> a spreadsheet program where you can filter/sort by user, computer, date,
>> etc. In principal you can tell which computer a given user was using when
>> you copied the log file. I have VBScript examples at this link:
>>
>> http://www.rlmueller.net/Logon5.htm
>>
>> --
>> Richard Mueller
>> MVP Directory Services
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>>
>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Query user id return computer name PowerShell
Is it possible to return to the old hotmail ? Live Mail
Return by ref? PowerShell
Return to XP? Vista General
Return to XP Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46