Bonjour,

Je ne comprend pas pourquoi mon script ne s’exécute pas normalement si un bloc du code est positionné avant ou après l'initialisation de certaines variables qui n'ont rien à voir avec l'appel d'une fonction.

Si je déplace mon bloc If IsMember .... sous "SI BLOC DEPLACE CI-DESSOUS" alors mon test d'appartenance au groupe ne fonctionne pas.

J'avoue que je ne comprends pas toutes les subtilité de VBS.

Pouvez-vous m'éclairer sur ce comportement bizarre selon moi.

Cordialement.


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
On Error Resume Next 
 
Dim item,filterArray,GrpUser,oShell,dateStamp,comment,driveP,logonserver
 
US = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%UserProfile%")
dateStamp = Now()
comment = "Connexion au domaine MYDOM le " & dateStamp
 
'*************************************************************************
' SI BLOC DEPLACE CI-DESSOUS  
'*************************************************************************
 
 
'CREATE NETWORK OBJECTS
Set oShell = WScript.CreateObject ("WSCript.shell")
Set mWSHNetwork = CreateObject("WScript.Network")
Set mExisitingMappedDrives = mWSHNetwork.EnumNetworkDrives
Set mFileSystemObject = CreateObject("Scripting.FileSystemObject")
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile(US & "\SCRIPT.TXT")
 
strUserName = mWSHNetwork.UserName
logonserver = oShell.expandenvironmentstrings("%logonserver%")
 
' ************************************************************************************
' DEBUT BLOC QUI POSE PROBLEME 
' ************************************************************************************
If IsMember("GRP_NO_GRPPRODDPE") Then
    WScript.quit
End If
' ************************************************************************************
' FIN BLOC QUI POSE PROBLEME 
' ************************************************************************************
 
 
 
 
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'RELEVENT FUNCTIONS BELOW
 
Dim errorReport
 
Private Function IsMember(groupName)
    domain = mWSHNetwork.UserDomain
	MSGBOX groupName 
    user = mWSHNetwork.UserName
    'On windows 9x the script may begin running before the user is logged in. 
    'The following loop handles the scenerio described above.
    startTime = Now
    Do While user = ""
    	If DateDiff("s", startTime, Now) > 30 Then WScript.Quit
    	WScript.Sleep 500
    	user = mWSHNetwork.UserName
    Loop
    flgIsMember = False
    Set userObj = GetObject("WinNT://" & domain & "/" & user & ",user")
    For Each grp In userObj.Groups
        If Trim(grp.Name) = Trim(groupName) Then
            flgIsMember = true
            Exit For
        End If
    Next
    IsMember = flgIsMember
    Set userObj = Nothing
End Function