Find logged in User on domain 
Author Message
 Find logged in User on domain

How can I find out if a user is logged onto my domain and what computer it
is

Thanks



Fri, 02 Sep 2005 00:51:53 GMT  
 Find logged in User on domain
hi, hope this vbs script helps..

' Initialize the variable farm
Dim objUserName, objUserDomain, objGroup, objUser, strGroupList, WshShell, strMessage, strTitle
Dim objDomain, strDomain, strUserName, strOS, strVer, strSortedGroups, arrGroupList, strUserList
Dim strstrMsgNoUser, strDefaultPrinter, objProcessor

Dim objChangePwdTrue, objChangePwd, objUserProfile
Dim objPwdExpiresTrue, objFlags, oPwdExpire, strPwdExpires
Dim objAcctDisabled, intPwdExpired, objPwdExpiredTrue

' Set WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
strVer = "Ver 1.0 "
strQuote = Chr(34)

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oPrinters = WshNetwork.EnumPrinterConnections

' Pull Environment variables for domain/user
strDomain = WshShell.ExpandEnvironmentStrings("%USERDOMAIN%")
strUserName = WshShell.ExpandEnvironmentStrings("%USERNAME%")
strOS = WshShell.ExpandEnvironmentStrings("%OS%")
'strDefaultPrinter = oPrinters.Item(1)PrintQueue.PrinterName

' WScript.Echo "Network printer mappings:"
  '       For i = 0 to oPrinters.Count - 1 Step 2
    '        WScript.Echo "Port " & oPrinters.Item(i) & " = " & oPrinters.Item(i+1)
    '     Next

SysTest ' sub routine to check for Script Version/ADSI installed
GetInfo ' sub routine to get user information

on error resume Next
' Creates the list of goups the user belongs To
For Each objGroup In objUser.Groups
        If strGroupList = "" Then
                strGroupList = objGroup.Name

'*****************************************************
' This WSH script allows the user to quickly set
' the default printer.
'*****************************************************

'Dim Text, Title, i, j, tmp, printer, PrinterText
'Dim WshNetwork, oDevices

'Set WshNetwork = WScript.CreateObject("WScript.Network")

'Set oDevices = WshNetwork.EnumPrinterConnections

'Text = "Listed below are the printers currently available to you.  Please enter the number of

'the printer you want set as the default." & vbCrLf & vbCrLf
'j = oDevices.Count
'For i = 0 To j - 1 Step 2
 '   Text = Text & (i/2) & vbTab
 '   Text = Text & oDevices(i) & vbTab & oDevices(i+1) & vbCrLf
'Next

'tmp = InputBox(Text, "Select default printer", 0)
'If tmp = "" Then
'    WScript.Echo "No user input, aborted"
'    WScript.Quit
'End If

'tmp = CInt(tmp)
'If (tmp < 0) Or (tmp > (j/2 - 1)) Then
'    WScript.Echo "Wrong value, aborted"
'    WScript.Quit
'End If

'printer = oDevices(tmp*2 + 1)

'WshNetwork.SetDefaultPrinter printer

'MsgBox "Your default printer has been successfully set to " & printer, _
  '      vbOKOnly + vbInformation, Title

'*** End

        Else
                strGroupList = strGroupList & ", " & objGroup.Name
        End If
Next
' Convert strgrouplist to Array
arrGroupList = Split(strGroupList,",")
'Sort the durn thing
Quicksort arrGroupList, LBound(arrGroupList), UBound(arrGroupList)
' Now concatenate arrGroupList into a variable for display
strSortedGroups = Join(arrGroupList, ", ")

'check for expired password

intPwdExpired = objUser.Get("PasswordExpired")

        If intPwdExpired = 1 Then
                objPwdExpiredTrue = "Yes"
                Else objPwdExpiredTrue = "No"
        End If

'Check for Must Change Password Flag
objFlags = objUser.Get("UserFlags")

        If (objFlags And &H00040) <> 0 Then
                objChangePwdTrue = "No"
                Else objChangePwdTrue = "Yes"
        End If

