Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.68 KB | None | 0 0
  1. Imports System.Management
  2. Imports System.ServiceProcess
  3. Public Class StartAndStop
  4.     Dim wmic As ManagementObjectCollection
  5.     Private Sub StartAndStop()
  6.         ' * osppsvc
  7.         ' - Start / Stop
  8.         Dim x As New ServiceController("Office Software Protection Platform")
  9.         If x.Status.Equals(ServiceControllerStatus.Stopped) Or x.Status.Equals(ServiceControllerStatus.StopPending) Then
  10.             x.Start()
  11.         Else
  12.             x.Stop()
  13.         End If
  14.         ' - Enable / Disable
  15.         wmic = New ManagementObjectSearcher("SELECT Name, StartMode FROM Win32_Service WHERE Name LIKE '%osppsvc%'").Get()
  16.         For Each wm As ManagementObject In wmic
  17.             If wm.GetPropertyValue("StartMode") = "Disabled" Then
  18.                 wm.InvokeMethod("ChangeStartMode", {"Automatic"})
  19.             Else
  20.                 wm.InvokeMethod("ChangeStartMode", {"Disabled"})
  21.             End If
  22.         Next
  23.         ' * sppsvc
  24.         ' - Start / Stop
  25.         Dim y As New ServiceController("Software Protection")
  26.         If y.Status.Equals(ServiceControllerStatus.Stopped) Or y.Status.Equals(ServiceControllerStatus.StopPending) Then
  27.             y.Start()
  28.         Else
  29.             y.Stop()
  30.         End If
  31.         ' - Enable / Disable
  32.         wmic = New ManagementObjectSearcher("SELECT Name, StartMode FROM Win32_Service WHERE Name LIKE '%sppsvc%'").Get()
  33.         For Each wm As ManagementObject In wmic
  34.             If wm.GetPropertyValue("StartMode") = "Disabled" Then
  35.                 wm.InvokeMethod("ChangeStartMode", {"Automatic"})
  36.             Else
  37.                 wm.InvokeMethod("ChangeStartMode", {"Disabled"})
  38.             End If
  39.         Next
  40.     End Sub
  41. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement