Solved

Interogating NT

Posted on 1999-01-25
7
193 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now