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

VBScript Discussion :

afficher sur Excel la liste des groupes et comptes de l'ordinateur


Sujet :

VBScript

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    37
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 37
    Points : 28
    Points
    28
    Par défaut afficher sur Excel la liste des groupes et comptes de l'ordinateur
    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
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
     
    ' ----------------------------------------------------------
     
    ' Script VBS d'affichage sous EXCEL de la liste des
     
    ' Permet d'afficher sur EXCEL la liste des groupes et
     
    ' comptes sur une machine locale ou distante
     
    ' ----------------------------------------------------------
     
     
     
    Dim net, computer, args, GUSet, Group, User, GDict,UDict,Members, Groups
     
     
     
    ' Constantes EXCEL
     
    ' ----------------
     
    Const xlDiagonalDown      = 5
     
    Const xlDiagonalUp        = 6
     
    Const xlEdgeLeft          = 7
     
    Const xlEdgeTop           = 8
     
    Const xlEdgeBottom        = 9
     
    Const xlEdgeRight         =10
     
    Const xlContinous         = 1
     
    Const xlThin              = 2
     
    Const xlMedium                     =&HFFFFEFD6
     
    Const xlThick             = 4
     
    Const xlDouble            =&HFFFFEFE9
     
    Const xlAutomatic         =&HFFFFEFF7
     
    Const xlInsideVertical    = 11
     
    Const xlInsideHorizontal  = 12
     
    Const xlNone              =&HFFFFEFD2
     
    Const xlUnderlineStyleNone =&HFFFFEFD2
     
    Const xlCenter            =&HFFFFEFF4
     
    Const xlBottom            =&HFFFFEFF5
     
    Const xlContext            =&HFFFFEC76
     
    Const xlSolid             = 1
     
    Const msoFalse            = 0
     
    Const msoScaleFromTopLeft = 0
     
     
     
    Const xlR1C1              =&HFFFFEFCA
     
     
     
    ' Couleurs EXCEL
     
    ' --------------
     
    Black         =  1
     
    Brown         = 53
     
    OliveGreen    = 52
     
    DarkGreen     = 51
     
    DarkGreenBlue = 49
     
    DarkBlue      = 11
     
    Indigo        = 55
     
    Grey80        = 56
     
     
     
    DarkRed       =  9
     
    Orange        = 46
     
    LightBrown    = 12
     
    Green         = 10
     
    GreenBlue     = 14
     
    Blue          =  5
     
    GrayBlue      = 47
     
    Gray50        = 16
     
     
     
    Red           =  3
     
    LightOrange   = 45
     
    LimeGreen     = 43
     
    MarineGreen   = 50
     
    WaterGreen    = 42
     
    LightBlue     = 41
     
    Violet        = 13
     
    Gray40        = 48
     
     
     
    Pink          =  7
     
    Gold          = 44
     
    Yellow        =  6
     
    BrigthGreen   =  4
     
    Turquoise     =  8
     
    SkyBlue       = 33
     
    Plum          = 54
     
    Grey25        = 15
     
     
     
    SalmonPink    = 38
     
    Brown         = 40
     
    LightYellow   = 36
     
    LightGreen    = 35
     
    LightTurquoise= 34
     
    MediumBlue    = 37
     
    Lavender      = 39
     
    White         =  2
     
     
     
    Set net   =Wscript.CreateObject("WScript.Network")
     
    Set fso   = WScript.CreateObject("Scripting.FileSystemObject")
     
    Set args  =Wscript.Arguments
     
    If args.count=0 Then
     
                computer=net.ComputerName
     
    Else
     
                computer=args(0)
     
                End If
     
     
     
    Set GDict =WScript.CreateObject("Scripting.Dictionary")
     
    Set UDict = WScript.CreateObject("Scripting.Dictionary")
     
     
     
    Set GUset =GetObject("winmgmts:{impersonationLevel=impersonate}!//" &Computer).InstancesOf _
     
                ("Win32_GroupUser")
     
     
     
    for each GU in GUset
     
                setGroup=GetObject("winmgmts:" & GU.GroupComponent)
     
                set User=GetObject("winmgmts:" & GU.PartComponent)
     
                GName=Group.Name
     
                Uname=User.Name
     
                IfGDict.Exists(GName) Then
     
                            OldList=GDict.Item(GName)
     
                            GDict.Item(GName)=OldList& "," & UName
     
                Else
     
                            GDict.AddGName, UName
     
                            EndIf
     
     
     
                IfUDict.Exists(UName) Then
     
                            OldList=UDict.Item(UName)
     
                            UDict.Item(UName)=OldList& "," & GName
     
                Else
     
                            UDict.AddUName, GName
     
                            EndIf
     
                next
     
     
     
    Dim GTabG,GtabU, UTabU, UTabG
     
    GtabG=GDict.Keys
     
    GtabU=GDict.Items
     
    UtabU=UDict.Keys
     
    UtabG=UDict.Items
     
     
     
    Set oXL =WScript.CreateObject("EXCEL.application")
     
    oXL.Visible = True
     
    oXL.Workbooks.Add
     
     
     
    Cellule 1,1,"Liste des Groupes et Comptes de l'ordinateur " & Computer & " le" & FormatDateTime(now, vbLongDate),true,false,12
     
     
     
    NL=3
     
    Cellule NL,2,"GROUPE",true,false,10
     
    Cellule NL,3,"COMPTES DU GROUPE",true,false,10
     
    Color NL,2,NL,3,xlMedium,Grey25
     
    IndexCol=1
     
    For i = 0 To GDict.count-1
     
                Members=Split(GtabU(i),",")
     
                nm=Ubound(Members)
     
                NL=NL+1
     
                NLdeb=NL
     
                CelluleNL,2,GtabG(i),true,false,8
     
                If nm>=0Then
     
                            Forj = 0 To nm
     
                                       Ifj>0 Then NL=NL+1
     
                                       CelluleNL,3,Members(j),false,false,8
     
                                       Next
     
                            EndIf
     
                ColorNLdeb,2,NL,3,xlThin,LightTurquoise
     
                Next
     
    Color 3,2,NL,3,xlMedium,-2
     
    NLMax=NL
     
     
     
    NL=3
     
    Cellule NL,5,"COMPTE",true,false,10
     
    Cellule NL,6,"APPARTENANCE",true,false,10
     
    Color NL,5,NL,6,xlMedium,Grey25
     
    IndexCol=1
     
    For i = 0 To UDict.count-1
     
                Groups=Split(UtabG(i),",")
     
                ng=Ubound(Groups)
     
                NL=NL+1
     
                NLdeb=NL
     
                CelluleNL,5,UtabU(i),true,false,8
     
                If ng>=0Then
     
                            Forj = 0 To ng
     
                                       Ifj>0 Then NL=NL+1           
     
                                       CelluleNL,6,Groups(j),false,false,8
     
                                       Next
     
                            EndIf
     
                ColorNLdeb,5,NL,6,xlThin,LightTurquoise
     
                Next
     
    Color 3,5,NL,6,xlMedium,-2
     
     
     
    If NL>NLmax Then NLMax=NL
     
     
     
    Cellule NLMax+2,1,"",false,true,8
     
    oXL.Columns("B:F").Select
     
    oXL.Selection.Columns.AutoFit
     
    oXL.Range("A1").Select
     
    ExcelFile=getpath() & "Liste des comptes de "& Computer &".xls"
     
    If fso.FileExists(ExcelFile) Then fso.DeleteFile ExcelFile,true
     
    oXL.ActiveWorkbook.SaveAs ExcelFile
     
    oXL.ACtiveWorkbook.Saved = True
     
    Wscript.quit
     
    '--------------------------------------------------------------------
     
    Sub Cellule(NumL,NumC,chaine,casse,italic,size)
     
    oXL.Cells(NumL,NumC).Value = Chaine
     
    If casse or size<>0 Then
     
                Coords=CellName(NumL,NumC)
     
                oXL.Range(Coords& ":" & Coords).Select
     
                Ifcasse   Then oXL.Selection.Font.Bold =True
     
                Ifitalic  Then oXL.Selection.Font.Italic =True
     
                Ifsize<>0 Then oXL.Selection.Font.Size = size
     
                End If
     
    End Sub
     
    '--------------------------------------------------------------------
     
    Function CellName(NumL,NumC)
     
    If NumC<=26 Then
     
                anumc=chr(64+NumC)
     
    Else
     
                n1=int(NumC/26)
     
                n2=NumC-n1*26
     
                anumc=chr(64+n1)& chr(64+n2)
     
                End If
     
    CellName=anumc & NumL
     
    End Function
     
    '--------------------------------------------------------------------
     
    Sub Color(NLdeb,NCdeb,NLfin,NCfin,W,col)
     
    Coords1=CellName(NLdeb,NCdeb)
     
    Coords2=CellName(NLfin,NCfin)
     
    oXL.Range(Coords1 & ":" & Coords2).Select
     
    With oXL.Selection.Borders(xlEdgeLeft)
     
        .LineStyle =xlContinuous
     
                .Weight = W
     
        .ColorIndex =xlAutomatic
     
                End With
     
    With oXL.Selection.Borders(xlEdgeTop)
     
        .LineStyle =xlContinuous
     
        .Weight = W
     
        .ColorIndex =xlAutomatic
     
                End With
     
    With oXL.Selection.Borders(xlEdgeBottom)
     
        .LineStyle =xlContinuous
     
        .Weight = W
     
        .ColorIndex =xlAutomatic
     
                End With
     
    With oXL.Selection.Borders(xlEdgeRight)
     
                .LineStyle= xlContinuous
     
        .Weight = W
     
        .ColorIndex =xlAutomatic
     
                End With
     
    With oXL.Selection.Interior
     
                Select Casecol
     
                            Case-1
     
                                       IfIndexCol=1 Then
     
                                                   .ColorIndex= LightTurquoise 
     
                                       Else
     
                                                   .ColorIndex= LightYellow
     
                                                   EndIf  
     
                            Case-2
     
                            Caseelse
     
                                       .ColorIndex=col
     
                            EndSelect
     
        .Pattern = xlSolid
     
        .PatternColorIndex= xlAutomatic
     
                End With
     
    IndexCol=3-IndexCol
     
    End Sub
     
    '--------------------------------------------------------------------
     
    ' Fonction de récupération du répertoire courant
     
    Function GetPath()
     
    Dim path
     
    path = WScript.ScriptFullName
     
    GetPath = Left(path, InStrRev(path, "\"))
     
    End Function
     
    '--------------------------------------------------------------------
    J ne comprend pas ou est l'errer il me dis qu'il y en a une ligne 191 ("Win32_GroupUser")
    bisare

  2. #2
    Expert éminent sénior


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008
    Points : 20 040
    Points
    20 040
    Par défaut
    il y a vraiment un saut de ligne, au milieu de ta ligne :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Set GUset =GetObject("winmgmts:{impersonationLevel=impersonate}!//" &Computer).InstancesOf _
     
                ("Win32_GroupUser")

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    37
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 37
    Points : 28
    Points
    28
    Par défaut
    heu non en fait l'erreuer est a la ligne 204
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    IfGDict.Exists(GName) Then

  4. #4
    Expert éminent sénior


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008
    Points : 20 040
    Points
    20 040
    Par défaut
    Citation Envoyé par bleubykey Voir le message
    heu non en fait l'erreuer est a la ligne 204
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    IfGDict.Exists(GName) Then
    tu est sur ...? et tu n'as rien fait entre-temps ?

    et il n'y as pas de message d'erreur ..?





    Rajoute déjà l'espace qui manque entre if et GDi.....

    mais bon essai d'arranger ton code qu'il soit plus lisible..

  5. #5
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    37
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 37
    Points : 28
    Points
    28
    Par défaut
    apres avoir modifier la ligne 192
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Set GUset =GetObject("winmgmts:{impersonationLevel=impersonate}!//" &Computer).InstancesOf_("Win32_GroupUser")
    et modifier les If et end if

    le message d'errer est à la ligne 281



    c dur dur je n'y connai vraiment rien

    je vous remet le code modifier :

    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
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    ' ----------------------------------------------------------
     
    ' Script VBS d'affichage sous EXCEL de la liste des
     
    ' Permet d'afficher sur EXCEL la liste des groupes et
     
    ' comptes sur une machine locale ou distante
     
    ' ----------------------------------------------------------
     
     
     
    Dim net, computer, args, GUSet, Group, User, GDict,UDict,Members, Groups
     
     
     
    ' Constantes EXCEL
     
    ' ----------------
     
    Const xlDiagonalDown      = 5
     
    Const xlDiagonalUp        = 6
     
    Const xlEdgeLeft          = 7
     
    Const xlEdgeTop           = 8
     
    Const xlEdgeBottom        = 9
     
    Const xlEdgeRight         =10
     
    Const xlContinous         = 1
     
    Const xlThin              = 2
     
    Const xlMedium                     =&HFFFFEFD6
     
    Const xlThick             = 4
     
    Const xlDouble            =&HFFFFEFE9
     
    Const xlAutomatic         =&HFFFFEFF7
     
    Const xlInsideVertical    = 11
     
    Const xlInsideHorizontal  = 12
     
    Const xlNone              =&HFFFFEFD2
     
    Const xlUnderlineStyleNone =&HFFFFEFD2
     
    Const xlCenter            =&HFFFFEFF4
     
    Const xlBottom            =&HFFFFEFF5
     
    Const xlContext            =&HFFFFEC76
     
    Const xlSolid             = 1
     
    Const msoFalse            = 0
     
    Const msoScaleFromTopLeft = 0
     
     
     
    Const xlR1C1              =&HFFFFEFCA
     
     
     
    ' Couleurs EXCEL
     
    ' --------------
     
    Black         =  1
     
    Brown         = 53
     
    OliveGreen    = 52
     
    DarkGreen     = 51
     
    DarkGreenBlue = 49
     
    DarkBlue      = 11
     
    Indigo        = 55
     
    Grey80        = 56
     
     
     
    DarkRed       =  9
     
    Orange        = 46
     
    LightBrown    = 12
     
    Green         = 10
     
    GreenBlue     = 14
     
    Blue          =  5
     
    GrayBlue      = 47
     
    Gray50        = 16
     
     
     
    Red           =  3
     
    LightOrange   = 45
     
    LimeGreen     = 43
     
    MarineGreen   = 50
     
    WaterGreen    = 42
     
    LightBlue     = 41
     
    Violet        = 13
     
    Gray40        = 48
     
     
     
    Pink          =  7
     
    Gold          = 44
     
    Yellow        =  6
     
    BrigthGreen   =  4
     
    Turquoise     =  8
     
    SkyBlue       = 33
     
    Plum          = 54
     
    Grey25        = 15
     
     
     
    SalmonPink    = 38
     
    Brown         = 40
     
    LightYellow   = 36
     
    LightGreen    = 35
     
    LightTurquoise= 34
     
    MediumBlue    = 37
     
    Lavender      = 39
     
    White         =  2
     
     
     
    Set net   =Wscript.CreateObject("WScript.Network")
     
    Set fso   = WScript.CreateObject("Scripting.FileSystemObject")
     
    Set args  =Wscript.Arguments
     
    If args.count=0 Then
     
                computer=net.ComputerName
     
    Else
     
                computer=args(0)
     
                End If
     
     
     
    Set GDict =WScript.CreateObject("Scripting.Dictionary")
     
    Set UDict = WScript.CreateObject("Scripting.Dictionary")
     
     
     
    Set GUset =GetObject("winmgmts:{impersonationLevel=impersonate}!//" &Computer).InstancesOf_("Win32_GroupUser")
     
     
     
    for each GU in GUset
     
                setGroup=GetObject("winmgmts:" & GU.GroupComponent)
     
                set User=GetObject("winmgmts:" & GU.PartComponent)
     
                GName=Group.Name
     
                Uname=User.Name
     
                If GDict.Exists(GName) Then
     
                            OldList=GDict.Item(GName)
     
                            GDict.Item(GName)=OldList& "," & UName
     
                Else
     
                            GDict.AddGName, UName
     
                            End If
     
     
     
                If UDict.Exists(UName) Then
     
                            OldList=UDict.Item(UName)
     
                            UDict.Item(UName)=OldList& "," & GName
     
                Else
     
                            UDict.AddUName, GName
     
                            End If
     
                next
     
     
     
    Dim GTabG,GtabU, UTabU, UTabG
     
    GtabG=GDict.Keys
     
    GtabU=GDict.Items
     
    UtabU=UDict.Keys
     
    UtabG=UDict.Items
     
     
     
    Set oXL =WScript.CreateObject("EXCEL.application")
     
    oXL.Visible = True
     
    oXL.Workbooks.Add
     
     
     
    Cellule 1,1,"Liste des Groupes et Comptes de l'ordinateur " & Computer & " le" & FormatDateTime(now, vbLongDate),true,false,12
     
     
     
    NL=3
     
    Cellule NL,2,"GROUPE",true,false,10
     
    Cellule NL,3,"COMPTES DU GROUPE",true,false,10
     
    Color NL,2,NL,3,xlMedium,Grey25
     
    IndexCol=1
     
    For i = 0 To GDict.count-1
     
                Members=Split(GtabU(i),",")
     
                nm=Ubound(Members)
     
                NL=NL+1
     
                NLdeb=NL
     
                CelluleNL,2,GtabG(i),true,false,8
     
                If nm>=0Then
     
                            Forj = 0 To nm
     
                                       Ifj>0 Then NL=NL+1
     
                                       CelluleNL,3,Members(j),false,false,8
     
                                       Next
     
                            EndIf
     
                ColorNLdeb,2,NL,3,xlThin,LightTurquoise
     
                Next
     
    Color 3,2,NL,3,xlMedium,-2
     
    NLMax=NL
     
     
     
    NL=3
     
    Cellule NL,5,"COMPTE",true,false,10
     
    Cellule NL,6,"APPARTENANCE",true,false,10
     
    Color NL,5,NL,6,xlMedium,Grey25
     
    IndexCol=1
     
    For i = 0 To UDict.count-1
     
                Groups=Split(UtabG(i),",")
     
                ng=Ubound(Groups)
     
                NL=NL+1
     
                NLdeb=NL
     
                CelluleNL,5,UtabU(i),true,false,8
     
                If ng>=0Then
     
                            Forj = 0 To ng
     
                                       Ifj>0 Then NL=NL+1           
     
                                       CelluleNL,6,Groups(j),false,false,8
     
                                       Next
     
                            EndIf
     
                ColorNLdeb,5,NL,6,xlThin,LightTurquoise
     
                Next
     
    Color 3,5,NL,6,xlMedium,-2
     
     
     
    If NL>NLmax Then NLMax=NL
     
     
     
    Cellule NLMax+2,1,"",false,true,8
     
    oXL.Columns("B:F").Select
     
    oXL.Selection.Columns.AutoFit
     
    oXL.Range("A1").Select
     
    ExcelFile=getpath() & "Liste des comptes de "& Computer &".xls"
     
    If fso.FileExists(ExcelFile) Then fso.DeleteFile ExcelFile,true
     
    oXL.ActiveWorkbook.SaveAs ExcelFile
     
    oXL.ACtiveWorkbook.Saved = True
     
    Wscript.quit
     
    '--------------------------------------------------------------------
     
    Sub Cellule(NumL,NumC,chaine,casse,italic,size)
     
    oXL.Cells(NumL,NumC).Value = Chaine
     
    If casse or size<>0 Then
     
                Coords=CellName(NumL,NumC)
     
                oXL.Range(Coords& ":" & Coords).Select
     
                Ifcasse   Then oXL.Selection.Font.Bold =True
     
                Ifitalic  Then oXL.Selection.Font.Italic =True
     
                Ifsize<>0 Then oXL.Selection.Font.Size = size
     
                End If
     
    End Sub
     
    '--------------------------------------------------------------------
     
    Function CellName(NumL,NumC)
     
    If NumC<=26 Then
     
                anumc=chr(64+NumC)
     
    Else
     
                n1=int(NumC/26)
     
                n2=NumC-n1*26
     
                anumc=chr(64+n1)& chr(64+n2)
     
                End If
     
    CellName=anumc & NumL
     
    End Function
     
    '--------------------------------------------------------------------
     
    Sub Color(NLdeb,NCdeb,NLfin,NCfin,W,col)
     
    Coords1=CellName(NLdeb,NCdeb)
     
    Coords2=CellName(NLfin,NCfin)
     
    oXL.Range(Coords1 & ":" & Coords2).Select
     
    With oXL.Selection.Borders(xlEdgeLeft)
     
        .LineStyle =xlContinuous
     
                .Weight = W
     
        .ColorIndex =xlAutomatic
     
                End With
     
    With oXL.Selection.Borders(xlEdgeTop)
     
        .LineStyle =xlContinuous
     
        .Weight = W
     
        .ColorIndex =xlAutomatic
     
                End With
     
    With oXL.Selection.Borders(xlEdgeBottom)
     
        .LineStyle =xlContinuous
     
        .Weight = W
     
        .ColorIndex =xlAutomatic
     
                End With
     
    With oXL.Selection.Borders(xlEdgeRight)
     
                .LineStyle= xlContinuous
     
        .Weight = W
     
        .ColorIndex =xlAutomatic
     
                End With
     
    With oXL.Selection.Interior
     
                Select Casecol
     
                            Case-1
     
                                       IfIndexCol=1 Then
     
                                                   .ColorIndex= LightTurquoise 
     
                                       Else
     
                                                   .ColorIndex= LightYellow
     
                                                   EndIf  
     
                            Case-2
     
                            Caseelse
     
                                       .ColorIndex=col
     
                            EndSelect
     
        .Pattern = xlSolid
     
        .PatternColorIndex= xlAutomatic
     
                End With
     
    IndexCol=3-IndexCol
     
    End Sub
     
    '--------------------------------------------------------------------
     
    ' Fonction de récupération du répertoire courant
     
    Function GetPath()
     
    Dim path
     
    path = WScript.ScriptFullName
     
    GetPath = Left(path, InStrRev(path, "\"))
     
    End Function
     
    '--------------------------------------------------------------------

  6. #6
    Expert éminent sénior


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008
    Points : 20 040
    Points
    20 040
    Par défaut
    Ligne 192 : tu as laissé le "_ " de saut de ligne .... enlève le...


    c'est quoi ta ligne 281 ... ( je vais pas continuer à compter pour toi ..)

  7. #7
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    37
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 37
    Points : 28
    Points
    28
    Par défaut


    GDict.AddGName, UName

    End If

    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
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    ' ----------------------------------------------------------
     
    ' Script VBS d'affichage sous EXCEL de la liste des
     
    ' Permet d'afficher sur EXCEL la liste des groupes et
     
    ' comptes sur une machine locale ou distante
     
    ' ----------------------------------------------------------
     
     
     
    Dim net, computer, args, GUSet, Group, User, GDict,UDict,Members, Groups
     
     
     
    ' Constantes EXCEL
     
    ' ----------------
     
    Const xlDiagonalDown      = 5
     
    Const xlDiagonalUp        = 6
     
    Const xlEdgeLeft          = 7
     
    Const xlEdgeTop           = 8
     
    Const xlEdgeBottom        = 9
     
    Const xlEdgeRight         =10
     
    Const xlContinous         = 1
     
    Const xlThin              = 2
     
    Const xlMedium                     =&HFFFFEFD6
     
    Const xlThick             = 4
     
    Const xlDouble            =&HFFFFEFE9
     
    Const xlAutomatic         =&HFFFFEFF7
     
    Const xlInsideVertical    = 11
     
    Const xlInsideHorizontal  = 12
     
    Const xlNone              =&HFFFFEFD2
     
    Const xlUnderlineStyleNone =&HFFFFEFD2
     
    Const xlCenter            =&HFFFFEFF4
     
    Const xlBottom            =&HFFFFEFF5
     
    Const xlContext            =&HFFFFEC76
     
    Const xlSolid             = 1
     
    Const msoFalse            = 0
     
    Const msoScaleFromTopLeft = 0
     
     
     
    Const xlR1C1              =&HFFFFEFCA
     
     
     
    ' Couleurs EXCEL
     
    ' --------------
     
    Black         =  1
     
    Brown         = 53
     
    OliveGreen    = 52
     
    DarkGreen     = 51
     
    DarkGreenBlue = 49
     
    DarkBlue      = 11
     
    Indigo        = 55
     
    Grey80        = 56
     
     
     
    DarkRed       =  9
     
    Orange        = 46
     
    LightBrown    = 12
     
    Green         = 10
     
    GreenBlue     = 14
     
    Blue          =  5
     
    GrayBlue      = 47
     
    Gray50        = 16
     
     
     
    Red           =  3
     
    LightOrange   = 45
     
    LimeGreen     = 43
     
    MarineGreen   = 50
     
    WaterGreen    = 42
     
    LightBlue     = 41
     
    Violet        = 13
     
    Gray40        = 48
     
     
     
    Pink          =  7
     
    Gold          = 44
     
    Yellow        =  6
     
    BrigthGreen   =  4
     
    Turquoise     =  8
     
    SkyBlue       = 33
     
    Plum          = 54
     
    Grey25        = 15
     
     
     
    SalmonPink    = 38
     
    Brown         = 40
     
    LightYellow   = 36
     
    LightGreen    = 35
     
    LightTurquoise= 34
     
    MediumBlue    = 37
     
    Lavender      = 39
     
    White         =  2
     
     
     
    Set net   =Wscript.CreateObject("WScript.Network")
     
    Set fso   = WScript.CreateObject("Scripting.FileSystemObject")
     
    Set args  =Wscript.Arguments
     
    If args.count=0 Then
     
                computer=net.ComputerName
     
    Else
     
                computer=args(0)
     
                End If
     
     
     
    Set GDict =WScript.CreateObject("Scripting.Dictionary")
     
    Set UDict = WScript.CreateObject("Scripting.Dictionary")
     
     
     
    Set GUset =GetObject("winmgmts:{impersonationLevel=impersonate}!//" &Computer).InstancesOf("Win32_GroupUser")
     
     
     
    for each GU in GUset
     
                Set Group=GetObject("winmgmts:" & GU.GroupComponent)
     
                set User=GetObject("winmgmts:" & GU.PartComponent)
     
                GName=Group.Name
     
                Uname=User.Name
     
                If GDict.Exists(GName) Then
     
                            OldList=GDict.Item(GName)
     
                            GDict.Item(GName)=OldList& "," & UName
     
                Else
     
                            GDict.AddGName, UName
     
                            End If
     
     
     
                If UDict.Exists(UName) Then
     
                            OldList=UDict.Item(UName)
     
                            UDict.Item(UName)=OldList& "," & GName
     
                Else
     
                            UDict.AddUName, GName
     
                            End If
     
                next
     
     
     
    Dim GTabG,GtabU, UTabU, UTabG
     
    GtabG=GDict.Keys
     
    GtabU=GDict.Items
     
    UtabU=UDict.Keys
     
    UtabG=UDict.Items
     
     
     
    Set oXL =WScript.CreateObject("EXCEL.application")
     
    oXL.Visible = True
     
    oXL.Workbooks.Add
     
     
     
    Cellule 1,1,"Liste des Groupes et Comptes de l'ordinateur " & Computer & " le" & FormatDateTime(now, vbLongDate),true,false,12
     
     
     
    NL=3
     
    Cellule NL,2,"GROUPE",true,false,10
     
    Cellule NL,3,"COMPTES DU GROUPE",true,false,10
     
    Color NL,2,NL,3,xlMedium,Grey25
     
    IndexCol=1
     
    For i = 0 To GDict.count-1
     
                Members=Split(GtabU(i),",")
     
                nm=Ubound(Members)
     
                NL=NL+1
     
                NLdeb=NL
     
                CelluleNL,2,GtabG(i),true,false,8
     
                If nm>=0Then
     
                            For j = 0 To nm
     
                                       If j>0 Then NL=NL+1
     
                                       CelluleNL,3,Members(j),false,false,8
     
                                       Next
     
                            End If
     
                ColorNLdeb,2,NL,3,xlThin,LightTurquoise
     
                Next
     
    Color 3,2,NL,3,xlMedium,-2
     
    NLMax=NL
     
     
     
    NL=3
     
    Cellule NL,5,"COMPTE",true,false,10
     
    Cellule NL,6,"APPARTENANCE",true,false,10
     
    Color NL,5,NL,6,xlMedium,Grey25
     
    IndexCol=1
     
    For i = 0 To UDict.count-1
     
                Groups=Split(UtabG(i),",")
     
                ng=Ubound(Groups)
     
                NL=NL+1
     
                NLdeb=NL
     
                CelluleNL,5,UtabU(i),true,false,8
     
                If ng>=0Then
     
                            For j = 0 To ng
     
                                       If j>0 Then NL=NL+1           
     
                                       CelluleNL,6,Groups(j),false,false,8
     
                                       Next
     
                            End If
     
                ColorNLdeb,5,NL,6,xlThin,LightTurquoise
     
                Next
     
    Color 3,5,NL,6,xlMedium,-2
     
     
     
    If NL>NLmax Then NLMax=NL
     
     
     
    Cellule NLMax+2,1,"",false,true,8
     
    oXL.Columns("B:F").Select
     
    oXL.Selection.Columns.AutoFit
     
    oXL.Range("A1").Select
     
    ExcelFile=getpath() & "Liste des comptes de "& Computer &".xls"
     
    If fso.FileExists(ExcelFile) Then fso.DeleteFile ExcelFile,true
     
    oXL.ActiveWorkbook.SaveAs ExcelFile
     
    oXL.ACtiveWorkbook.Saved = True
     
    Wscript.quit
     
    '--------------------------------------------------------------------
     
    Sub Cellule(NumL,NumC,chaine,casse,italic,size)
     
    oXL.Cells(NumL,NumC).Value = Chaine
     
    If casse or size<>0 Then
     
                Coords=CellName(NumL,NumC)
     
                oXL.Range(Coords& ":" & Coords).Select
     
                If casse   Then oXL.Selection.Font.Bold =True
     
                If italic  Then oXL.Selection.Font.Italic =True
     
                If size<>0 Then oXL.Selection.Font.Size = size
     
                End If
     
    End Sub
     
    '--------------------------------------------------------------------
     
    Function CellName(NumL,NumC)
     
    If NumC<=26 Then
     
                anumc=chr(64+NumC)
     
    Else
     
                n1=int(NumC/26)
     
                n2=NumC-n1*26
     
                anumc=chr(64+n1)& chr(64+n2)
     
                End If
     
    CellName=anumc & NumL
     
    End Function
     
    '--------------------------------------------------------------------
     
    Sub Color(NLdeb,NCdeb,NLfin,NCfin,W,col)
     
    Coords1=CellName(NLdeb,NCdeb)
     
    Coords2=CellName(NLfin,NCfin)
     
    oXL.Range(Coords1 & ":" & Coords2).Select
     
    With oXL.Selection.Borders(xlEdgeLeft)
     
        .LineStyle =xlContinuous
     
                .Weight = W
     
        .ColorIndex =xlAutomatic
     
                End With
     
    With oXL.Selection.Borders(xlEdgeTop)
     
        .LineStyle =xlContinuous
     
        .Weight = W
     
        .ColorIndex =xlAutomatic
     
                End With
     
    With oXL.Selection.Borders(xlEdgeBottom)
     
        .LineStyle =xlContinuous
     
        .Weight = W
     
        .ColorIndex =xlAutomatic
     
                End With
     
    With oXL.Selection.Borders(xlEdgeRight)
     
                .LineStyle= xlContinuous
     
        .Weight = W
     
        .ColorIndex =xlAutomatic
     
                End With
     
    With oXL.Selection.Interior
     
                Select Case col
     
                            Case-1
     
                                       If IndexCol=1 Then
     
                                                   .ColorIndex= LightTurquoise 
     
                                       Else
     
                                                   .ColorIndex= LightYellow
     
                                                   End If  
     
                            Case-2
     
                            Case else
     
                                       .ColorIndex=col
     
                            End Select
     
        .Pattern = xlSolid
     
        .PatternColorIndex= xlAutomatic
     
                End With
     
    IndexCol=3-IndexCol
     
    End Sub
     
    '--------------------------------------------------------------------
     
    ' Fonction de récupération du répertoire courant
     
    Function GetPath()
     
    Dim path
     
    path = WScript.ScriptFullName
     
    GetPath = Left(path, InStrRev(path, "\"))
     
    End Function
     
    '--------------------------------------------------------------------

  8. #8
    Expert éminent sénior


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008
    Points : 20 040
    Points
    20 040
    Par défaut
    mais il sort d'ou ce code ...?

    applique toi sur les copier/coller....

    je comprends pas tous ces sauts de lignes en trop...

    et la encore il semble manquer un espace après le add



    PS: je n'ai pas encore regardé ce que pouvais faire ce code, mais si tu fais juste un copier/coller sans rien comprendre, on aura de la chance si cela fonctionne..
    dans ton code tu as une ligne "Dim Gname" , qui est une déclaration de variable.. il semble ensuite évidant que cette variable est utilisé en paramètre de la fonction Add.. d'où l'espace entre le Add et le Gname.

  9. #9
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mars 2008
    Messages
    37
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2008
    Messages : 37
    Points : 28
    Points
    28
    Par défaut
    j’ai trouvé ce code sur cette page et j'aimerai le faire fonctionné pour une machine en local :
    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
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
     
    ' ----------------------------------------------------------
     
    ' Script VBS d'affichage sous EXCEL de la liste des
     
    ' Permet d'afficher sur EXCEL la liste des groupes et
     
    ' comptes sur une machine locale ou distante
     
    ' ----------------------------------------------------------
     
     
     
    Dim net, computer, args, GUSet, Group, User, GDict,UDict,Members, Groups
     
     
     
    ' Constantes EXCEL
     
    ' ----------------
     
    Const xlDiagonalDown      = 5
     
    Const xlDiagonalUp        = 6
     
    Const xlEdgeLeft          = 7
     
    Const xlEdgeTop           = 8
     
    Const xlEdgeBottom        = 9
     
    Const xlEdgeRight         =10
     
    Const xlContinous         = 1
     
    Const xlThin              = 2
     
    Const xlMedium                     =&HFFFFEFD6
     
    Const xlThick             = 4
     
    Const xlDouble            =&HFFFFEFE9
     
    Const xlAutomatic         =&HFFFFEFF7
     
    Const xlInsideVertical    = 11
     
    Const xlInsideHorizontal  = 12
     
    Const xlNone              =&HFFFFEFD2
     
    Const xlUnderlineStyleNone =&HFFFFEFD2
     
    Const xlCenter            =&HFFFFEFF4
     
    Const xlBottom            =&HFFFFEFF5
     
    Const xlContext            =&HFFFFEC76
     
    Const xlSolid             = 1
     
    Const msoFalse            = 0
     
    Const msoScaleFromTopLeft = 0
     
     
     
    Const xlR1C1              =&HFFFFEFCA
     
     
     
    ' Couleurs EXCEL
     
    ' --------------
     
    Black         =  1
     
    Brown         = 53
     
    OliveGreen    = 52
     
    DarkGreen     = 51
     
    DarkGreenBlue = 49
     
    DarkBlue      = 11
     
    Indigo        = 55
     
    Grey80        = 56
     
     
     
    DarkRed       =  9
     
    Orange        = 46
     
    LightBrown    = 12
     
    Green         = 10
     
    GreenBlue     = 14
     
    Blue          =  5
     
    GrayBlue      = 47
     
    Gray50        = 16
     
     
     
    Red           =  3
     
    LightOrange   = 45
     
    LimeGreen     = 43
     
    MarineGreen   = 50
     
    WaterGreen    = 42
     
    LightBlue     = 41
     
    Violet        = 13
     
    Gray40        = 48
     
     
     
    Pink          =  7
     
    Gold          = 44
     
    Yellow        =  6
     
    BrigthGreen   =  4
     
    Turquoise     =  8
     
    SkyBlue       = 33
     
    Plum          = 54
     
    Grey25        = 15
     
     
     
    SalmonPink    = 38
     
    Brown         = 40
     
    LightYellow   = 36
     
    LightGreen    = 35
     
    LightTurquoise= 34
     
    MediumBlue    = 37
     
    Lavender      = 39
     
    White         =  2
     
     
     
    Set net   =Wscript.CreateObject("WScript.Network")
     
    Set fso   = WScript.CreateObject("Scripting.FileSystemObject")
     
    Set args  =Wscript.Arguments
     
    If args.count=0 Then
     
                computer=net.ComputerName
     
    Else
     
                computer=args(0)
     
                End If
     
     
     
    Set GDict =WScript.CreateObject("Scripting.Dictionary")
     
    Set UDict = WScript.CreateObject("Scripting.Dictionary")
     
     
     
    Set GUset =GetObject("winmgmts:{impersonationLevel=impersonate}!//" &Computer).InstancesOf _
     
                ("Win32_GroupUser")
     
     
     
    for each GU in GUset
     
                setGroup=GetObject("winmgmts:" & GU.GroupComponent)
     
                set User=GetObject("winmgmts:" & GU.PartComponent)
     
                GName=Group.Name
     
                Uname=User.Name
     
                IfGDict.Exists(GName) Then
     
                            OldList=GDict.Item(GName)
     
                            GDict.Item(GName)=OldList& "," & UName
     
                Else
     
                            GDict.AddGName, UName
     
                            EndIf
     
     
     
                IfUDict.Exists(UName) Then
     
                            OldList=UDict.Item(UName)
     
                            UDict.Item(UName)=OldList& "," & GName
     
                Else
     
                            UDict.AddUName, GName
     
                            EndIf
     
                next
     
     
     
    Dim GTabG,GtabU, UTabU, UTabG
     
    GtabG=GDict.Keys
     
    GtabU=GDict.Items
     
    UtabU=UDict.Keys
     
    UtabG=UDict.Items
     
     
     
    Set oXL =WScript.CreateObject("EXCEL.application")
     
    oXL.Visible = True
     
    oXL.Workbooks.Add
     
     
     
    Cellule 1,1,"Liste des Groupes et Comptes de l'ordinateur " & Computer & " le" & FormatDateTime(now, vbLongDate),true,false,12
     
     
     
    NL=3
     
    Cellule NL,2,"GROUPE",true,false,10
     
    Cellule NL,3,"COMPTES DU GROUPE",true,false,10
     
    Color NL,2,NL,3,xlMedium,Grey25
     
    IndexCol=1
     
    For i = 0 To GDict.count-1
     
                Members=Split(GtabU(i),",")
     
                nm=Ubound(Members)
     
                NL=NL+1
     
                NLdeb=NL
     
                CelluleNL,2,GtabG(i),true,false,8
     
                If nm>=0Then
     
                            Forj = 0 To nm
     
                                       Ifj>0 Then NL=NL+1
     
                                       CelluleNL,3,Members(j),false,false,8
     
                                       Next
     
                            EndIf
     
                ColorNLdeb,2,NL,3,xlThin,LightTurquoise
     
                Next
     
    Color 3,2,NL,3,xlMedium,-2
     
    NLMax=NL
     
     
     
    NL=3
     
    Cellule NL,5,"COMPTE",true,false,10
     
    Cellule NL,6,"APPARTENANCE",true,false,10
     
    Color NL,5,NL,6,xlMedium,Grey25
     
    IndexCol=1
     
    For i = 0 To UDict.count-1
     
                Groups=Split(UtabG(i),",")
     
                ng=Ubound(Groups)
     
                NL=NL+1
     
                NLdeb=NL
     
                CelluleNL,5,UtabU(i),true,false,8
     
                If ng>=0Then
     
                            Forj = 0 To ng
     
                                       Ifj>0 Then NL=NL+1           
     
                                       CelluleNL,6,Groups(j),false,false,8
     
                                       Next
     
                            EndIf
     
                ColorNLdeb,5,NL,6,xlThin,LightTurquoise
     
                Next
     
    Color 3,5,NL,6,xlMedium,-2
     
     
     
    If NL>NLmax Then NLMax=NL
     
     
     
    Cellule NLMax+2,1,"",false,true,8
     
    oXL.Columns("B:F").Select
     
    oXL.Selection.Columns.AutoFit
     
    oXL.Range("A1").Select
     
    ExcelFile=getpath() & "Liste des comptes de "& Computer &".xls"
     
    If fso.FileExists(ExcelFile) Then fso.DeleteFile ExcelFile,true
     
    oXL.ActiveWorkbook.SaveAs ExcelFile
     
    oXL.ACtiveWorkbook.Saved = True
     
    Wscript.quit
     
    '--------------------------------------------------------------------
     
    Sub Cellule(NumL,NumC,chaine,casse,italic,size)
     
    oXL.Cells(NumL,NumC).Value = Chaine
     
    If casse or size<>0 Then
     
                Coords=CellName(NumL,NumC)
     
                oXL.Range(Coords& ":" & Coords).Select
     
                Ifcasse   Then oXL.Selection.Font.Bold =True
     
                Ifitalic  Then oXL.Selection.Font.Italic =True
     
                Ifsize<>0 Then oXL.Selection.Font.Size = size
     
                End If
     
    End Sub
     
    '--------------------------------------------------------------------
     
    Function CellName(NumL,NumC)
     
    If NumC<=26 Then
     
                anumc=chr(64+NumC)
     
    Else
     
                n1=int(NumC/26)
     
                n2=NumC-n1*26
     
                anumc=chr(64+n1)& chr(64+n2)
     
                End If
     
    CellName=anumc & NumL
     
    End Function
     
    '--------------------------------------------------------------------
     
    Sub Color(NLdeb,NCdeb,NLfin,NCfin,W,col)
     
    Coords1=CellName(NLdeb,NCdeb)
     
    Coords2=CellName(NLfin,NCfin)
     
    oXL.Range(Coords1 & ":" & Coords2).Select
     
    With oXL.Selection.Borders(xlEdgeLeft)
     
        .LineStyle =xlContinuous
     
                .Weight = W
     
        .ColorIndex =xlAutomatic
     
                End With
     
    With oXL.Selection.Borders(xlEdgeTop)
     
        .LineStyle =xlContinuous
     
        .Weight = W
     
        .ColorIndex =xlAutomatic
     
                End With
     
    With oXL.Selection.Borders(xlEdgeBottom)
     
        .LineStyle =xlContinuous
     
        .Weight = W
     
        .ColorIndex =xlAutomatic
     
                End With
     
    With oXL.Selection.Borders(xlEdgeRight)
     
                .LineStyle= xlContinuous
     
        .Weight = W
     
        .ColorIndex =xlAutomatic
     
                End With
     
    With oXL.Selection.Interior
     
                Select Casecol
     
                            Case-1
     
                                       IfIndexCol=1 Then
     
                                                   .ColorIndex= LightTurquoise 
     
                                       Else
     
                                                   .ColorIndex= LightYellow
     
                                                   EndIf  
     
                            Case-2
     
                            Caseelse
     
                                       .ColorIndex=col
     
                            EndSelect
     
        .Pattern = xlSolid
     
        .PatternColorIndex= xlAutomatic
     
                End With
     
    IndexCol=3-IndexCol
     
    End Sub
     
    '--------------------------------------------------------------------
     
    ' Fonction de récupération du répertoire courant
     
    Function GetPath()
     
    Dim path
     
    path = WScript.ScriptFullName
     
    GetPath = Left(path, InStrRev(path, "\"))
     
    End Function
     
    '--------------------------------------------------------------------
    PS: je ne connais rien en vbscript

Discussions similaires

  1. Réponses: 2
    Dernier message: 27/03/2008, 18h49
  2. VBA Liste des Groups d'un User
    Par Keuf95 dans le forum Access
    Réponses: 2
    Dernier message: 24/08/2006, 14h38
  3. Test sur formulaire avec liste des erreurs
    Par Nicos77 dans le forum Langage
    Réponses: 37
    Dernier message: 17/11/2005, 10h22

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