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
| '************************************
'* Registry Key Exists (Function)
'* Returns a value (true / false)
'************************************
'This function checks to see if a passed registry key exists, and
'returns true if it does
'
'Requirements: The registry key you are looking for (RegistryKey)
'Note: RegistryKey MUST end in a backslash (\), or FALSE will be returned
Function RegistryKeyExists (RegistryKey)
'Ensure the last character is a backslash (\) - if it isn't, we aren't looking for a key
If (Right(RegistryKey, 1) <> "\") Then
'It's not a registry key we are looking for
RegistryKeyExists = false
Else
'If there isnt the key when we read it, it will return an error, so we need to resume
On Error Resume Next
'Try reading the key
WshShell.RegRead RegistryKey
'Catch the error
Select Case Err
'Error Code 0 = 'success'
Case 0:
RegistryKeyExists = true
'This checks for the (Default) value existing (but being blank); as well as key's not existing at all (same error code)
Case &h80070002:
'Read the error description, removing the registry key from that description
ErrDescription = Replace(Err.description, RegistryKey, "")
'Clear the error
Err.clear
'Read in a registry entry we know doesn't exist (to create an error description for something that doesnt exist)
WshShell.RegRead "HKEY_ERROR\"
'The registry key exists if the error description from the HKEY_ERROR RegRead attempt doesn't match the error
'description from our RegistryKey RegRead attempt
If (ErrDescription <> Replace(Err.description, "HKEY_ERROR\", "")) Then
RegistryKeyExists = true
Else
RegistryKeyExists = false
End If
'Any other error code is a failure code
Case Else:
RegistryKeyExists = false
End Select
'Turn error reporting back on
On Error Goto 0
End If
End Function
Dim WSHShell, objNET, objSysInfo, objComputer, strComputerDN, strGroups, Group, GroupName, Mytest
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set objSysInfo = WScript.CreateObject("ADSystemInfo")
strComputerDN = objSysInfo.COMPUTERNAME
Set objComputer = GetObject("LDAP://" & strComputerDN) 'Binds the objComputer to the Distiguished Name of the Computer in reference
Set objNetwork = WScript.CreateObject("Wscript.Network")
If RegistryKeyExists ("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\OCS INVENTORY\")=True Then 'si le service OCS Agent éxiste déjà alors
MsgBox "le service existe"
Else 'si le service Ocs Agent n'éxiste pas alors
'lance le fichier agent
Set aAgent = WScript.CreateObject("WScript.Shell")
aAgent.Run("\\group.tok\net_install\ocs\ocspackage.exe")
End If
set WshShell = WScript.CreateObject("WScript.Shell")
DesktopPath = WSHShell.SpecialFolders("Desktop")
'''''''''''''''''''''''''''''''''''''''''''''''''
WScript.Sleep 30000 'Délai d attente de 30 secondes le temps de l'installation de lagent
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objSourceFile = objFSO.OpenTextFile("C:\Program Files\OCS Inventory Agent\service.ini", 1) ' Fichier originale
Set objSourceFile2 = objFSO.OpenTextFile("\\group.tok\net_install\ocs\service_tf.ini", 1) 'Fichier copié
vrNumLigne = 0
Do Until objSourceFile.AtEndOfStream Or objSourceFile2.AtEndOfStream
vrNumLigne = vrNumLigne + 1
vrLigne = objSourceFile.ReadLine
vrLigne2 = objSourceFile2.ReadLine
vrComprLign = StrComp(vrLigne, vrLigne2, 1)
If vrComprLign = 1 Or vrComprLign = -1 Or IsNull(vrComprLign) Then
vrNul = "Les fichiers ne sont pas les mêmes"
Else
End If
Loop
objSourceFile.Close
objSourceFile2.Close
If IsEmpty(vrNul) Then
'les fichiers sont identiques alors aucune opération
Else
'les fichiers sont différents alors :
'Supression du fichier service.ini par défaut
Set aFile = CreateObject("Scripting.FileSystemObject")
aFile.DeleteFile("C:\Program Files\OCS Inventory Agent\service.ini")
'Copie du nouveau fichier de config
Set fso = CreateObject("Scripting.FileSystemObject")
Set aFile = fso.GetFile("\\group.tok\net_install\ocs\service_tf.ini")
aFile.Copy("C:\Program Files\OCS Inventory Agent\service_tf.ini")
'Renommage du fichier de config
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile "C:\Program Files\OCS Inventory Agent\service_tf.ini" , "C:\Program Files\OCS Inventory Agent\service.ini"
WScript.Sleep 30000 'Délai d attente de 10 secondes le temps de l'installation de lagent
'lance le fichier contact
Set aContact = WScript.CreateObject("WScript.Shell")
aContact.Run("file:///C:\Program%20Files\OCS%20Inventory%20Agent\Ocs_contact.exe")
End If |
Partager