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 :

Erreur: 'Function' attendu (à la dernière ligne)


Sujet :

VBScript

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Responsable du parc et des réseaux de télécommunication
    Inscrit en
    Novembre 2012
    Messages
    37
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Responsable du parc et des réseaux de télécommunication
    Secteur : Industrie

    Informations forums :
    Inscription : Novembre 2012
    Messages : 37
    Par défaut Erreur: 'Function' attendu (à la dernière ligne)
    Bonjour,

    Je but sur un problème avec un script vbs que j'ai fait à l'aide de fonctions récupérées un peu partout.

    Lorsque je l'exécute le "compilateur vbscript" me renvoit une erreur à la dernière ligne disant Fonction attendu.

    Je vous remercie de votre aide.

    Voici mon code:

    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
     
        'On Error Resume Next
     
        ' Script d'ouverture de session
        '
        '
        '
     
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        ' INFORMATIONS GENERALES
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
     
        'Date et heure
        Dim varnow, Current, Vardate
     
        Varnow = now
        Current = TimeHHMMSS()
        Vardate = Day(varnow) & "-" & Month(varnow) & "-" & Year(varnow) & "_at_" & Current
     
     
     
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        ' COLLECTE DES INFORMATIONS SYSTEMES / MACHINE / UTILISATEURS / SESSION-PROFIL
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        Dim objShell,WshNetwork,objFSO,objTextFile
        Dim UserPath,UserUpn,StrComputer,LocalFile,NetPath,OutFile,VarIP
     
        Const ForWriting = 2
        Const OverwriteExisting = True
        Const ForAppend = 8
        StrComputer="."
     
        ' Creation du fichier de log local, collecte des informations de session et de profil
        Set WshShell = CreateObject("wscript.shell")
        Set WshNetwork = WScript.CreateObject("WScript.Network")
        Set objFSO = CreateObject("scripting.filesystemobject")
     
        UserPath = WshShell.ExpandEnvironmentStrings("%userprofile%") & "\session_log"
        UserUpn = WshNetwork.UserName
        LocalFile = UserPath & "\" & Vardate & "_.log"
        NetPath = "\\S-FR-DC01\LogIn$\"
        OutFile = NetPath & StrComputer & "_" & UserUpn & "__" & VarIP & "__date-" & Vardate & "_.log"
     
     
        If objFSO.FolderExists(UserPath) = False Then
                 objFSO.CreateFolder(UserPath)
        End If
     
        Set objTextFile = objFSO.CreateTextFile(LocalFile, True)
     
     
     
        'Os info et CPU Name
     
     
        Dim  Reg_1, Reg_2, Reg_3, Reg_4, Reg_5, Reg_Bool
     
     
           Reg_1 = "HKLM\Software\Microsoft\Windows NT\CurrentVersion\" & "ProductName"
           Reg_2 = "HKLM\Software\Microsoft\Windows NT\CurrentVersion\" & "CSDVersion"
           Reg_3 = "HKLM\Software\Microsoft\Windows NT\CurrentVersion\" & "CurrentVersion"
           Reg_4 = "HKLM\Hardware\Description\System\CentralProcessor\0\" & "ProcessorNameString"
           Reg_5 = "HKLM\SOFTWARE\Wow6432Node"
     
     
     
           If RegValueExists(Reg_5) then
     
           Reg_Bool = "x64"
           OsType = WshShell.RegRead (Reg_1) & "__" & WshShell.RegRead (Reg_2) & "__" & WshShell.RegRead (Reg_3) & "__" & Reg_Bool
     
           Else if RegKeyExists(Reg_5)= False then
     
           Reg_Bool = "x86"
           OsType = WshShell.RegRead (Reg_1) & "__" & WshShell.RegRead (Reg_2) & "__" & WshShell.RegRead (Reg_3) & "__" & Reg_Bool
     
           End if
     
     
     
        'Collecte des informations de configuration  IP du poste
        Dim  objWMIService,IPItems
        Set objWMIService = GetObject("winmgmts:\\" & strcomputer & "\root\CIMV2")
        Set IPItems = objWMIService.ExecQuery("Select IPAddress from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
     
              For Each IPConfig In IPItems
                 If Not IsNull(IPConfig.IPAddress) Then
                    For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
                       If varIP="" Then
                          varIP=IPConfig.IPAddress(0)
                       End If
                    Next
                 End If
              Next
     
     
     
     
     
        ' ECRITURE DES RESULTATS DE REQUETTE DANS LE FICHIER DE LOG
     
        objTextFile.WriteLine "Computer    : " & strComputer
        objTextFile.WriteLine "OS : " & OsType
        objTextFile.WriteLine "CPU : " & WshShell.RegRead (Reg_4)
        objTextFile.WriteLine ProfilState()
        objTextFile.WriteLine "Username    : " & UserUpn
        objTextFile.WriteLine "Adresse IP    : " & varIP
        objTextFile.WriteBlankLines (3)
     
     
     
        ' Récupération du RSOP si la machine execute un OS client
     
        Dim ColSys,OSVersion
     
        Set ColSys = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
     
        For Each OS In ColSys
     
           OSVersion = Left(OS.Version,3)
     
                 If InStr(OS.Caption, "Server") Then
     
                    objTextFile.Close
                    Exit For
     
                 Else
     
                    objTextFile.WriteLine "RSOP return"
                    objTextFile.Close
     
                 End if
     
     
                 Select Case OSVersion
     
     
                    Case "5.0","5.1","5.2"
                       objShell.Run  "cmd.exe /c gpresult >>" & LocalFile
     
     
     
                    Case "6.0","6.1","6.2"
                       objShell.Run  "cmd.exe /c gpresult /R >>" & LocalFile
     
     
                    Case Else
     
                       objShell.Run "cmd /c echo impossible de détécter le système d'exploitation et donc de déterminer la syntaxe de gpresult >>" & LocalFile
     
                 End Select
     
        Next
     
     
        WScript.Sleep 3000
     
     
        'Copie du fichier sur le share avec indication du nom d'ordinateur du login utilisateur et horodatage dans le nom du fichier
        objFSO.CopyFile LocalFile , Outfile , OverwriteExisting
     
     
     
        ' Vide le contenu du session_log antérieur à 60 jours
        Dim objLocalFolder,objFile,objSubfolder,objNetFolder
        Dim DayToKeep
     
        DayToKeep = 60
        Set objLocalFolder = objFSO.GetFolder(UserPath)
     
     
        For Each objFile In objLocalFolder.files
            If DateDiff("d", objFile.DateCreated,Now) > DayToKeep Then
                objFile.Delete True
                objFile
            End If
        Next
     
     
        For Each objSubfolder In objLocalFolder.Subfolders
            If DateDiff("d", objSubfolder.DateCreated,Now) > DayToKeep Then
                    objSubfolder.Delete True     
            End If
        Next
     
        Set objNetFolder = objFSO.GetFolder(NetPath)
     
        For Each objFile In objNetFolder.files
            If DateDiff("d", objFile.DateCreated,Now) > DayToKeep Then
                objFile.Delete True
            End If
        Next
     
     
        For Each objSubfolder In objNetFolder.Subfolders
            If DateDiff("d", objSubfolder.DateCreated,Now) > DayToKeep Then
                    objSubfolder.Delete True     
            End If
        Next
     
     
        'annulation / vidage des objets
        set objTextFile = Nothing
        set objFSO = Nothing
        Set objFile = Nothing
        Set objFolder = Nothing
        set WshShell = Nothing
        Set WshNetwork = Nothing
        Set objWMIService = Nothing
        Set objTextStream = Nothing
        Set objLocalFolder = Nothing
        Set objNetFolder = Nothing
     
     
     
     
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        ''''''''''''''''''''''''''''''' BLOC DE FONCTIONS '''''''''''''''''''''''''''''''''''''''''''''''''''
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
     
        ' Fonction heure
     
        Function TimeHHMMSS()
     
            Dim retv, d
            d = Now
            retv = Right("00" & Hour(d), 2) & "-" & Right("00" & Minute(d), 2) & "-" & Right("00" & Second(d), 2)
            TimeHHMMSS = retv
     
        End Function
     
     
        ' Fonction Reg TEST
        Function RegValueExists(sRegValue)
             ' Returns True or False based of the existence of a registry value.
             Dim oShell, RegReadReturn
             Set oShell = CreateObject("WScript.Shell")
             RegValueExists = True  ' init value
             On Error Resume Next
             RegReadReturn = oShell.RegRead(sRegValue)
             If Err.Number <> 0 Then
               RegValueExists = False
             End if
             On Error Goto 0
        End Function
     
     
        ' Fonction profil status
     
        Function ProfilState()
     
        Dim oWMI,ColProfil,Info,KeyProfileStatus,MyUserSid,Etat
     
        Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
     
        Set ColProfil = objWMIService.ExecQuery("Select * From Win32_UserProfile")
     
        For Each Info in ColProfil
     
           MySidUser = Info.SID
     
        Next
     
        KeyProfileStatus = WshShell.RegRead("HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList\" & MySidUser & "\State")
     
     
              Select case KeyProfileStatus
                 Case 0
                  Etat = "Le profil est de type : Normal"
                 Case 16
                  Etat = "Le profil est de type : Itinérant"
                 Case 20
                  Etat = "Le profil est de type : Itinérant" & Vbtab & "1er ouverture de Session - Profil local supprimé"
                 Case 24
                  Etat = "Le profil est de type : Itinérant" & Vbtab & "Profil serveur supprimé"
                 Case 262149
                  Etat = "Le profil est de type : Mandatory" & Vbtab & "1er ouverture de Session"
                 Case 393217
                  Etat = "Le profil est de type : Mandatory"
                 Case 516
                  Etat = "Le profil est de type : Normal" & Vbtab & "1er ouverture de Session"   
                 Case 540
                  Etat = "Le profil est de type : Itinérant" & Vbtab & "1er ouverture de Session"               
                 Case 2564
                  Etat = "Le profil est de type : Temporaire"            
                 Case Else
                  Etat ="Le profil est de type : Inconnu"
     
              End Select
     
              ProfilState =  Etat
     
        End Function
    Merci de votre aide

    Orwell

  2. #2
    Modérateur
    Avatar de l_autodidacte
    Homme Profil pro
    Retraité : Directeur de lycée/Professeur de sciences physiques
    Inscrit en
    Juillet 2009
    Messages
    2 420
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 69
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Retraité : Directeur de lycée/Professeur de sciences physiques
    Secteur : Enseignement

    Informations forums :
    Inscription : Juillet 2009
    Messages : 2 420
    Par défaut
    Bonjour
    Voici quelques remarques sur le code :
    1 - Ligne 72 "Else if" à rempacer par "ElseIf"
    2 - Ligne 72 "RegKeyEsists" à remplcaer par "RegValueExists"
    3 - Ligne 139 "objShell" non initialisé ; il faut mettre avant cette ligne : Set objShell = CreateObject("Wscript.Shell")
    4 - Ligne 256 à remplacer par : Set ColProfil = objWMIService.ExecQuery("Select * FROM Win32_UserAccount",,48).
    Maintenant, le code modifié(avec les corrections à faire pour obtenir l'état du compte) est :
    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
     Const ForReading = 1, ForWriting = 2, ForAppend = 8
     
        'On Error Resume Next
     
        ' Script d'ouverture de session
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        ' INFORMATIONS GENERALES
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
         'Date et heure
        Dim varnow, Current, Vardate
     
        Varnow = now
        Current = TimeHHMMSS()
        Vardate = Day(varnow) & "-" & Month(varnow) & "-" & Year(varnow) & "_at_" & Current
     
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        ' COLLECTE DES INFORMATIONS SYSTEMES / MACHINE / UTILISATEURS / SESSION-PROFIL
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        Dim objShell,WshNetwork,objFSO,objTextFile
        Dim UserPath,UserUpn,StrComputer,LocalFile,NetPath,OutFile,VarIP
     
        'Const ForWriting = 2
        Const OverwriteExisting = True
        StrComputer="."
     
        ' Creation du fichier de log local, collecte des informations de session et de profil
        Set WshShell = CreateObject("wscript.shell")
    	Set objShell = CreateObject("wscript.shell")
        Set WshNetwork = WScript.CreateObject("WScript.Network")
        Set objFSO = CreateObject("scripting.filesystemobject")
     
        UserPath = WshShell.ExpandEnvironmentStrings("%userprofile%") & "\session_log"
        UserUpn = WshNetwork.UserName
        LocalFile = UserPath & "\" & Vardate & "_.log"
        'NetPath = "\\S-FR-DC01\LogIn$\"
    	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
    	Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem",,48) 
    	For Each objItem in colItems 
    		 Nom = objItem.Caption
    	Next	 
    	NetPath = "C:\Tmp\"
    '    OutFile = NetPath & Nom & "_" & UserUpn & "__" & VarIP & "__date-" & Vardate & "_.log"
     
        If objFSO.FolderExists(UserPath) = False Then
                 objFSO.CreateFolder(UserPath)
        End If
     
        Set objTextFile = objFSO.CreateTextFile(LocalFile, True)
     
        'Os info et CPU Name
        Dim  Reg_1, Reg_2, Reg_3, Reg_4, Reg_5, Reg_Bool
     
           Reg_1 = "HKLM\Software\Microsoft\Windows NT\CurrentVersion\" & "ProductName"
           Reg_2 = "HKLM\Software\Microsoft\Windows NT\CurrentVersion\" & "CSDVersion"
           Reg_3 = "HKLM\Software\Microsoft\Windows NT\CurrentVersion\" & "CurrentVersion"
           Reg_4 = "HKLM\Hardware\Description\System\CentralProcessor\0\" & "ProcessorNameString"
           Reg_5 = "HKLM\SOFTWARE\Wow6432Node"
     
           If RegValueExists(Reg_5) then
    		  Reg_Bool = "x64"
    		  OsType = WshShell.RegRead (Reg_1) & "__" & WshShell.RegRead (Reg_2) & "__" & WshShell.RegRead (Reg_3) & "__" & Reg_Bool
           Elseif RegValueExists(Reg_5)= False then
    		  Reg_Bool = "x86"
    		  OsType = WshShell.RegRead (Reg_1) & "__" & WshShell.RegRead (Reg_2) & "__" & WshShell.RegRead (Reg_3) & "__" & Reg_Bool
           End if
     
        'Collecte des informations de configuration  IP du poste
        Dim  objWMIService,IPItems
        Set objWMIService = GetObject("winmgmts:\\" & strcomputer & "\root\CIMV2")
        Set IPItems = objWMIService.ExecQuery("Select IPAddress from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
     
              For Each IPConfig In IPItems
                 If Not IsNull(IPConfig.IPAddress) Then
                    For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
                       If varIP="" Then
                          varIP=IPConfig.IPAddress(0)
                       End If
                    Next
                 End If
              Next
    OutFile = NetPath & Nom & "_" & UserUpn & "_" & VarIP & "_date-" & Vardate & "_.log"
        ' ECRITURE DES RESULTATS DE REQUETTE DANS LE FICHIER DE LOG
        objTextFile.WriteLine "Computer    : " & strComputer
        objTextFile.WriteLine "OS : " & OsType
        objTextFile.WriteLine "CPU : " & WshShell.RegRead (Reg_4)
        objTextFile.WriteLine ProfilState()
        objTextFile.WriteLine "Username    : " & UserUpn
        objTextFile.WriteLine "Adresse IP    : " & varIP
        objTextFile.WriteBlankLines (3)
     
        ' Récupération du RSOP si la machine execute un OS client
     
        Dim ColSys,OSVersion
     
        Set ColSys = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
     
        For Each OS In ColSys
              OSVersion = Left(OS.Version,3)
     
    		 If InStr(OS.Caption, "Server") Then
    			 objTextFile.Close
    			Exit For
    		 Else
    			 objTextFile.WriteLine "RSOP return"
    			 objTextFile.Close
    		 End if
     
    		 Select Case OSVersion
    			Case "5.0","5.1","5.2"
    			   objShell.Run  "cmd.exe /c gpresult >>" & LocalFile
    			Case "6.0","6.1","6.2"
    			   objShell.Run  "cmd.exe /c gpresult /R >>" & LocalFile
    			Case Else
    				objShell.Run "cmd /c echo impossible de détécter le système d'exploitation et donc de déterminer la syntaxe de gpresult >>" & LocalFile
    		 End Select
         Next
     
        WScript.Sleep 3000
     
        'Copie du fichier sur le share avec indication du nom d'ordinateur du login utilisateur et horodatage dans le nom du fichier
        objFSO.CopyFile LocalFile , Outfile , 0 'OverwriteExisting
     
        ' Vide le contenu du session_log antérieur à 60 jours
        Dim objLocalFolder,objFile,objSubfolder,objNetFolder
        Dim DayToKeep
     
        DayToKeep = 60
        Set objLocalFolder = objFSO.GetFolder(UserPath)
     
        For Each objFile In objLocalFolder.files
            If DateDiff("d", objFile.DateCreated,Now) > DayToKeep Then
                objFile.Delete True
                'objFile
            End If
        Next
     
        For Each objSubfolder In objLocalFolder.Subfolders
            If DateDiff("d", objSubfolder.DateCreated,Now) > DayToKeep Then
                    objSubfolder.Delete True     
            End If
        Next
     
        Set objNetFolder = objFSO.GetFolder(NetPath)
     
        For Each objFile In objNetFolder.files
            If DateDiff("d", objFile.DateCreated,Now) > DayToKeep Then
                objFile.Delete True
            End If
        Next
     
        For Each objSubfolder In objNetFolder.Subfolders
            If DateDiff("d", objSubfolder.DateCreated,Now) > DayToKeep Then
                    objSubfolder.Delete True     
            End If
        Next
     
        'annulation / vidage des objets
        set objTextFile = Nothing
        set objFSO = Nothing
        Set objFile = Nothing
        Set objFolder = Nothing
        set WshShell = Nothing
        Set WshNetwork = Nothing
        Set objWMIService = Nothing
        Set objTextStream = Nothing
        Set objLocalFolder = Nothing
        Set objNetFolder = Nothing
     
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        ''''''''''''''''''''''''''''''' BLOC DE FONCTIONS '''''''''''''''''''''''''''''''''''''''''''''''''''
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
     
      ' ================ Fonction heure ================
        Function TimeHHMMSS()
            Dim retv, d
            d = Now
            retv = Right("00" & Hour(d), 2) & "-" & Right("00" & Minute(d), 2) & "-" & Right("00" & Second(d), 2)
            TimeHHMMSS = retv
         End Function
       ' ============= Fonction Reg TEST ==============
        Function RegValueExists(sRegValue)
             ' Returns True or False based of the existence of a registry value.
             Dim oShell, RegReadReturn
             Set oShell = CreateObject("WScript.Shell")
             RegValueExists = True  ' init value
             On Error Resume Next
             RegReadReturn = oShell.RegRead(sRegValue)
             If Err.Number <> 0 Then
               RegValueExists = False
             End if
             On Error Goto 0
        End Function
       ' ============ Fonction profil status =========
        Function ProfilState()
        Dim oWMI,ColProfil,Info,KeyProfileStatus,MyUserSid,Etat
        Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
        Set ColProfil = objWMIService.ExecQuery("Select * FROM Win32_UserAccount",,48)
     
    		'On Error Resume Next
    		For Each Info in ColProfil
    			MySidUser = Info.SID
    		Next
        KeyProfileStatus = WshShell.RegRead("HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList\" & MySidUser & "\State")
              Select case KeyProfileStatus
                 Case 0
                  Etat = "Le profil est de type : Normal"
                 Case 16
                  Etat = "Le profil est de type : Itinérant"
                 Case 20
                  Etat = "Le profil est de type : Itinérant" & Vbtab & "1er ouverture de Session - Profil local supprimé"
                 Case 24
                  Etat = "Le profil est de type : Itinérant" & Vbtab & "Profil serveur supprimé"
                 Case 262149
                  Etat = "Le profil est de type : Mandatory" & Vbtab & "1er ouverture de Session"
                 Case 393217
                  Etat = "Le profil est de type : Mandatory"
                 Case 516
                  Etat = "Le profil est de type : Normal" & Vbtab & "1er ouverture de Session"   
                 Case 540
                  Etat = "Le profil est de type : Itinérant" & Vbtab & "1er ouverture de Session"               
                 Case 2564
                  Etat = "Le profil est de type : Temporaire"            
               '  Case Else
               '   Etat ="Le profil est de type : Inconnu"
              End Select
              ProfilState =  Etat
        End Function
    Ne pas oublier le tag si satisfait.
    Voter pour toute réponse satisfaisante avec pour encourager les intervenants.
    Balises CODE indispensables. Regardez ICI
    Toujours utiliser la clause Option Explicit(VBx, VBS ou VBA) et Ne jamais typer variables et/ou fonctions en VBS.
    Vous pouvez consulter mes contributions
    Ne pas oublier de consulter les différentes FAQs et les Cours/Tutoriels VB6/VBScript
    Ne pas oublier L'Aide VBScript et MSDN VB6 Fr

  3. #3
    Membre averti
    Homme Profil pro
    Responsable du parc et des réseaux de télécommunication
    Inscrit en
    Novembre 2012
    Messages
    37
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Responsable du parc et des réseaux de télécommunication
    Secteur : Industrie

    Informations forums :
    Inscription : Novembre 2012
    Messages : 37
    Par défaut
    Merci beaucoup à toi.

    Grâce à tes conseils j'ai pu corriger mon script.

    J'ai fait les corrections pour le elseif et le RegValueExists.

    Pour le objShell (ligne 139) je l'ai simplement remplacé par le WshShell que j'avais créé plus haut dans le corps principal.

    Pour le ColProfil, je l'ai pas changé parce que c'est bien les informations sur l'état du profil sur le poste que je voulais collecter.

    En tout cas encore une fois merci parce que toutes les erreurs de syntaxe et de nom de fonction et d'objet que tu as relevé , j'avais rien vu.

    Problème résolu

    Orwell

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

Discussions similaires

  1. [JScrollPane] [JTable] Se placer à la dernière ligne
    Par wishnight dans le forum Composants
    Réponses: 9
    Dernier message: 24/12/2015, 18h42
  2. function replace et erreur avec retour a la ligne
    Par voyageurdumonde dans le forum Général JavaScript
    Réponses: 18
    Dernier message: 03/03/2011, 00h20
  3. Erreur shell - dernière ligne d'un fichier
    Par tiamat59 dans le forum Linux
    Réponses: 6
    Dernier message: 10/12/2008, 14h57
  4. Lecture de fichier - dernière ligne non prise en compte
    Par JulienPles dans le forum Algorithmes et structures de données
    Réponses: 3
    Dernier message: 16/03/2005, 11h57
  5. l'identifiant unique de la dernière ligne insérée
    Par dim_italia dans le forum PostgreSQL
    Réponses: 1
    Dernier message: 23/08/2004, 17h55

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