You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2015-09-09 17:48:22

sinnerman
Member
Registered: 2011-03-01
Posts: 44

Cadeau un script d'installation d'agent contre une question :)

Hello tout le monde,

voici le script que j'utilises, il marche super mais pas avec les derniers agent 2.3.16 je n'arrive pas à trouver la bonne syntaxe pour ses arguments en mode silencieux.

Il s'installe nickel, il pointe bien sur le bon serveurs (vérification dans les registres) mais le Runnow ne marche pas et je ne sais pas si l'argument version complète fonctionne (installtasks=full) car il ne remonte pas dans mon glpifusion... une idée.

Option Explicit
Dim versionverification, fusionarguments, uninstallocsagent, fusionsetupURL
''''' USER SETTINGS '''''
versionverification = "2.3.16" 
fusionarguments = "/acceptlicense  /installtasks=Full /installtype=from-scratch /execmode=Service /server='http://MONSERVEURICI/glpifusion/plugins/fusioninventory/' /S /runnow" 
fusionarguments = "/acceptlicense  /installtasks=Full /installtype=from-scratch /execmode=Service /server='http://MONSERVEURICI/glpifusion/plugins/fusioninventory/' /S /runnow" 
' Depending on your needs, you can use either HTTP or Windows share
'fusionsetupURL = "\\server1\data\fusioninventory-agent_windows-i386_" & versionverification & ".exe" 
fusionsetupURL = "http://www.VOTRESERVEURICI/fusion/fusioninventory-agent_windows-x86_2.3.16" & versionverification & ".exe" 

uninstallocsagent = "yes" 
''''' DO NOT EDIT BELOW '''''
Function baseName (strng)
  Dim regEx, ret
  Set regEx = New RegExp
  regEx.Global = true
  regEx.IgnoreCase = True
  regEx.Pattern = ".*[/\\]([^/\\]+)$" 
  baseName = regEx.Replace(strng,"$1")
End Function 

Function isHttp (strng)
  Dim regEx, matches 
  Set regEx = New RegExp
  regEx.Global = true
  regEx.IgnoreCase = True
  regEx.Pattern = "^(http(s?)).*" 
  If regEx.Execute(strng).count > 0 Then
    isHttp = True
  Else
    isHttp = False
  End If
  Exit Function
End Function 

Function SaveWebBinary(strUrl) 'As Boolean
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
Const ForWriting = 2
Dim web, varByteArray, strData, strBuffer, lngCounter, ado
'    On Error Resume Next
    'Download the file with any available object
    Err.Clear
    Set web = Nothing
    Set web = CreateObject("WinHttp.WinHttpRequest.5.1")
    If web Is Nothing Then Set web = CreateObject("WinHttp.WinHttpRequest")
    If web Is Nothing Then Set web = CreateObject("MSXML2.ServerXMLHTTP")
    If web Is Nothing Then Set web = CreateObject("Microsoft.XMLHTTP")
    web.Open "GET", strURL, False
    web.Send
    If Err.Number <> 0 Then
        SaveWebBinary = False
        Set web = Nothing
        Exit Function
    End If
    If web.Status <> "200" Then
        SaveWebBinary = False
        Set web = Nothing
        Exit Function
    End If
    varByteArray = web.ResponseBody
    Set web = Nothing
    'Now save the file with any available method
    On Error Resume Next
    Set ado = Nothing
    Set ado = CreateObject("ADODB.Stream")
    If ado Is Nothing Then
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set ts = fs.OpenTextFile(baseName(strUrl), ForWriting, True)
        strData = "" 
        strBuffer = "" 
        For lngCounter = 0 to UBound(varByteArray)
            ts.Write Chr(255 And Ascb(Midb(varByteArray,lngCounter + 1, 1)))
        Next
        ts.Close
    Else
        ado.Type = adTypeBinary
        ado.Open
        ado.Write varByteArray
        ado.SaveToFile CreateObject("WScript.Shell").ExpandEnvironmentStrings("%Temp%") & "\fusioninventory.exe", adSaveCreateOverWrite
        ado.Close
    End If
    SaveWebBinary = True
End Function




Function removeOCS()
    On error resume next

    Dim OCS
    ' Uninstall agent ocs if is installed
    ' Verification on OS 32 Bits
    On error resume next
MyLog.WriteLine "start remove ?"

OCS = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OCS Inventory Agent\UninstallString")
    If err.number = 0 then
MyLog.WriteLine "r2"
        WshShell.Run "CMD.EXE /C net stop ""OCS INVENTORY SERVICE""",0,True
        WshShell.Run "CMD.EXE /C """ & OCS & """ /S /NOSPLASH",0,True
        WshShell.Run "CMD.EXE /C rmdir ""%ProgramFiles%\OCS Inventory Agent"" /S /Q",0,True
        WshShell.Run "CMD.EXE /C rmdir ""%SystemDrive%\ocs-ng"" /S /Q",0,True
        WshShell.Run "CMD.EXE /C sc delete ""OCS INVENTORY""",0,True
    End If

    ' Verification on OS 64 Bits
    On error resume next
    OCS = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\OCS Inventory Agent\UninstallString")
    If err.number = 0 then
