Results 1 to 10 of 10

Thread: How to get the currently logged on user of a remote computer

  1. #1

    Thread Starter
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011

    How to get the currently logged on user of a remote computer

    Any NetAPI which could retrieve the name of user currently logged in on a remote computer.. and the time a remote computer is on for..
    ?????

  2. #2
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918
    I'm not sure about how to use the net API's to do this, but Sysinternal Software has a free utility which can return the logged in user from a remote machine.

    You could shell to this prog and send its output to a text file.

    The program is called PsLoggedOn and you can get it here: http://www.sysinternals.com/ntw2k/fr...loggedon.shtml
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  3. #3

    Thread Starter
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    Anybody plz...I need VB code!!

  4. #4
    Hyperactive Member Dasiths's Avatar
    Join Date
    Apr 2001
    Location
    Colombo, Sri Lanka
    Posts
    331

    moin kahn

    r u the pakistani former wicket keeper ......... in cricket team ........... lol
    It is the mark of an instructed mind to rest satisfied with the degree of precision which the nature of the subject admits, and not to seek exactness when only an approximation of the truth is possible.
    -Aristotle As quoted in Rapid Development, chapter 8, page 167.

  5. #5
    Junior Member
    Join Date
    Oct 2002
    Posts
    30
    You could use WMI.

    Code:
    Set objWMIService = GetObject("winmgmts:" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem", , 48)
        For Each objItem In colItems
            RemoteUser = objItem.Username
        Next
    Also check out Microsoft's documentation.
    http://www.microsoft.com/technet/tre...er/ScrUG59.asp

  6. #6

    Thread Starter
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011

    Re: moin kahn

    Originally posted by Dasiths
    r u the pakistani former wicket keeper ......... in cricket team ........... lol
    Maybe

  7. #7

    Thread Starter
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    I've used your code ITGuy.. but it's very slow and it doesn't get the username of all computers and moreover it also gives permission denied error...
    IT only gives the username of those computers on which i have the administrative rights... (and in our 75 computers i have the administrative rights on only 10 )
    Any ideas?

  8. #8
    Hyperactive Member Libero's Avatar
    Join Date
    Jun 2000
    Location
    Swedish viking
    Posts
    460
    In a form with a Listbox "Listbox1"
    This code is from VBnet..

    VB Code:
    1. Private Const MAX_PREFERRED_LENGTH As Long = -1
    2. Private Const NERR_SUCCESS As Long = 0&
    3. Private Const ERROR_MORE_DATA As Long = 234&
    4.  
    5. Private Const SV_TYPE_WORKSTATION         As Long = &H1
    6. Private Const SV_TYPE_SERVER              As Long = &H2
    7. Private Const SV_TYPE_SQLSERVER           As Long = &H4
    8. Private Const SV_TYPE_DOMAIN_CTRL         As Long = &H8
    9. Private Const SV_TYPE_DOMAIN_BAKCTRL      As Long = &H10
    10. Private Const SV_TYPE_TIME_SOURCE         As Long = &H20
    11. Private Const SV_TYPE_AFP                 As Long = &H40
    12. Private Const SV_TYPE_NOVELL              As Long = &H80
    13. Private Const SV_TYPE_DOMAIN_MEMBER       As Long = &H100
    14. Private Const SV_TYPE_PRINTQ_SERVER       As Long = &H200
    15. Private Const SV_TYPE_DIALIN_SERVER       As Long = &H400
    16. Private Const SV_TYPE_XENIX_SERVER        As Long = &H800
    17. Private Const SV_TYPE_SERVER_UNIX         As Long = SV_TYPE_XENIX_SERVER
    18. Private Const SV_TYPE_NT                  As Long = &H1000
    19. Private Const SV_TYPE_WFW                 As Long = &H2000
    20. Private Const SV_TYPE_SERVER_MFPN         As Long = &H4000
    21. Private Const SV_TYPE_SERVER_NT           As Long = &H8000
    22. Private Const SV_TYPE_POTENTIAL_BROWSER   As Long = &H10000
    23. Private Const SV_TYPE_BACKUP_BROWSER      As Long = &H20000
    24. Private Const SV_TYPE_MASTER_BROWSER      As Long = &H40000
    25. Private Const SV_TYPE_DOMAIN_MASTER       As Long = &H80000
    26. Private Const SV_TYPE_SERVER_OSF          As Long = &H100000
    27. Private Const SV_TYPE_SERVER_VMS          As Long = &H200000
    28. Private Const SV_TYPE_WINDOWS             As Long = &H400000  'Windows95 and above
    29. Private Const SV_TYPE_DFS                 As Long = &H800000  'Root of a DFS tree
    30. Private Const SV_TYPE_CLUSTER_NT          As Long = &H1000000 'NT Cluster
    31. Private Const SV_TYPE_TERMINALSERVER      As Long = &H2000000 'Terminal Server
    32. Private Const SV_TYPE_DCE                 As Long = &H10000000 'IBM DSS
    33. Private Const SV_TYPE_ALTERNATE_XPORT     As Long = &H20000000 'rtn alternate transport
    34. Private Const SV_TYPE_LOCAL_LIST_ONLY     As Long = &H40000000 'rtn local only
    35. Private Const SV_TYPE_DOMAIN_ENUM         As Long = &H80000000
    36. Private Const SV_TYPE_ALL                 As Long = &HFFFFFFFF
    37.  
    38. Private Const SV_PLATFORM_ID_OS2       As Long = 400
    39. Private Const SV_PLATFORM_ID_NT        As Long = 500
    40.  
    41. 'Mask applied to svX_version_major in
    42. 'order to obtain the major version number.
    43. Private Const MAJOR_VERSION_MASK        As Long = &HF
    44.  
    45. Private Type SERVER_INFO_100
    46.   sv100_platform_id As Long
    47.   sv100_name As Long
    48. End Type
    49.  
    50. Private Declare Function NetServerEnum Lib "netapi32" _
    51.   (ByVal servername As Long, _
    52.    ByVal level As Long, _
    53.    buf As Any, _
    54.    ByVal prefmaxlen As Long, _
    55.    entriesread As Long, _
    56.    totalentries As Long, _
    57.    ByVal servertype As Long, _
    58.    ByVal domain As Long, _
    59.    resume_handle As Long) As Long
    60.  
    61. Private Declare Function NetApiBufferFree Lib "netapi32" _
    62.    (ByVal Buffer As Long) As Long
    63.  
    64. Private Declare Sub CopyMemory Lib "kernel32" _
    65.    Alias "RtlMoveMemory" _
    66.   (pTo As Any, uFrom As Any, _
    67.    ByVal lSize As Long)
    68.    
    69. Private Declare Function lstrlenW Lib "kernel32" _
    70.   (ByVal lpString As Long) As Long
    71.  
    72.  
    73. Private Sub Form_Load()
    74.  
    75.    Call GetServers(vbNullString)
    76.  
    77. End Sub
    78.    
    79.  
    80.  
    81.  
    82. Private Function GetServers(sDomain As String) As Long
    83.  
    84.   'lists all servers of the specified type
    85.   'that are visible in a domain.
    86.  
    87.    Dim bufptr          As Long
    88.    Dim dwEntriesread   As Long
    89.    Dim dwTotalentries  As Long
    90.    Dim dwResumehandle  As Long
    91.    Dim se100           As SERVER_INFO_100
    92.    Dim success         As Long
    93.    Dim nStructSize     As Long
    94.    Dim Cnt             As Long
    95.  
    96.    nStructSize = LenB(se100)
    97.    
    98.   'Call passing MAX_PREFERRED_LENGTH to have the
    99.   'API allocate required memory for the return values.
    100.   '
    101.   'The call is enumerating all machines on the
    102.   'network (SV_TYPE_ALL); however, by Or'ing
    103.   'specific bit masks for defined types you can
    104.   'customize the returned data. For example, a
    105.   'value of 0x00000003 combines the bit masks for
    106.   'SV_TYPE_WORKSTATION (0x00000001) and
    107.   'SV_TYPE_SERVER (0x00000002).
    108.   '
    109.   'dwServerName must be Null. The level parameter
    110.   '(100 here) specifies the data structure being
    111.   'used (in this case a SERVER_INFO_100 structure).
    112.   '
    113.   'The domain member is passed as Null, indicating
    114.   'machines on the primary domain are to be retrieved.
    115.   'If you decide to use this member, pass
    116.   'StrPtr("domain name"), not the string itself.
    117.    success = NetServerEnum(0&, _
    118.                            100, _
    119.                            bufptr, _
    120.                            MAX_PREFERRED_LENGTH, _
    121.                            dwEntriesread, _
    122.                            dwTotalentries, _
    123.                            SV_TYPE_ALL, _
    124.                            0&, _
    125.                            dwResumehandle)
    126.  
    127.   'if all goes well
    128.    If success = NERR_SUCCESS And _
    129.       success <> ERROR_MORE_DATA Then
    130.        
    131.  
    132.     'loop through the returned data, adding each
    133.     'machine to the list
    134.       For Cnt = 0 To dwEntriesread - 1
    135.          
    136.         'get one chunk of data and cast
    137.         'into an SERVER_INFO_100 struct
    138.         'in order to add the name to a list
    139.          CopyMemory se100, ByVal bufptr + (nStructSize * Cnt), nStructSize
    140.            
    141.          
    142.                List1.AddItem GetPointerToByteStringW(se100.sv100_name)
    143.  
    144.       Next
    145.          
    146.  
    147.    End If
    148.    
    149.   'clean up regardless of success
    150.    Call NetApiBufferFree(bufptr)
    151.    
    152.   'return entries as sign of success
    153.    GetServers = dwEntriesread
    154. End Function
    155.  
    156.  
    157. Public Function GetPointerToByteStringW(ByVal dwData As Long) As String
    158.  
    159.    Dim tmp() As Byte
    160.    Dim tmplen As Long
    161.    
    162.    If dwData <> 0 Then
    163.    
    164.       tmplen = lstrlenW(dwData) * 2
    165.      
    166.       If tmplen <> 0 Then
    167.      
    168.          ReDim tmp(0 To (tmplen - 1)) As Byte
    169.          CopyMemory tmp(0), ByVal dwData, tmplen
    170.          GetPointerToByteStringW = tmp
    171.          
    172.      End If
    173.      
    174.    End If
    175.    
    176. End Function

  9. #9

    Thread Starter
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    Thanx Libero....your code is working like a charm.. but what i need is the way to know the currently logged on user name
    Thanx again..
    Last edited by moinkhan; May 16th, 2003 at 03:08 AM.

  10. #10
    Hyperactive Member Libero's Avatar
    Join Date
    Jun 2000
    Location
    Swedish viking
    Posts
    460
    Ooops! I did see that now.. . Sorry!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width