' Is password set to NEVER expire?
objPwdExpires = objUser.Get("UserFlags")

        If (objPwdExpires And &H10000) <> 0 Then
                objPwdExpiresTrue = "Yes"
                        strPwdExpires = "Date Set: "
                Else objPwdExpiresTrue = "No"
                        strPwdExpires = "Password Expires: "
        End If

' Is the account disabled?
        If objUser.AccountDisabled = True Then
                objAccountDisabled = "Yes"
                Else objAccountDisabled = "No"
        End If

'How many wrong logins?
'Int objBadLogins
objBadLogins = objUser.BadPasswordAttempts

'Maximum bad password attempts?
objMaxBadPwd = objUser.MaxBadPasswordsAllowed  

objPrinter = PrintQueue.PrinterName

'Unlock Interval after bad attempts?
objAutoUnlock = FormatNumber((objUser.AutoUnlockInterval/60), 0)

'Account Lockout Observation Interval
objAcctLockout = FormatNumber((objUser.LockoutObservationInterval/60), 0)

' How old is the current password?
objPwdAge = FormatNumber(((objUser.Get("PasswordAge")/60)/60)/24, 0)

' Calculate the date the password was last changed
objPwdLastChanged = CStr(objUser.PasswordExpirationDate - objUser.Get("MaxPasswordAge") / (60 *

60 * 24))

' Set Profile path to tabs if blank
objUserProfile = objUser.Profile
        If objUserProfile = "" Then
                objUserProfile= "<None>" & vbTab
                Else objUserProfile = objUserProfile
        End If

' Determine how many passwords are saved
Set Domain = GetObject("WinNT://" & objDomain)

Set Computer= GetObject("WinNT://" & objComputer)

objProcessor = Computer.Processor

Int intPwdHistory
intPwdHistory = Domain.PasswordHistoryLength

' Set strMessage box variables to null  
strMessage =""

'popup user information: each line broken up for better reading
strMessage = strMessage & "Domain: " & objDomain & vbTab & "User Name: " & objUserName & _
vbTab & "Full Name: " & objUser.FullName & vbCrLf
strMessage = strMessage &  "Description: " & objUser.Description & vbCrLf & vbCrLf

strMessage = strMessage & "Domain: " & objDomain & " " & vbTab & _
"Default Printer: "& objProcessor & vbTab & "Full Name: " & objUser.FullName & vbCrLf
strMessage = strMessage &  "Description: " & objUser.Description & vbCrLf & vbCrLf

strMessage = strMessage & "Account Locked Out: " & objUser.IsAccountLocked & _
vbTab & "Account Disabled: " & objAccountDisabled & vbCrLf
strMessage = strMessage &  "Bad Logins: " & objBadLogins & vbTab & vbTab & "Last logon: " & _
objUser.LastLogin & vbCrLf
strMessage = strMessage & "Max password attempts: " & objMaxBadPwd & vbTab & "Attempts left: " &

_
objMaxBadPwd - objBadLogins & vbCrLf & vbCrLf

strMessage = strMessage & "Password Expired: " & objPwdExpiredTrue & vbTab & "Password Age: " & _
objPwdAge & " days" & vbCrLf
strMessage = strMessage & "Password Last Changed: " & vbTab & objPwdLastChanged & vbCrLf
strMessage = strMessage & "Password Never Expires: " & objPwdExpiresTrue & vbTab & strPwdExpires

& _
objUser.PasswordExpirationDate & vbCrLf  & vbCrLf

strMessage = strMessage & "User can change Pwd: " & objChangePwdTrue & _
vbTab & "Password Minimum Length: " & objUser.PasswordMinimumLength & vbCrLf
strMessage = strMessage & "Passwords Kept In History: " & vbTab & intPwdHistory & " password(s)"

& vbCrLf
strMessage = strMessage & "Lockout Time: " & objAcctLockout & " minutes" & vbTab & "AutoUnlock: "

& _
objAutoUnlock & " minutes" & vbCrLf & vbCrLf

strMessage = strMessage & "Login Script: " & objUser.LoginScript & vbTab & "Home Directory: " & _
objUser.HomeDirectory & vbCrLf
strMessage = strMessage & "User Profile Path: " & objUserProfile & vbCrLf & vbCrLf

