我正在使用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
答案 0 :(得分:1)
此命令可以解决问题:
WMIC service where "Not PathName like '%Micro%' AND Not PathName like '%Windows%'" get Name,DisplayName,PathName,State,Status
您也可以使用Powershell脚本来实现它:
在How to filter Microsoft Service using PowerShell?处参考此答案。
您可以使用powershell脚本过滤 非Microsoft服务 :
$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的屏幕截图: