January 13, 2001

A Trace Tool, Part 1

In my latest article here at VB-2-The-Max (“COM+ Centric Assert“) I promised to deliver a three-part article about tracing. Here I am. Santa Claus is fulfilling your wish list for goodies, I take care of the programming stuff. In this first part I will start with a general discussion about

ServiceCommand – Start, stop, pause, and continue a Windows NT service

Private Type SERVICE_STATUS dwServiceType As Long dwCurrentState As Long dwControlsAccepted As Long dwWin32ExitCode As Long dwServiceSpecificExitCode As Long dwCheckPoint As Long dwWaitHint As LongEnd TypePrivate Declare Function OpenSCManager Lib “advapi32.dll” Alias _ “OpenSCManagerA” (ByVal lpMachineName As String, _ ByVal lpDatabaseName As String, ByVal dwDesiredAccess As Long) As LongPrivate Declare Function

GetServicesInfo – Enumerate Windows NT services

Option ExplicitPrivate Type SERVICE_STATUS ‘ 28 bytes dwServiceType As Long dwCurrentState As Long dwControlsAccepted As Long dwWin32ExitCode As Long dwServiceSpecificExitCode As Long dwCheckPoint As Long dwWaitHint As LongEnd TypePrivate Type ENUM_SERVICE_STATUS ‘ 36 bytes lpServiceName As Long lpDisplayName As Long ServiceStatus As SERVICE_STATUSEnd TypeConst SERVICE_ACTIVE = &H1&Const SERVICE_INACTIVE = &H2&Const

GetProcessesInfo – Retrieve information on active processes

Private Const TH32CS_SNAPPROCESS As Long = 2&Private Const MAX_PATH As Integer = 260Private Type PROCESSENTRY32 dwSize As Long cntUsage As Long th32ProcessID As Long th32DefaultHeapID As Long th32ModuleID As Long cntThreads As Long th32ParentProcessID As Long pcPriClassBase As Long dwFlags As Long szExeFile As String * MAX_PATHEnd TypePrivate Declare Function

LogOffUser – Shut down the current user session

Const EWX_LOGOFF = 0Const EWX_FORCE = 4Private Declare Function ExitWindowsEx Lib “user32” (ByVal dwOptions As Long, _ ByVal dwReserved As Long) As Long’ close all applications and log off the current user’ if Force is True, no message is sent to applicationsSub LogOffUser(Optional ByVal Force As Boolean) Dim flags As

KillProcess – Terminate any application

Private Type LUID lowpart As Long highpart As LongEnd TypePrivate Type TOKEN_PRIVILEGES PrivilegeCount As Long LuidUDT As LUID Attributes As LongEnd TypeConst TOKEN_ADJUST_PRIVILEGES = &H20Const TOKEN_QUERY = &H8Const SE_PRIVILEGE_ENABLED = &H2Const PROCESS_ALL_ACCESS = &H1F0FFFPrivate Declare Function GetVersion Lib “kernel32” () As LongPrivate Declare Function GetCurrentProcess Lib “kernel32” () As LongPrivate

ShutDownWindows – Shut down and reboot the operating system

Private Type LUID LowPart As Long HighPart As LongEnd TypePrivate Type TOKEN_PRIVILEGES PrivilegeCount As Long LuidUDT As LUID Attributes As LongEnd TypeConst TOKEN_ADJUST_PRIVILEGES = &H20Const TOKEN_QUERY = &H8Const SE_PRIVILEGE_ENABLED = &H2Const EWX_SHUTDOWN = 1Const EWX_REBOOT = 2Const EWX_FORCE = 4Private Declare Function GetVersion Lib “kernel32” () As LongPrivate Declare Function