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