Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Use "Win32_Service"
Author:
Gehan Fernando
E-mail:
Click to e-mail author
Submitted:
5/31/2007
Version:
VB 2005
Compatibility:
VB 2005, VB 2008
Category:
Miscellaneous
Views:
14475
Using this code you Can catch windows services in few seconds.
Declarations:
Option Explicit On Imports System Imports System.Management
Code:
Public Class Form1 Private MgClass As New Management.ManagementClass("Win32_Service") Private Sub ButtonLoadServices_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonLoadServices.Click Try Me.Cursor = Cursors.WaitCursor ListView1.Items.Clear() Label3.Text = "" Label5.Text = "" Label7.Text = "" Label9.Text = "" ButtonLoadServices.Enabled = False ButtonLoadServices.Refresh() Label1.Text = "0% Complete." Label1.Refresh() With ProgressBar1 .Value = 0 .Minimum = 0 .Maximum = MgClass.GetInstances().Count .Refresh() End With For Each obj As Management.ManagementObject In MgClass.GetInstances() Application.DoEvents() Dim MHeader As New ListViewItem() Dim SHeader As New ListViewItem.ListViewSubItem() MHeader.Text = obj.GetPropertyValue("Caption").ToString If obj.GetPropertyValue("Description") <> "" Then SHeader.Text = obj.GetPropertyValue("Description").ToString() End If ListView1.Items.Add(MHeader).SubItems.Add(SHeader) ProgressBar1.Value += 1 ProgressBar1.Refresh() Label1.Text = ((ProgressBar1.Value / ProgressBar1.Maximum) * 100).ToString("0.00") & "% Complete." Label1.Refresh() Next ButtonLoadServices.Enabled = True ButtonLoadServices.Refresh() Me.Cursor = Cursors.Default Catch ex As Exception MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) ButtonLoadServices.Enabled = True ButtonLoadServices.Refresh() Me.Cursor = Cursors.Default End Try End Sub Private Sub ListView1_AfterLabelEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LabelEditEventArgs) Handles ListView1.AfterLabelEdit e.CancelEdit = True End Sub Private Sub ListView1_BeforeLabelEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LabelEditEventArgs) Handles ListView1.BeforeLabelEdit e.CancelEdit = True End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Label3.Text = "" Label5.Text = "" Label7.Text = "" Label9.Text = "" End Sub Private Sub ListView1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseClick Dim SelectItem As String = "" Dim SelRow As Integer = 0 Try Me.Cursor = Cursors.WaitCursor SelRow = ListView1.SelectedItems.Item(0).Index SelectItem += """" SelectItem += ListView1.Items.Item(SelRow).Text.ToString() SelectItem += """" Dim SelQuery As New SelectQuery("Win32_Service", "Caption=" & SelectItem & "") Dim ObjectSearcher As New ManagementObjectSearcher(SelQuery) For Each service As ManagementObject In ObjectSearcher.Get() Label3.Text = service.GetPropertyValue("PathName") Label5.Text = service.GetPropertyValue("ServiceType") Label7.Text = service.GetPropertyValue("StartMode") Label9.Text = service.GetPropertyValue("State") Exit For Next SelQuery = Nothing ObjectSearcher.Dispose() Me.Cursor = Cursors.Default Catch ex As Exception MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) Me.Cursor = Cursors.Default End Try End Sub End Class
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement