1
1
Option Explicit On
2
- Imports System.Data
3
- Imports System.Data.OleDb
4
2
5
3
Public Class frmMain
6
4
7
- Private Declare Function WTSRegisterSessionNotification Lib "Wtsapi32" ( ByVal hWnd As IntPtr, ByVal THISSESS As Long ) As Long
8
- Private Declare Function WTSUnRegisterSessionNotification Lib "Wtsapi32" ( ByVal hWnd As IntPtr) As Long
9
-
10
- Private Const NOTIFY_FOR_ALL_SESSIONS As Integer = 1
11
- Private Const NOTIFY_FOR_THIS_SESSION As Integer = 0
12
- Private Const WM_WTSSESSION_CHANGE As Integer = &H2B1
13
-
14
- Private Enum WTS
15
- CONSOLE_CONNECT = 1
16
- CONSOLE_DISCONNECT = 2
17
- REMOTE_CONNECT = 3
18
- REMOTE_DISCONNECT = 4
19
- SESSION_LOGON = 5
20
- SESSION_LOGOFF = 6
21
- SESSION_LOCK = 7
22
- SESSION_UNLOCK = 8
23
- SESSION_REMOTE_CONTROL = 9
24
- End Enum
25
-
26
5
Private Sub tmrMinute_Tick( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMinute.Tick
27
6
logStatus()
28
7
End Sub
@@ -50,50 +29,8 @@ Public Class frmMain
50
29
initAppLaunchTime()
51
30
End Sub
52
31
53
- Protected Overrides Sub WndProc( ByRef m As System.Windows.Forms.Message)
54
- Dim newEntry As ListViewItem
55
-
56
- Select Case m.Msg
57
- Case WM_WTSSESSION_CHANGE
58
- Select Case m.WParam.ToInt32
59
- Case WTS.CONSOLE_CONNECT
60
- 'Debug.Print("A session was connected to the console session.")
61
- Case WTS.CONSOLE_DISCONNECT
62
- 'Debug.Print("A session was disconnected from the console session.")
63
- Case WTS.REMOTE_CONNECT
64
- 'Debug.Print("A session was connected to the remote session.")
65
- Case WTS.REMOTE_DISCONNECT
66
- 'Debug.Print("A session was disconnected from the remote session.")
67
- Case WTS.SESSION_LOGON
68
- 'Debug.Print("A user has logged on to the session.")
69
- Case WTS.SESSION_LOGOFF
70
- 'Debug.Print("A user has logged off the session.")
71
- Case WTS.SESSION_LOCK
72
- 'Debug.Print("A session has been locked.")
73
- ' Populate the listview with Windows locked entry
74
- newEntry = lvEntries.Items.Insert( 0 , "-1" )
75
- newEntry.SubItems.Add( "Microsoft" )
76
- newEntry.SubItems.Add( "Windows" )
77
- newEntry.SubItems.Add( "Locked" )
78
- newEntry.SubItems.Add(Format(Now, "yyyy/MM/dd HH:mm:ss" ))
79
- Case WTS.SESSION_UNLOCK
80
- 'Debug.Print("A session has been unlocked.")
81
- ' Populate the listview with Windows locked entry
82
- newEntry = lvEntries.Items.Insert( 0 , "-1" )
83
- newEntry.SubItems.Add( "Microsoft" )
84
- newEntry.SubItems.Add( "Windows" )
85
- newEntry.SubItems.Add( "Unlocked" )
86
- newEntry.SubItems.Add(Format(Now, "yyyy/MM/dd HH:mm:ss" ))
87
- Case WTS.SESSION_REMOTE_CONTROL
88
- 'Debug.Print("A session has changed its remote controlled status. To determine the status, call GetSystemMetrics and check the SM_REMOTECONTROL metric.")
89
- End Select
90
- End Select
91
-
92
- MyBase .WndProc(m)
93
-
94
- End Sub
95
32
96
- Private Sub Form1_FormClosing (ByVal sender As Object , ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me .FormClosing
33
+ Private Sub frmMain_FormClosing (ByVal sender As Object , ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me .FormClosing
97
34
WTSUnRegisterSessionNotification( Me .Handle)
98
35
End Sub
99
36
@@ -139,8 +76,9 @@ Public Class frmMain
139
76
.FilterIndex = 0 , _
140
77
.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)}
141
78
142
- 'show the dialog + display the results in a msgbox unless cancelled
143
-
79
+ '****************************************************************
80
+ ' show the dialog + export window log unless cancelled
81
+ '****************************************************************
144
82
If sfd.ShowDialog = DialogResult.OK Then
145
83
146
84
Dim headers = ( From ch In lvEntries.Columns _
@@ -160,7 +98,7 @@ Public Class frmMain
160
98
161
99
table = table.TrimEnd( CChar (vbCr), CChar (vbLf))
162
100
163
- ' Add retry/abort here in case file write fails (eg. if file open in other app)
101
+ ' TODO: Issue#11: Add retry/abort here in case file write fails (eg. if file open in other app)
164
102
IO.File.WriteAllText(sfd.FileName, table)
165
103
166
104
End If
@@ -175,4 +113,5 @@ Public Class frmMain
175
113
Private Sub AboutToolStripMenuItem_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
176
114
frmAbout.ShowDialog()
177
115
End Sub
116
+
178
117
End Class
0 commit comments