strMessage = strMessage & "User Groups: " & vbCrLf & vbCrLf & strSortedGroups & vbCrLf

' Display User Information!
WshShell.Popup strMessage,0,strVer & " User Information for: " & objUserName & " in " & objDomain

Sub GetInfo()
' Define user then retrieve and store groups in a list
' Retrieve Domain from user
If strOS = "Windows_NT" Then

strMessage = "Please enter the domain to search." & vbCrLf & vbCrLf & _
"Default is: " & strDomain & vbCrLf & vbCrLf
strMessage = strMessage & "Hit Cancel or enter a blank to quit"
strTitle = "Domain to Search"

        'get resource domain name, domain default
        objDomain = InputBox(strMessage, strTitle, strDomain)

        ' Evaluate the user input.
        If objDomain = "" Then    ' Cancelled by the user
            WScript.quit
        End If
Else    'must be Windows 9x

strMessage = "Please enter the domain to search." & vbCrLf & vbCrLf & "Hit Cancel or enter a

blank to quit"
strTitle = "Domain to Search"

        'get resource domain name, domain default
        objDomain = InputBox(strMessage, strTitle)

        ' Evaluate the user input.
        If objDomain = "" Then    ' Cancelled by the user
            WScript.quit
        End If
End If  
' Set strMessage box variables to null  
strMessage = ""
strTitle = ""

on error resume Next

' Define username dialog box variables.

If strOS = "Windows_NT" Then
strMessage = "Please enter the USER Login ID" & vbCrLf & vbCrLf & _
"Default is: " & strUserName & vbCrLf & vbCrLf
strMessage = strMessage & "Hit Cancel or enter a blank to quit"
strTitle = "USER Login ID"

        'get resource domain name, domain default via input box
        objUserName = InputBox(strMessage, strTitle, strUserName)

        ' Evaluate the user input.
        If objUserName = "" Then    ' Cancelled by the user
            WScript.quit
        End If

Else    ' If NOT Windows NT then must be Win 9x

strMessage = "Please enter the USER Login ID" & vbCrLf & vbCrLf
strMessage = strMessage & "Hit Cancel or enter a blank to quit"
strTitle = "USER Login ID"
'get resource domain name, domain default via input box
        objUserName = InputBox(strMessage, strTitle)

        ' Evaluate the user input.
        If objUserName = "" Then    ' Cancelled by the user
            WScript.quit
        End If
End If

        ' Display Just a minute!
        strMessage = "This may take a few seconds. . ."

        WshShell.Popup strMessage,2,"One moment please. . . "
        strMessage = ""

'Attempt to bind to the user
Set objUser = GetObject("WinNT://"& objDomain &"/"& objUserName, user)

If Err <> 0 Then
' Lets see if anyone matches objUserName first 4 characters...
Set objFindUser = GetObject("WinNT://"& objDomain)
objUserName = UCase(objUserName)        ' has to be uppercase
        For Each User In objFindUser    'search thru the domain users list
                If Left(User.Name, 4) = Left(objUserName, 4) Then
                        strUserList = strUserList & User.Name & vbTab & User.Fullname & vbCrLf
                End If
        Next
                ' show list of matching users if any at all
                strMsgNoUser =  "Error: Could not find: " & vbCrLf _
                        & vbCrLf & "WinNT://" & objDomain &"/"& objUserName & vbCrLf & vbCrLf
                strMsgNoUser = strMsgNoUser & "Perhaps you meant one of these: " & vbCrLf &

vbCrLf & strUserList
                WshShell.Popup strMsgNoUser,0,"Error retrieving information",vbCritical

                ' Evaluate the user input in case they want to quit
                If objUserName =
...

read more »



Fri, 02 Sep 2005 22:50:54 GMT  
 Find logged in User on domain
Na thanx but i want to be able to search the domain for a logged on user on
a machine, for example

Get list of machines in domain and find which machine a user is logged onto

cheers


Quote:
> hi, hope this vbs script helps..

> ' Initialize the variable farm
> Dim objUserName, objUserDomain, objGroup, objUser, strGroupList, WshShell,