MyLog.WriteLine "r3"
        WshShell.Run "CMD.EXE /C net stop ""OCS INVENTORY SERVICE""",0,True
        WshShell.Run "CMD.EXE /C """ & OCS & """ /S /NOSPLASH",0,True
        WshShell.Run "CMD.EXE /C rmdir ""%ProgramFiles(x86)%\OCS Inventory Agent"" /S /Q",0,True
        WshShell.Run "CMD.EXE /C rmdir ""%SystemDrive%\ocs-ng"" /S /Q",0,True
        WshShell.Run "CMD.EXE /C sc delete ""OCS INVENTORY""",0,True
    End If

    ' Verification Agent V2 on 32Bit
    On error resume next
    OCS = WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OCS Inventory NG Agent\UninstallString")
    If err.number = 0 then
MyLog.WriteLine "r5"
        WshShell.Run "CMD.EXE /C net stop ""OCS INVENTORY SERVICE""",0,True
        WshShell.Run "CMD.EXE /C taskkill /F /IM ocssystray.exe",0,True
        WshShell.Run "CMD.EXE /C """ & OCS & """ /S /NOSPLASH",0,True
        WshShell.Run "CMD.EXE /C rmdir ""%ProgramFiles%\OCS Inventory Agent"" /S /Q",0,True
        WshShell.Run "CMD.EXE /C rmdir ""%SystemDrive%\ocs-ng"" /S /Q",0,True
        WshShell.Run "CMD.EXE /C sc delete ""OCS INVENTORY""",0,True
    End If

    ' Verification Agent V2 on 64Bit
    On error resume next
    OCS = WshShell.RegRead("HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\OCS Inventory NG Agent\UninstallString")
    If err.number = 0 Then
    MyLog.WriteLine "r6"
        WshShell.Run "CMD.EXE /C net stop ""OCS INVENTORY SERVICE""",0,True
        WshShell.Run "CMD.EXE /C taskkill /F /IM ocssystray.exe",0,True
        WshShell.Run "CMD.EXE /C """ & OCS & """ /S /NOSPLASH",0,True
        WshShell.Run "CMD.EXE /C rmdir ""%ProgramFiles%\OCS Inventory Agent"" /S /Q",0,True
        WshShell.Run "CMD.EXE /C rmdir ""%SystemDrive%\ocs-ng"" /S /Q",0,True
        WshShell.Run "CMD.EXE /C sc delete ""OCS INVENTORY""",0,True
    End If
MyLog.WriteLine "end remove"
End Function




Function needFusionInstall ()
    Dim Fusion
    ' install fusion if version is different or if not installed
    needFusionInstall = False 
MyLog.WriteLine "start need ?"
    On error resume next
    Fusion = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\FusionInventory Agent\DisplayVersion")
    If err.number = 0 Then
      ' Verification on OS 32 Bits
MyLog.WriteLine "n2"
      If Fusion <> versionverification Then
MyLog.WriteLine "n3"
          needFusionInstall = True
      Else
MyLog.WriteLine "n4=>je force"
    needFusionInstall = False 
    needFusionInstall = true 
        Return
      End If
    Else
      ' Verification on OS 64 Bits
      On error resume next
MyLog.WriteLine "n5"
      Fusion = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\FusionInventory Agent\DisplayVersion")
      If err.number = 0 Then
        If Fusion <> versionverification Then
MyLog.WriteLine "n6"
          needFusionInstall = True
        End if
      Else
      MyLog.WriteLine "n7"

          needFusionInstall = True
      End If
    End If
    MyLog.WriteLine "end n"

End Function






''' MAIN
Dim WshShell,objFSO,MyLog
Set WshShell = Wscript.CreateObject("Wscript.shell")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set myLog = objFSO.OpenTextFile("c:\setec\jpa\log\fusion.log", 2, True)
MyLog.WriteLine "Hello"

If uninstallocsagent = "yes" Then
MyLog.WriteLine "Remove old OCS ..."
    removeOCS()
End If

If needFusionInstall() Then
MyLog.WriteLine "needed => install !"
    If (isHttp(fusionsetupURL)) Then
       SaveWebBinary(fusionsetupURL)
MyLog.WriteLine "GO1 !"
       WshShell.Run "CMD.EXE /C %TEMP%\fusioninventory.exe " & fusionarguments,0,True
    Else
MyLog.WriteLine "GO2 !"
        WshShell.Run "CMD.EXE /C """ & fusionsetupURL & """ " & fusionarguments,0,True
    End If
End If

MyLog.WriteLine "END"

Last edited by sinnerman (2015-09-09 17:49:48)

Offline

#2 2015-09-15 13:33:41

nicolas996
Member
Registered: 2012-10-22
Posts: 17

Re: Cadeau un script d'installation d'agent contre une question :)

Je te conseille d'utiliser le script vbs fourni sur cette page : http://fusioninventory.org/documentatio … ndows.html dans la section "Large installation"
Il devrait résoudre tous tes problèmes

Offline

#3 2015-09-16 16:07:30

sinnerman
Member
Registered: 2011-03-01
Posts: 44

Re: Cadeau un script d'installation d'agent contre une question :)

Merci Nicolas996 par contre je n'ai pas trouvé le VBS sur cette page ? il est ou le lien stp ?

Offline

Board footer

Powered by FluxBB