-
Notifications
You must be signed in to change notification settings - Fork 0
/
Service Control frmMain.vb
executable file
·280 lines (247 loc) · 12.7 KB
/
Service Control frmMain.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
Public Class frmMain 'Were things really better back in the day? I seem to
Inherits System.Windows.Forms.Form 'not be able to let go of the past, tend
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Friend WithEvents tabMain As System.Windows.Forms.TabControl
Friend WithEvents tbpServices As System.Windows.Forms.TabPage
Friend WithEvents lvwServices As System.Windows.Forms.ListView
Friend WithEvents lchCaptions As System.Windows.Forms.ColumnHeader
Friend WithEvents lchNames As System.Windows.Forms.ColumnHeader
Friend WithEvents lchState As System.Windows.Forms.ColumnHeader
Friend WithEvents cmdStop As System.Windows.Forms.Button
Friend WithEvents cmdStart As System.Windows.Forms.Button
Friend WithEvents cmdExit As System.Windows.Forms.Button
Friend WithEvents cmdRefresh As System.Windows.Forms.Button
Friend WithEvents lnk As System.Windows.Forms.LinkLabel
Private components As System.ComponentModel.IContainer
'Required by the Windows Form Designer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.cmdExit = New System.Windows.Forms.Button()
Me.cmdStop = New System.Windows.Forms.Button()
Me.lchState = New System.Windows.Forms.ColumnHeader()
Me.cmdStart = New System.Windows.Forms.Button()
Me.tbpServices = New System.Windows.Forms.TabPage()
Me.cmdRefresh = New System.Windows.Forms.Button()
Me.lvwServices = New System.Windows.Forms.ListView()
Me.lchCaptions = New System.Windows.Forms.ColumnHeader()
Me.lchNames = New System.Windows.Forms.ColumnHeader()
Me.tabMain = New System.Windows.Forms.TabControl()
Me.lnk = New System.Windows.Forms.LinkLabel()
Me.tbpServices.SuspendLayout()
Me.tabMain.SuspendLayout()
Me.SuspendLayout()
'
'cmdExit
'
Me.cmdExit.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.cmdExit.Location = New System.Drawing.Point(376, 296)
Me.cmdExit.Name = "cmdExit"
Me.cmdExit.Size = New System.Drawing.Size(76, 24)
Me.cmdExit.TabIndex = 1
Me.cmdExit.Text = "Exit"
'
'cmdStop
'
Me.cmdStop.Enabled = False
Me.cmdStop.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.cmdStop.Location = New System.Drawing.Point(260, 232)
Me.cmdStop.Name = "cmdStop"
Me.cmdStop.Size = New System.Drawing.Size(84, 24)
Me.cmdStop.TabIndex = 1
Me.cmdStop.Text = "Stop Service"
'
'lchState
'
Me.lchState.Text = "State"
Me.lchState.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
Me.lchState.Width = 100
'
'cmdStart
'
Me.cmdStart.Enabled = False
Me.cmdStart.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.cmdStart.Location = New System.Drawing.Point(348, 232)
Me.cmdStart.Name = "cmdStart"
Me.cmdStart.Size = New System.Drawing.Size(84, 24)
Me.cmdStart.TabIndex = 1
Me.cmdStart.Text = "Start Service"
'
'tbpServices
'
Me.tbpServices.Controls.AddRange(New System.Windows.Forms.Control() {Me.lnk, Me.cmdRefresh, Me.cmdStart, Me.cmdStop, Me.lvwServices})
Me.tbpServices.Location = New System.Drawing.Point(4, 22)
Me.tbpServices.Name = "tbpServices"
Me.tbpServices.Size = New System.Drawing.Size(440, 262)
Me.tbpServices.TabIndex = 0
Me.tbpServices.Text = "Windows Services"
'
'cmdRefresh
'
Me.cmdRefresh.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.cmdRefresh.Location = New System.Drawing.Point(156, 232)
Me.cmdRefresh.Name = "cmdRefresh"
Me.cmdRefresh.Size = New System.Drawing.Size(84, 24)
Me.cmdRefresh.TabIndex = 1
Me.cmdRefresh.Text = "Refresh"
'
'lvwServices
'
Me.lvwServices.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.lchCaptions, Me.lchNames, Me.lchState})
Me.lvwServices.FullRowSelect = True
Me.lvwServices.GridLines = True
Me.lvwServices.Location = New System.Drawing.Point(8, 8)
Me.lvwServices.Name = "lvwServices"
Me.lvwServices.Size = New System.Drawing.Size(424, 220)
Me.lvwServices.TabIndex = 0
Me.lvwServices.View = System.Windows.Forms.View.Details
'
'lchCaptions
'
Me.lchCaptions.Text = "Service"
Me.lchCaptions.Width = 200
'
'lchNames
'
Me.lchNames.Text = "Real Names"
Me.lchNames.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
Me.lchNames.Width = 100
'
'tabMain
'
Me.tabMain.Controls.AddRange(New System.Windows.Forms.Control() {Me.tbpServices})
Me.tabMain.Location = New System.Drawing.Point(4, 4)
Me.tabMain.Name = "tabMain"
Me.tabMain.SelectedIndex = 0
Me.tabMain.Size = New System.Drawing.Size(448, 288)
Me.tabMain.TabIndex = 0
'
'lnk
'
Me.lnk.Location = New System.Drawing.Point(12, 236)
Me.lnk.Name = "lnk"
Me.lnk.Size = New System.Drawing.Size(144, 16)
Me.lnk.TabIndex = 2
Me.lnk.TabStop = True
Me.lnk.Text = "jBistoGOOD@Hotmail.com"
'
'frmMain
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(456, 323)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.cmdExit, Me.tabMain})
Me.Name = "frmMain"
Me.Text = "Windows Services Control - tHe_cLeanER productions..."
Me.tbpServices.ResumeLayout(False)
Me.tabMain.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region 'to revel on previous experiences, just because it is ... comfortable.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call ReadSvcs() '... as pathetic as a middle-aged
End Sub 'corporate drone watching tapes
Sub ReadSvcs() 'of his old football
Dim ListSvcs() As ServiceProcess.ServiceController 'games from back in the day,
Dim SingleSvc As ServiceProcess.ServiceController 'when "your mother and I were dating." But the
Dim LVW As ListViewItem 'warm fuzzy of nostalgia,
ListSvcs = SingleSvc.GetServices 'knowing that yes, you accomplished something, makes the world
lvwServices.Items.Clear() 'feel a bit easier to deal with, and
Try 'eventual death acceptable, almost as though we
For Each SingleSvc In ListSvcs 'have made
LVW = lvwServices.Items.Add(SingleSvc.DisplayName) 'indelible marks upon the history of whatever.
LVW.SubItems.Add(SingleSvc.ServiceName) 'But a sigh usually caps off the standard cock-
LVW.SubItems.Add(SingleSvc.Status.ToString) 'stroking session of the BBS-days bullshit, when we had
LVW.SubItems.Add(SingleSvc.ServiceType.ToString) 'only 32 baud modems. Maybe it's that I need to know
Next 'how little I knew, how young I was, to re-
Catch e As Exception 'assure myself of the growth that I have (?) experienced,
MessageBox.Show("Could not initialize Windows Service engine. Restarting your computer may work", "Fatal Error: " & e.Source)
End Try 'magic marker lines with my handle and the date, maybe
End Sub 'a dial-in or two on some sort of collective
Private Sub lvwServices_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lvwServices.Click 'parental
If lvwServices.SelectedItems(0).Text <> "" Then 'doorjam belonging to history herself. It could be
Select Case lvwServices.SelectedItems(0).SubItems(2).Text 'a quest for immortality,
Case "Stopped" 'for power -- all expressions of sexual
cmdStop.Enabled = False 'drives -- or maybe a hug for my inner child.
cmdStart.Enabled = True 'But I
Case "Running" 'am not by any means someone who has any clue
cmdStop.Enabled = True 'about
cmdStart.Enabled = False 'anything, other than distilled problems which
Case Else 'can be expressed in purely logical situations, which is
cmdStop.Enabled = False 'almost a moot point when dealing
cmdStart.Enabled = False 'with complex systems such
End Select 'as human interaction.
End If 'Feeling... like a jazz
End Sub 'note on life, thoughts from the crowds,
Private Sub cmdStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStop.Click
If lvwServices.SelectedItems(0).Text <> "" Then 'interacting, loving?
Call StopService(lvwServices.SelectedItems(0).SubItems(1).Text) 'each one special in its own way.
End If 'It has
End Sub 'been said that empathy is what
Sub StopService(ByVal ServiceName As String) 'sets us apart from the
Dim ListSvcs() As ServiceProcess.ServiceController 'animals, but does
Dim SingleSvc As ServiceProcess.ServiceController 'anyone give a
ListSvcs = SingleSvc.GetServices 'rat's ass about other people
Try 'when their own lives are at a
For Each SingleSvc In ListSvcs 'crossroads?
If UCase(SingleSvc.ServiceName) = UCase(ServiceName) Then 'Nihilism.
SingleSvc.Stop() 'The opposite of hippiedom? The cyclical
Call ReadSvcs() 'nature of the thread, which
Exit For 'should just be trashed,
End If 'but that is okay.
Next 'Vibes can be recorded,
Catch e As Exception 'saved, reflected upon,
MessageBox.Show("Could not stop service. Ensure it is not disabled", "Fatal Error: " & e.Source)
End Try 'cherished possibly,
End Sub ' forgotten probably.
Sub StartService(ByVal ServiceName As String) 'but it can be hoped
Dim ListSvcs() As ServiceProcess.ServiceController 'that someone,
Dim SingleSvc As ServiceProcess.ServiceController 'years from now,
ListSvcs = SingleSvc.GetServices ' reads this,
Try
For Each SingleSvc In ListSvcs 'and imagines the
If UCase(SingleSvc.ServiceName) = UCase(ServiceName) Then
SingleSvc.Start() 'the writer,
Call ReadSvcs() 'back in the day,
Exit For 'reminiscing on when the sounds
End If 'and the medium actually meant freedom of thought,
Next ' and,
Catch e As Exception 'possibly, a shot at eternal life.
MessageBox.Show("Could not start service. Ensure it is not disabled", "Fatal Error: " & e.Source)
End Try 'But me? What do I have now that cant be emulated or recreated by technology?
End Sub 'Only my mind
Private Sub cmdStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStart.Click
If lvwServices.SelectedItems(0).Text <> "" Then
Call StartService(lvwServices.SelectedItems(0).SubItems(1).Text)
End If
End Sub
Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
End
End Sub
Private Sub cmdRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRefresh.Click
Call ReadSvcs()
End Sub
Private Sub lnk_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnk.LinkClicked
Try
Shell("explorer mailto:jbistogood@hotmail.com")
Catch
End Try
End Sub
'Something that will never leave me...
End Class
'thanx to Javaman for the comments