Отфильтруйте службу Microsoft из команды `wmic service get` - PullRequest
1 голос
/ 30 октября 2019

Я использую wmic для перечисления установленных служб:

wmic service get

Можно ли скрыть от него службу Microsoft?

Запрос возвращает следующие поля, ни одно из которых не представляется полезным:

AcceptPause AcceptStop Caption CheckPoint CreationClassName Description DesktopInteract DisplayName ErrorControl ExitCode InstallDate Name PathName ProcessId ServiceSpecificExitCode ServiceType Started StartMode StartName State Status SystemCreationClassName SystemName TagId WaitHint

1 Ответ

1 голос
/ 31 октября 2019

Эта команда может помочь:

WMIC service where "Not PathName like '%Micro%' AND Not PathName like '%Windows%'" get Name,DisplayName,PathName,State,Status

И вы можете сделать это также с помощью скрипта Powershell:

См. Этот ответ здесь Как отфильтровать службы Microsoft с помощью PowerShell? .

Вы можете отфильтровать службы сторонних разработчиков с помощью сценария powershell:

$services = Get-WmiObject Win32_Service -Property Name,DisplayName,PathName | Select Name, DisplayName,PathName
$serviceList = New-Object System.Collections.ArrayList
foreach ($service in $services) {
  Try {
    $path = $service.Pathname.tostring().replace('"','')
    $cri = ([System.Diagnostics.FileVersionInfo]::GetVersionInfo($path)).legalcopyright
    if ($cri -notlike "*Microsoft*") {
      $serviceList += $service
    }
  } catch {}
}
$serviceList

Редактировать: 02/11/2019 Версия Vbscript

Вот еще одна версия, использующая vbscript для экспорта результатов вывода в Excel.

Просто скопируйте и вставьте этот кодниже как Non-Microsoft-Services.vbs и выполните его двойным щелчком мыши.

Option Explicit
' Non-Microsoft-Services.vbs
Dim objExcel,strComputer,objWMIService
Dim State,colServices,x,objService,objWorksheet,objWorkbook
' Create a new and blank spreadsheet:
Set objExcel = CreateObject("Excel.Application")
Set objWorkBook = objExcel.WorkBooks.Add
objExcel.Visible = True

Set objWorksheet = objWorkbook.Worksheets(1)
objWorksheet.Name = "Services Non-Microsoft"
objWorksheet.Tab.ColorIndex = 3

' Format the cell A1 and add the text: Service Name
objExcel.Cells(1, 1).Value = "Service Name"
objExcel.Cells(1, 1).Font.Bold = TRUE
objExcel.Cells(1, 1).Interior.ColorIndex = 43
objExcel.Cells(1, 1).Font.ColorIndex = 2
' Format the cell A2 and add the text: Display Name
objExcel.Cells(1, 2).Value = "Display Name"
objExcel.Cells(1, 2).Font.Bold = TRUE
objExcel.Cells(1, 2).Interior.ColorIndex = 43
objExcel.Cells(1, 2).Font.ColorIndex = 2
'*************************************************
' Format the cell A3 and add the text: State
objExcel.Cells(1, 3).Value = "State"
objExcel.Cells(1, 3).Font.Bold = TRUE
objExcel.Cells(1, 3).Interior.ColorIndex = 43
objExcel.Cells(1, 3).Font.ColorIndex = 2
'*************************************************
' Format the cell A4 and add the text: Executable Path
objExcel.Cells(1, 4).Value = "Executable Path"
objExcel.Cells(1, 4).Font.Bold = TRUE
objExcel.Cells(1, 4).Interior.ColorIndex = 43
objExcel.Cells(1, 4).Font.ColorIndex = 2
'*************************************************
' Format the cell A5 and add the text: Description
objExcel.Cells(1, 5).Value = "Description"
objExcel.Cells(1, 5).Font.Bold = TRUE
objExcel.Cells(1, 5).Interior.ColorIndex = 43
objExcel.Cells(1, 5).Font.ColorIndex = 2
' Find the Non-Microsoft Windows services on this computer
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService.ExecQuery("Select * From Win32_Service where Not PathName like '%Micro%' AND Not PathName like '%Windows%'")
' Write each service to Excel, starting in A2
x = 1
For Each objService in colServices
    x = x + 1
    objExcel.Cells(x, 1) = objService.Name
    objExcel.Cells(x, 2) = objService.DisplayName
    objExcel.Cells(x, 3) = objService.State
    objExcel.Cells(x, 4) = objService.PathName
    objExcel.Cells(x, 5) = objService.Description
    State = objService.Started
    If State Then 
        Cellule x,3,"Running"
        objExcel.Cells(x, 1).Font.ColorIndex = 10
        objExcel.Cells(x, 2).Font.ColorIndex = 10
        objExcel.Cells(x, 3).Font.ColorIndex = 10
        objExcel.Cells(x, 4).Font.ColorIndex = 10
        objExcel.Cells(x, 5).Font.ColorIndex = 10
    ELSE
        Cellule X,3,"Stopped"
        objExcel.Cells(x, 1).Font.ColorIndex = 3
        objExcel.Cells(x, 2).Font.ColorIndex = 3
        objExcel.Cells(x, 3).Font.ColorIndex = 3
        objExcel.Cells(x, 4).Font.ColorIndex = 3
        objExcel.Cells(x, 5).Font.ColorIndex = 3
    end if
Next

objExcel.Columns("A:A").EntireColumn.AutoFit
objExcel.Columns("B:B").EntireColumn.AutoFit
objExcel.Columns("C:C").EntireColumn.AutoFit
objExcel.Columns("D:D").EntireColumn.AutoFit
objExcel.Columns("E:E").EntireColumn.AutoFit

Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
Dim Network : Set Network = CreateObject("WScript.Network")
Dim Computer : Computer = Network.ComputerName
Dim xlVer,objXL
Set objXL = CreateObject("Excel.Application") 
' Check Excel Version (12.0 = 2007)
xlVer = Split(objXL.Version,".")(0) 
If xlVer >= "12" Then
    objExcel.ActiveWorkbook.SaveAs fso.GetAbsolutePathName(".") & "\Non-Microsoft-Services_" & Computer & ".xlsx"
    objExcel.DisplayAlerts = True
' 56 = Excel 97-2003
' Voir la page http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.xlfileformat.aspx
Else
    objExcel.ActiveWorkbook.SaveAs fso.GetAbsolutePathName(".") & "\Non-Microsoft-Services_" & Computer & ".xls",56
    objExcel.DisplayAlerts = True
End If
'--------------------------------------------------------------------
Sub Cellule(X,NC,chaine)
    objExcel.Cells(X,NC).Value = Chaine
End Sub
'--------------------------------------------------------------------
'Function to determine the current directory
Function GetPath()
    Dim path
    path = WScript.ScriptFullName
    GetPath = Left(path, InStrRev(path, "\"))
End Function
'--------------------------------------------------------------------

Вот скриншот, который я получил в результате этого vbscript:

enter image description here

...