Interogating NT

Posted on 1999-01-25
Medium Priority
Last Modified: 2010-05-03
How can I interogate my Windows NT servers to know wich uses are currently logged, wich files are opened, etc.

I want to do something similar to the Server Manager tool that comes with NT. I will be using this app on the server itself and also from remote Win95 station.

Please tell me the available API calls to do that.

Thank you
Question by:frenchjericho
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 1470545
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Function loginn() As String
Dim s As String, i As Integer, lettre As String
s = String(255, 0)
i = GetUserName(s, 255)
loginn = s
End Function
The function loginn will give you the user name

Expert Comment

ID: 1470546
That will only give you the current name of the person logged into a PC.

Have a look at :



There are sections here that have code to do the type of things you want.

Author Comment

ID: 1470547
This code will only give me the name of the currently logged user. That is not what I'm looking for.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Accepted Solution

anzen earned 100 total points
ID: 1470548
You must use the NetSessionEnum() and NetSessionGetInfo() APIs
exported by svrapi.dll, these two functions together allow You to enumerate the current server sessions and to retrieve details about each enumerated session, for more details You'd better get the MSDN CD which comes with the Pro/Ent edition of VB and make a quick search for these APIs


Author Comment

ID: 1470549
Can any one post the correct vb declaration these fonctions?

Expert Comment

ID: 1470550
Try this...
Sorry I've written it down in a pair of minutes...

Option Explicit

' Level flags (0 and 10 are allowed to non-admins too)
Private Const INFO_LEVEL0 = 0&
Private Const INFO_LEVEL10 = 10&

Private Type tag_SESSION_INFO_0
    lpSesi0_cname       As Long     ' computer name
End Type

Private Type tag_SESSION_INFO_10
    lpSesi10_cname      As Long     ' computer name
    lpSesi10_username   As Long     ' user name
    dwSesi10_time       As Long     ' session time
    dwSesi10_idle_time  As Long     ' session idle time
End Type

#If WIN9X Then
' WIN 9X - lib is svrapi.dll
Private Declare Function NetSessionEnum Lib "svrapi.dll" (ByVal lpServername As Long, ByVal sUncClientName As Long, ByVal sUsername As Long, ByVal dwLevel As Long, lpBufPtr As Any, ByVal dwPrefMaxLen As Long, dwEntriesRead As Long, dwTotalEntries As Long, hResume As Long) As Long
' WIN NT - lib is netapi32.dll
Private Declare Function NetSessionEnum Lib "netapi32.dll" (ByVal lpServername As Long, ByVal sUncClientName As Long, ByVal sUsername As Long, ByVal dwLevel As Long, lpBufPtr As Any, ByVal dwPrefMaxLen As Long, dwEntriesRead As Long, dwTotalEntries As Long, hResume As Long) As Long
#End If
Private Declare Sub MemCpy Lib "kernel32.dll" Alias "RtlMoveMemory" (lpDes As Any, lpSrc As Any, ByVal lSize As Long)
Private Declare Sub MemClr Lib "kernel32.dll" Alias "RtlZeroMemory" (lpDes As Any, ByVal lSize As Long)
' Load saSessInfo with session infos (level 0)
' e.g. lRet=GetSessions("\\MyServer",saSessions())
Public Function GetSessions(ByVal sServerID As String, saSessInfo() As String) As Long
    Dim lRet As Long
    Dim sServerName As String, tSES0 As tag_SESSION_INFO_0
    Dim lBufSize As Long, lReadCount As Long, lTotCount As Long
    Dim hResume As Long, sBuff As String, lCount As Long
    Erase saSessInfo
    ReDim saSessInfo(1)
        sServerName = sServerID
        lBufSize = 32
        tSES0.lpSesi0_cname = 0&
        lRet = NetSessionEnum(StrPtr(sServerName), 0&, 0&, INFO_LEVEL0, tSES0, lBufSize, lReadCount, lTotCount, hResume)
        If tSES0.lpSesi0_cname <> 0 Then
            ' extract info and load array
            sBuff = String(32, vbNullChar)
            MemCpy ByVal sBuff, ByVal tSES0.lpSesi0_cname, 32
            sBuff = Mid(StrConv(sBuff, vbFromUnicode), 3)
            sBuff = Mid(sBuff, 1, InStr(sBuff & vbNullChar, vbNullChar) - 1)
            ReDim Preserve saSessInfo(lCount + 1)
            saSessInfo(lCount) = sBuff
            lCount = lCount + 1
        End If
    Loop While tSES0.lpSesi0_cname <> 0
    GetSessions = lCount
End Function

Bye (Byte .. :-D)

Author Comment

ID: 1470551
It doesn't work: "bad DLL calling convention"

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 6 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question