IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Scripts/Batch Discussion :

Comment filtrer tous les services Non-Microsoft avec WMIC et rediriger le résultat dans un fichier texte ? [Batch]


Sujet :

Scripts/Batch

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Expert confirmé
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 844
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 844
    Par défaut Comment filtrer tous les services Non-Microsoft avec WMIC et rediriger le résultat dans un fichier texte ?

    WMIC service where "Not PathName like '%Micro%' AND Not PathName like '%Windows%'" get Name, DisplayName, PathName, Status
    Donc cette commande marche chez moi 5/5 sur la console mais le problème c'est quand je veux rediriger le résultat dans un fichier texte, j'obtiens tous les instances sans aucun filtre ? alors que je vois bien dans la console la commande me donne bien le résultat attendu avec le filtre ?

  2. #2
    Expert confirmé
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 844
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 844
    Par défaut

    J'ai oublié d'ajouter le pourcentage % , donc avec un fichier batch fonctionne 5/5
    Donc Problème
    Code BAT : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    @echo off
    WMIC service where "Not PathName like '%%Micro%%' AND Not PathName like '%%Windows%%'" get Name, DisplayName, PathName, Status >"%computername%.txt"
    Start "" "%computername%.txt"
    pause & exit

    J'obtiens un résultat comme celui-là :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    DisplayName                         Name                          PathName                                                                               Status  
    Agent                               Agent                         "C:\Users\Hackoo\Downloads\Compressed\AgentSetup\%ProgramFiles(x86)%\Agent\Agent.exe"  OK      
    Disc Soft Lite Bus Service          Disc Soft Lite Bus Service    "C:\Program Files\DAEMON Tools Lite\DiscSoftBusServiceLite.exe"                        OK      
    ESET HTTP Server                    EHttpSrv                      "C:\Program Files\ESET\ESET Endpoint Security\ehttpsrv.exe"                            OK      
    ESET Service                        ekrn                          "C:\Program Files\ESET\ESET Endpoint Security\ekrn.exe"                                OK      
    ESET SHA Service                    eshasrv                       "C:\Program Files\ESET\ESET Endpoint Security\eshasrv.exe"                             OK      
    Foxit Reader Service                FoxitReaderService            "C:\Program Files\Foxit Software\Foxit Reader\FoxitConnectedPDFService.exe"            OK      
    Google Chrome Elevation Service     GoogleChromeElevationService  "C:\Program Files\Google\Chrome\Application\77.0.3865.120\elevation_service.exe"       OK      
    Service Google Update (gupdate)     gupdate                       "C:\Program Files\Google\Update\GoogleUpdate.exe" /svc                                 OK      
    Service Google Update (gupdatem)    gupdatem                      "C:\Program Files\Google\Update\GoogleUpdate.exe" /medsvc                              OK      
    HMA! Pro VPN                        HmaProVpn                     "C:\Program Files\HMA! Pro VPN\VpnSvc.exe"                                             OK      
    HuaweiHiSuiteService.exe            HuaweiHiSuiteService.exe      "C:\Program Files\HiSuite\HandSetService\HuaweiHiSuiteService.exe" -/service           OK      
    IObit Uninstaller Service           IObitUnSvr                    C:\Program Files\IObit\IObit Uninstaller\IUService.exe                                 OK      
    Ivideon Video Surveillance Service  ivideon_video_service         "C:\Program Files\Ivideon\IvideonServer\videoserver.exe" --service run                 OK      
    Malware Defender Service            MalwareDefenderService        c:\program files\malware defender\mdservice.exe                                        OK      
    Mozilla Maintenance Service         MozillaMaintenance            "C:\Program Files\Mozilla Maintenance Service\maintenanceservice.exe"                  OK      
    QFX Software Update Service         QFXUpdateService              C:\Program Files\KeyScrambler\QFXUpdateService.exe                                     OK      
    Sandboxie Service                   SbieSvc                       "C:\Program Files\Sandboxie\SbieSvc.exe"                                               OK      
    Windows Remediation Service         sedsvc                        "C:\Program Files\rempl\sedsvc.exe"                                                    OK      
    SynTPEnh Caller Service             SynTPEnhService               "C:\Program Files\Synaptics\SynTP\SynTPEnhService.exe"                                 OK      
    System Explorer Service             SystemExplorerHelpService     C:\Program Files\System Explorer\service\SystemExplorerService.exe                     OK

  3. #3
    Expert confirmé
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 844
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 844
    Par défaut

    Voici une version en vbscript Non-Microsoft-Services.vbs avec exportation du résultat dans un fichier Excel
    Code VB : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    Option Explicit
    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
    '--------------------------------------------------------------------

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [LibreOffice][Tableur] CreateUnoService marche -t-il avec tous les services ?
    Par molo2003 dans le forum OpenOffice & LibreOffice
    Réponses: 2
    Dernier message: 17/08/2017, 11h48
  2. Réponses: 12
    Dernier message: 13/07/2011, 08h35
  3. Réponses: 2
    Dernier message: 14/02/2010, 19h30
  4. [Tomcat] Comment supprimer tous les logs ?
    Par Soulsurfer dans le forum Tomcat et TomEE
    Réponses: 8
    Dernier message: 11/05/2004, 16h35
  5. Réponses: 4
    Dernier message: 16/08/2003, 13h21

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo