Interogating NT

Posted on 1999-01-25
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.
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.


Accepted Solution

anzen earned 50 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

Independent Software Vendors: 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!

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

696 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