strMessage, strTitle
Quote:
> Dim objDomain, strDomain, strUserName, strOS, strVer, strSortedGroups,

arrGroupList, strUserList
Quote:
> Dim strstrMsgNoUser, strDefaultPrinter, objProcessor

> Dim objChangePwdTrue, objChangePwd, objUserProfile
> Dim objPwdExpiresTrue, objFlags, oPwdExpire, strPwdExpires
> Dim objAcctDisabled, intPwdExpired, objPwdExpiredTrue

> ' Set WshShell
> Set WshShell = WScript.CreateObject("WScript.Shell")
> strVer = "Ver 1.0 "
> strQuote = Chr(34)

> Set WshNetwork = WScript.CreateObject("WScript.Network")
> Set oPrinters = WshNetwork.EnumPrinterConnections

> ' Pull Environment variables for domain/user
> strDomain = WshShell.ExpandEnvironmentStrings("%USERDOMAIN%")
> strUserName = WshShell.ExpandEnvironmentStrings("%USERNAME%")
> strOS = WshShell.ExpandEnvironmentStrings("%OS%")
> 'strDefaultPrinter = oPrinters.Item(1)PrintQueue.PrinterName

> ' WScript.Echo "Network printer mappings:"
>   '       For i = 0 to oPrinters.Count - 1 Step 2
>     '        WScript.Echo "Port " & oPrinters.Item(i) & " = " &
oPrinters.Item(i+1)
>     '     Next

> SysTest ' sub routine to check for Script Version/ADSI installed
> GetInfo ' sub routine to get user information

> on error resume Next
> ' Creates the list of goups the user belongs To
> For Each objGroup In objUser.Groups
> If strGroupList = "" Then
> strGroupList = objGroup.Name

> '*****************************************************
> ' This WSH script allows the user to quickly set
> ' the default printer.
> '*****************************************************

> 'Dim Text, Title, i, j, tmp, printer, PrinterText
> 'Dim WshNetwork, oDevices

> 'Set WshNetwork = WScript.CreateObject("WScript.Network")

> 'Set oDevices = WshNetwork.EnumPrinterConnections

> 'Text = "Listed below are the printers currently available to you.  Please
enter the number of

> 'the printer you want set as the default." & vbCrLf & vbCrLf
> 'j = oDevices.Count
> 'For i = 0 To j - 1 Step 2
>  '   Text = Text & (i/2) & vbTab
>  '   Text = Text & oDevices(i) & vbTab & oDevices(i+1) & vbCrLf
> 'Next

> 'tmp = InputBox(Text, "Select default printer", 0)
> 'If tmp = "" Then
> '    WScript.Echo "No user input, aborted"
> '    WScript.Quit
> 'End If

> 'tmp = CInt(tmp)
> 'If (tmp < 0) Or (tmp > (j/2 - 1)) Then
> '    WScript.Echo "Wrong value, aborted"
> '    WScript.Quit
> 'End If

> 'printer = oDevices(tmp*2 + 1)

> 'WshNetwork.SetDefaultPrinter printer

> 'MsgBox "Your default printer has been successfully set to " & printer, _
>   '      vbOKOnly + vbInformation, Title

> '*** End

> Else
> strGroupList = strGroupList & ", " & objGroup.Name
> End If
> Next
> ' Convert strgrouplist to Array
> arrGroupList = Split(strGroupList,",")
> 'Sort the durn thing
> Quicksort arrGroupList, LBound(arrGroupList), UBound(arrGroupList)
> ' Now concatenate arrGroupList into a variable for display
> strSortedGroups = Join(arrGroupList, ", ")

> 'check for expired password

> intPwdExpired = objUser.Get("PasswordExpired")

> If intPwdExpired = 1 Then
> objPwdExpiredTrue = "Yes"
> Else objPwdExpiredTrue = "No"
> End If

> 'Check for Must Change Password Flag
> objFlags = objUser.Get("UserFlags")

> If (objFlags And &H00040) <> 0 Then
> objChangePwdTrue = "No"
> Else objChangePwdTrue = "Yes"
> End If

