Solved

Interogating NT

Posted on 1999-01-25
7
207 Views
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
0
Comment
Question by:frenchjericho
7 Comments
 

Expert Comment

by:robertbeauregard
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
0
 
LVL 3

Expert Comment

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

Have a look at :
http://www.netfokus.dk/vbadmincode/

or

http://www.mvps.org/vb


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

Author Comment

by:frenchjericho
ID: 1470547
This code will only give me the name of the currently logged user. That is not what I'm looking for.
0
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!

 
LVL 4

Accepted Solution

by:
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

0
 

Author Comment

by:frenchjericho
ID: 1470549
Can any one post the correct vb declaration these fonctions?
0
 
LVL 4

Expert Comment

by:anzen
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
#Else
' 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)
    Do
        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)
0
 

Author Comment

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

Featured Post

Technology Partners: 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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

756 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