Soyez le premier à donner votre avis sur cette source.
Vue 12 743 fois - Téléchargée 567 fois
'****************************************************************************** '*** SoftwareUpdater.vbs permet de sélectionner à partir d'une interface web un '*** des packages msi se trouvant dans le dossier 'msi' et de l'installer. '*** Ce script doit être lancé en tant qu'administrateur. '*** L'utilitaire ExecAs vous permettra de le rendre accessible par un utilisateur '*** standard (création d'un exe avec pour ligne de commande 'wscript.exe SoftwareUpdater.vbs'). '*** '****************************************************************************** on error resume next Const Overwrite = True Const ForReading = 1 Const ForWriting = 2 Const ALL_USERS = True dim ListeMsi(50) Dim shell, IE Set objFSO = CreateObject("Scripting.FileSystemObject") Set shell = WScript.CreateObject("WScript.Shell") Set objService = GetObject("winmgmts:") Set objSoftware = objService.Get("Win32_Product") RepWork = Left(WScript.ScriptFullName, InStrRev(WScript.ScriptFullName, "\")-1) RepWorkWeb="" for i=1 to len(RepWork) char=mid(RepWork, i, 1) if char="\" then RepWorkWeb=RepWorkWeb & "/" else RepWorkWeb=RepWorkWeb & char next PathMsi=RepWork & "\msi\" 'lecture de tous les packages msi disponibles NbreMsi=0 If objFSO.FolderExists(PathMsi) Then Set objFolder = objFSO.GetFolder(PathMsi) Set colFiles = objFolder.Files For Each objFile in colFiles if GetExtension(objFile.Name)=".msi" then NbreMsi=NbreMsi+1 ListeMsi(NbreMsi)=objFile.Name end if Next end if 'affichage page web OpenIE() shell.AppActivate "Gestionnaire d'ordinateurs" AffichePageWeb "SoftwareUpdater.htm", 0 do do WScript.Sleep 30 err.clear() action=IE.Document.Script.CheckVal() if err.number<>0 then WScript.Sleep 30 err.clear() IE.document.Open IE.document.close if err.number<>0 then exitprog() else AffichePageWeb "SoftwareUpdater.htm" end if Loop While (action = "off") if action="installer" then 'Recherche du package à installer for i=1 to NbreMsi IsChecked=IE.Document.SelectionForm.GroupeRadioMsi(i-1).checked if IsChecked then IsChecked=i exit for end if next if IsChecked then 'lance l'install du msi AffichePageWeb "SoftwareUpdater.htm", IsChecked errReturn = objSoftware.Install(PathMsi & ListeMsi(i), , ALL_USERS) if errReturn<>0 then MsgBox " L'intallation du package '" & ListeMsi(i) & "' a echoué.", vbCritical + vbOkOnly + vbSystemModal + 0,"Erreur d'exécution" else MsgBox "L'intallation du package '" & ListeMsi(i) & "' s'est terminé correctement.", vbInformation + vbOkOnly + vbSystemModal + 0,"Fin d'exécution" end if AffichePageWeb "SoftwareUpdater.htm", 0 else MsgBox "Vous devez sélectionner un programme à mettre à jour.", vbCritical + vbOkOnly + vbSystemModal + 0,"Erreur d'exécution" end if end if err.clear() IE.Document.Script.SetVal("off") if err.number<>0 then action="quitter" Loop While (action<>"quitter") exitprog() '------------------------------------------------------------ ' Fonction d'arret du script Function exitprog() IE.Quit Set IE = Nothing wscript.quit end function '------------------------------------------------------------ ' Fonction ouverture IE Function OpenIE() Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_") With IE .left=0 .top=0 .height=740 .width=1024 .menubar=0 .toolbar=0 .statusBar=0 .navigate "About:Blank" .visible=1 End With ' Attendre la fin du chargement de IE Do while IE.busy wscript.sleep(50) loop end function '------------------------------------------------------------ ' Fonction affichage page web Function AffichePageWeb(pageweb, index) On error resume next err.clear() Set objPageWeb = objFSO.OpenTextFile(RepWork & "\" & pageweb, ForReading) if err.number<>0 then MsgBox "Erreur d'ouverture de fichier." & vbCrLf & "Veuillez vérifier que le fichier '" & RepWork & "\" & pageweb & "' est accessible.", vbCritical + vbOkOnly + vbSystemModal + 0,"Erreur ouverture fichiers" exitprog() end if IE.document.Open Do Until objPageWeb.AtEndOfStream line=trim(objPageWeb.ReadLine) if line<>"" then IE.document.Writeln(line) if line="<!--inserrer ici la liste des packages msi-->" then if index<>0 then ligne="Installation du package en cours, veuillez patienter... (ce traitement peut être long)<br><br><img border='0' src='file:///" & RepWorkWeb & "/install.gif' width='30' height='32'> " & ListeMsi(index) & "<br>" IE.document.Writeln(ligne) else for ii=1 to NbreMsi ligne="<input type='radio' value='option_" & ii & "' name='GroupeRadioMsi'>" & ListeMsi(ii) & "<BR>" IE.document.Writeln(ligne) next end if end if end if loop IE.document.Close objPageWeb.Close IE.Document.SelectionForm.textsearch.value=textsearch end function '------------------------------------------------------------ ' Fonction retournant l'extension d'un fichier function GetExtension(filename) GetExtension="" filename=trim(filename) if len(filename)=0 then exit function yy=InStrRev(filename, ".") if yy>0 then GetExtension=mid(filename, yy, len(filename)-yy+1) end function
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.