> ' Is password set to NEVER expire?
> objPwdExpires = objUser.Get("UserFlags")

> If (objPwdExpires And &H10000) <> 0 Then
> objPwdExpiresTrue = "Yes"
> strPwdExpires = "Date Set: "
> Else objPwdExpiresTrue = "No"
> strPwdExpires = "Password Expires: "
> End If

> ' Is the account disabled?
> If objUser.AccountDisabled = True Then
> objAccountDisabled = "Yes"
> Else objAccountDisabled = "No"
> End If

> 'How many wrong logins?
> 'Int objBadLogins
> objBadLogins = objUser.BadPasswordAttempts

> 'Maximum bad password attempts?
> objMaxBadPwd = objUser.MaxBadPasswordsAllowed

> objPrinter = PrintQueue.PrinterName

> 'Unlock Interval after bad attempts?
> objAutoUnlock = FormatNumber((objUser.AutoUnlockInterval/60), 0)

> 'Account Lockout Observation Interval
> objAcctLockout = FormatNumber((objUser.LockoutObservationInterval/60), 0)

> ' How old is the current password?
> objPwdAge = FormatNumber(((objUser.Get("PasswordAge")/60)/60)/24, 0)

> ' Calculate the date the password was last changed
> objPwdLastChanged = CStr(objUser.PasswordExpirationDate -

objUser.Get("MaxPasswordAge") / (60 *

- Show quoted text -

Quote:

> 60 * 24))

> ' Set Profile path to tabs if blank
> objUserProfile = objUser.Profile
> If objUserProfile = "" Then
> objUserProfile= "<None>" & vbTab
> Else objUserProfile = objUserProfile
> End If

> ' Determine how many passwords are saved
> Set Domain = GetObject("WinNT://" & objDomain)

> Set Computer= GetObject("WinNT://" & objComputer)

> objProcessor = Computer.Processor

> Int intPwdHistory
> intPwdHistory = Domain.PasswordHistoryLength

> ' Set strMessage box variables to null
> strMessage =""

> 'popup user information: each line broken up for better reading
> strMessage = strMessage & "Domain: " & objDomain & vbTab & "User Name: " &
objUserName & _
> vbTab & "Full Name: " & objUser.FullName & vbCrLf
> strMessage = strMessage &  "Description: " & objUser.Description & vbCrLf
& vbCrLf

> strMessage = strMessage & "Domain: " & objDomain & " " & vbTab & _
> "Default Printer: "& objProcessor & vbTab & "Full Name: " &

objUser.FullName & vbCrLf
Quote:
> strMessage = strMessage &  "Description: " & objUser.Description & vbCrLf
& vbCrLf

> strMessage = strMessage & "Account Locked Out: " & objUser.IsAccountLocked
& _
> vbTab & "Account Disabled: " & objAccountDisabled & vbCrLf
> strMessage = strMessage &  "Bad Logins: " & objBadLogins & vbTab & vbTab &
"Last logon: " & _
> objUser.LastLogin & vbCrLf
> strMessage = strMessage & "Max password attempts: " & objMaxBadPwd & vbTab

& "Attempts left: " &
Quote:

> _
> objMaxBadPwd - objBadLogins & vbCrLf & vbCrLf

> strMessage = strMessage & "Password Expired: " & objPwdExpiredTrue & vbTab

& "Password Age: " & _
Quote:
> objPwdAge & " days" & vbCrLf
> strMessage = strMessage & "Password Last Changed: " & vbTab &

objPwdLastChanged & vbCrLf
Quote:
> strMessage = strMessage & "Password Never Expires: " & objPwdExpiresTrue &

vbTab & strPwdExpires
Quote:

> & _
> objUser.PasswordExpirationDate & vbCrLf  & vbCrLf

> strMessage = strMessage & "User can change Pwd: " & objChangePwdTrue & _
> vbTab & "Password Minimum Length: " & objUser.PasswordMinimumLength &
vbCrLf
> strMessage = strMessage & "Passwords Kept In History: " & vbTab &

intPwdHistory & " password(s)"
Quote:

