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 :

Rechercher logiciel depuis une textBox


Sujet :

Scripts/Batch

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    52
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2010
    Messages : 52
    Par défaut Rechercher logiciel depuis une textBox
    Bonjour à tous,

    Alors actuellement, je développe une petite application graphique pour rechercher la liste des logiciel installé sur un PC en local.

    J'en suis à la 2ème partie (recherche de logiciel individuellement) j'ai donc penser à une texte box ou l'on tape le nom d'un logiciel ou un mot clé, on valide par le biais d'un bouton et ensuite mon script va chercher dans hklm:\software\microsoft\windows\currentversion\uninstall si il trouve quelque chose en rapport avec la recherche et balance le résultat dans un fichier .docx

    Le problème est que je ne sais pas comment y parvenir, pour ce qui est de l'envoi du résultat dans un .docx je me contente d'un .txt de votre part je ferai la conversion une fois que je saurais comment faire. Quelqu'un pourrait m'aide svp? ^^

    Merci

  2. #2
    Rédacteur


    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7 171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7 171
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par Unfam0us Voir le message
    on valide par le biais d'un bouton et ensuite mon script va chercher dans hklm:\software\microsoft\windows\currentversion\uninstall
    Tu devrais plutot lire une seule fois la registry et afficher la liste, ensuite tu ajoutes un second bouton "Relire la registry" ou qq comme ça.

    Citation Envoyé par Unfam0us Voir le message
    Le problème est que je ne sais pas comment y parvenir
    Je n'ai pas compris ta question, peux-tu préciser ton problème ?

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    52
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2010
    Messages : 52
    Par défaut
    Hello,

    Dsl mais je ne comprend pas ce que tu propose

    Pour être plus précis voilà mon script:

    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
    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
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    [void][Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
    [void][Reflection.Assembly]::LoadWithPartialname("System.Drawing")
    [void][Reflection.Assembly]::LoadWithPartialname("System.Single")
    
    $label_principal = New-Object System.Windows.Forms.Label
    $label_txtBox = New-Object System.Windows.Forms.Label
    $label_valid = New-Object System.Windows.Forms.Label
    $groupBox1 = New-Object System.Windows.Forms.Groupbox
    $groupBox2 = New-Object System.Windows.Forms.Groupbox
    $button_grpBox1 = New-Object System.Windows.Forms.Button
    $button_grpBox2 = New-Object System.Windows.Forms.Button
    $textBox1 = New-Object System.Windows.Forms.TextBox
    
    
    # Label de titre
    #$label_principal.AutoSize = $true;
    #$label_principal.Size = New-Object System.Drawing.Font.Size(18)
    $label_principal.Location = New-Object System.Drawing.Point(10, 10)
    $label_principal.Name = 'label_principal'
    $label_principal.Text = 'Recherche de logiciel'
    
    
    # Rechercher tous les logiciels
        # groupBox1
        $groupBox1.Size = New-Object System.Drawing.Size(400, 100)
        $groupBox1.Text = "Rechercher tous les logiciels intallés"
        $groupBox1.Location = New-Object System.Drawing.Point(35, 40)
        #$groupBox1.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
        $groupBox1.TabStop = $False
        $groupBox1.Name = "groupBox1"
    
        # bouton dans groupBox1
        $button_grpBox1.Name = "button_grpBox"
        $System_Drawing_Size = New-Object System.Drawing.Size
        $System_Drawing_Size.Width = 150
        $System_Drawing_Size.Height = 30
        $button_grpBox1.Size = $System_Drawing_Size
        $button_grpBox1.Text = "Rechercher"
        $System_Drawing_Point = New-Object System.Drawing.Point
        $System_Drawing_Point.X = 120
        $System_Drawing_Point.Y = 30
        $button_grpBox1.Location = $System_Drawing_Point
        $groupBox1.Controls.Add($button_grpBox1)
        
        # Lors d'un clique sur le bouton "Rechercher"
        $button_grpBox1.Add_Click({
            $word = new-object -com word.application
            $word.visible = $true
            $doc = $word.documents.add()
            $texte =  gp HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Format-List DisplayName, DisplayVersion, Publisher | out-string -width 120
            $doc.content.text = $texte
            $doc.content.font.name = "Calibri"
            $doc.content.font.size = 10
            # $env:computername définit le nom de l'ordinateur local (ne fonctionne qu'en local)
            $doc.saveas([ref]"D:\Controle logiciel sur $env:computername.docx")
            $label_valid.Text = 'Enregistrer dans D:\Controle logiciel sur NomDuPC'     
        })
        
        # Label de confirmation d'enregistrement du fichier (A placer après l'événement Add_Click)
        $label_valid.AutoSize = $true;
        $label_principal.Size = New-Object System.Drawing.Size(70, 180)
        $label_valid.Location = New-Object System.Drawing.Point(70, 70)
        $label_valid.Name = 'label_valid'
        $label_valid.set_ForeColor("Green")
        $groupBox1.Controls.Add($label_valid)
        
    #Rechercher par logiciel
        # groupBox2
        $System_Drawing_Size = New-Object System.Drawing.Size
        $System_Drawing_Size.Width = 400
        $System_Drawing_Size.Height = 200
        $groupBox2.Size = $System_Drawing_Size
        $groupBox2.Text = "Rechercher un logiciel en particulier"
        $System_Drawing_Point = New-Object System.Drawing.Point
        $System_Drawing_Point.X = 35
        $System_Drawing_Point.Y = 150
        $groupBox2.Location = $System_Drawing_Point
        #$groupBox2.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
        $groupBox2.TabStop = $False
        $groupBox2.Name = "groupBox2"
    
        # Label pour textBox1
        $label_txtBox.AutoSize = $true;
        $label_txtBox.Location = New-Object System.Drawing.Point(60, 60)
        $label_txtBox.Name = 'label_txtBox'
        $label_txtBox.Text = 'Entrez le nom du logiciel'
        $groupBox2.Controls.Add($label_txtBox)
    
        # textBox1
        $textBox1.AutoSize = $true;
        $textBox1.Name = "textBox1"
        $textBox1.Location = New-Object System.Drawing.Point(215, 58)
        $groupBox2.Controls.Add($textBox1)
        
        # bouton dans groupBox2
        $button_grpBox2.Name = "button_grpBox2"
        $System_Drawing_Size = New-Object System.Drawing.Size
        $System_Drawing_Size.Width = 150
        $System_Drawing_Size.Height = 30
        $button_grpBox2.Size = $System_Drawing_Size
        $button_grpBox2.Text = "Rechercher"
        $System_Drawing_Point = New-Object System.Drawing.Point
        $System_Drawing_Point.X = 120
        $System_Drawing_Point.Y = 90
        $button_grpBox2.Location = $System_Drawing_Point
        $groupBox2.Controls.Add($button_grpBox2)
    
        # Lors d'un clique sur le bouton "Rechercher"
        $button_grpBox2.Add_Click({
            # Depuis le mot tapé dans le textBox1 on va rechercher dans le document
            #Get-Childitem "D:\Controle logiciel sur $env:computername.docx" -recurse | where {$_.DisplayName -eq "$textBox1"}
            
            # Depuis le mot tapé dans le textBox1 on va rechercher dans le registre
            #gp "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" | where {$_.DisplayName -eq "$textBox1"} | Out-File -FilePath D:\test2.txt
            Get-ChildItem hklm:\software\microsoft\windows\currentversion\uninstall | ForEach-Object {Get-ItemProperty $_.pspath} | Out-File -FilePath D:\test2.txt
    
    
        })
    
    
    # Form
    $Form1 = New-Object System.Windows.Forms.form
    $Form1.ClientSize = New-Object System.Drawing.Size(475, 400)
    $Form1.Controls.Add($label_principal)
    $Form1.Controls.Add($groupbox1)
    $Form1.Controls.Add($groupbox2)
    $Form1.Name = 'Form1'
    $Form1.Text = 'Recherche de logiciel'
    $Form1.ShowDialog()
    A la seconde ligne surligné en rouge c'est le control de mon bouton, j'ai fais 2-3 essais mais je ne vois pas trop comment faire, je demande donc un petit conseil

  4. #4
    Rédacteur


    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7 171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7 171
    Billets dans le blog
    1
    Par défaut
    Essaie ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
        $button_grpBox2.Add_Click({
            # Depuis le mot tapé dans le textBox1 on va rechercher dans le document
            #Get-Childitem "D:\Controle logiciel sur $env:computername.docx" -recurse | 
            # where {$_.DisplayName -eq "$textBox1"}
     
            # Depuis le mot tapé dans le textBox1 on va rechercher dans le registre
            #gp "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" | where {$_.DisplayName -eq "$textBox1"} | Out-File -FilePath D:\test2.txt
            push-location
            cd "hklm:\software\microsoft\windows\currentversion\uninstall\$($textBox1.Text)"  
            Get-ItemProperty $pwd | 
             Out-File -FilePath C:\temp\test2.txt
            pop-location         
        })
    Si je peux permettre un conseil, tu devrais prendre l'habitude de paramètrer tes traitements (utiliser des variables et des constantes), et aussi découpler la création d'objets de leurs présentation.
    Là, tout est dans tout, ce n'est pas franchement aisé à relire :/

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    52
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2010
    Messages : 52
    Par défaut
    Merci pour ton code mais voilà ce qu'il me retourne:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    Get-ItemProperty : Impossible de trouver le chemin d'accès «*HKLM:\software\mic
    rosoft\windows\currentversion\uninstall\Adobe*», car il n'existe pas.

  6. #6
    Rédacteur


    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7 171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7 171
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par Unfam0us Voir le message
    Merci pour ton code mais voilà ce qu'il me retourne:
    Je n'ai pas indiqué de joker dans mon exemple, de plus tu dois contrôler si le nom de clé saisie existe.

Discussions similaires

  1. Calculer depuis une textbox
    Par Lekno dans le forum VB.NET
    Réponses: 10
    Dernier message: 13/08/2014, 18h18
  2. [Débutant] Activer un timer "x" fois depuis une textbox.
    Par dragonmouff123 dans le forum VB.NET
    Réponses: 5
    Dernier message: 25/05/2013, 12h14
  3. Réponses: 2
    Dernier message: 04/09/2007, 13h53
  4. [vba excel] Recherche valeur d'une textbox dans une feuille
    Par vanessaferraz dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 10/08/2006, 10h55
  5. [C++.NET] Extraction de nombres depuis une TextBox
    Par KaeRZed dans le forum VC++ .NET
    Réponses: 4
    Dernier message: 19/04/2006, 13h57

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