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

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.
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.


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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

770 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