> & vbCrLf
> strMessage = strMessage & "Lockout Time: " & objAcctLockout & " minutes" &

vbTab & "AutoUnlock: "
Quote:

> & _
> objAutoUnlock & " minutes" & vbCrLf & vbCrLf

> strMessage = strMessage & "Login Script: " & objUser.LoginScript & vbTab &

"Home Directory: " & _
Quote:
> objUser.HomeDirectory & vbCrLf
> strMessage = strMessage & "User Profile Path: " & objUserProfile & vbCrLf
& vbCrLf

> strMessage = strMessage & "User Groups: " & vbCrLf & vbCrLf &

strSortedGroups & vbCrLf
Quote:

> ' Display User Information!
> WshShell.Popup strMessage,0,strVer & " User Information for: " &

objUserName & " in " & objDomain

- Show quoted text -

Quote:

> Sub GetInfo()
> ' Define user then retrieve and store groups in a list
> ' Retrieve Domain from user
> If strOS = "Windows_NT" Then

> strMessage = "Please enter the domain to search." & vbCrLf & vbCrLf & _
> "Default is: " & strDomain & vbCrLf & vbCrLf
> strMessage = strMessage & "Hit Cancel or enter a blank to quit"
> strTitle = "Domain to Search"

> 'get resource domain name, domain default
> objDomain = InputBox(strMessage, strTitle, strDomain)

> ' Evaluate the user input.
> If objDomain = "" Then    ' Cancelled by the user
>     WScript.quit
> End If
> Else 'must be Windows 9x

> strMessage = "Please enter the domain to search." & vbCrLf & vbCrLf & "Hit
Cancel or enter a

> blank to quit"
> strTitle = "Domain to Search"

> 'get resource domain name, domain default
> objDomain = InputBox(strMessage, strTitle)

> ' Evaluate the user input.
> If objDomain = "" Then    ' Cancelled by the user
>     WScript.quit
> End If
> End If
> ' Set strMessage box variables to null
> strMessage = ""
> strTitle = ""

> on error resume Next

> ' Define username dialog box variables.

> If strOS = "Windows_NT" Then
> strMessage = "Please enter the USER Login ID" & vbCrLf & vbCrLf & _
> "Default is: " & strUserName & vbCrLf & vbCrLf
> strMessage = strMessage & "Hit Cancel or enter a blank to quit"
> strTitle = "USER Login ID"

> 'get resource domain name, domain default via input box
> objUserName = InputBox(strMessage, strTitle, strUserName)

> ' Evaluate the user input.
> If objUserName = "" Then    ' Cancelled by the user
>     WScript.quit
> End If

> Else ' If NOT Windows NT then must be Win 9x

> strMessage = "Please enter the USER Login ID" & vbCrLf & vbCrLf
> strMessage = strMessage & "Hit Cancel or enter a blank to quit"
> strTitle = "USER Login ID"
> 'get resource domain name, domain default via input box
> objUserName = InputBox(strMessage, strTitle)

> ' Evaluate the user input.
> If objUserName = "" Then    ' Cancelled by the user
>     WScript.quit
> End If
> End If

> ' Display Just a minute!
> strMessage = "This may take a few seconds. . ."

> WshShell.Popup strMessage,2,"One moment please. . . "
> strMessage = ""

> 'Attempt to bind to the user
> Set objUser = GetObject("WinNT://"& objDomain &"/"& objUserName, user)

> If Err <> 0 Then
> ' Lets see if anyone matches objUserName first 4 characters...
> Set

...

read more »



Sat, 03 Sep 2005 19:51:14 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Current Domain User Name of logged in user?

2. Using VBScript to find out who is logged onto remote machines/domains

3. Resolving Logged on domain users

4. Logging on as a different domain user?

5. VB Code to list the Users logged on in a Domain

6. Disconnecting/logging off user from server (domain)???? URGENT

7. Verify the User have logged on to the domain

8. How to determine if a user is logged in to Domain

9. VB code to list users logged onto a domain

10. How to get the NT-Domain of a logged on User from VB 5.0

11. Checking if user is logged to domain

12. Users Logged Onto A Domain

 

 
Powered by phpBB® Forum Software