Overblog Tous les blogs Top blogs Technologie & Science Tous les blogs Technologie & Science
Editer l'article Suivre ce blog Administration + Créer mon blog
MENU

[vbscript] library perso

Publié le par damcuvelier

librairie personnelle

On Error Resume Next

' ######################################## Déclaration des Variables #########################
Dim strComputer
Dim logfile,installsource,strComputerName,strUSERPROFILE,strTEMP
Dim extractdotNetFx4,netfxCorex86cmdline,netfxextendedx86cmdline,netfxcorex64cmdline,netfxextendedx64cmdline
Dim vsvsrcmdline,vcPROPERTIES
Dim UCATypeLibrarycmdline,AvayaCollaborationx86cmdline,AvayaCollaborationx64cmdline,Avayaonexc_6_2_3_setupcmdline
Dim o2007piacmdline,o2010piacmdline
Dim addin,archi
Dim objFSO,wshshell,objWMIService,colItems,objItem,objFolder
dim homepath,ScriptName


' ######################################## Déclaration des Constantes #########################
strComputer = "."

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Const HKCR = &H80000000 'HKEY_CLASSES_ROOT
Const HKCU = &H80000001 'HKEY_CURRENT_USER
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
Const HKU  = &H80000003 'HKEY_USERS
Const HKCC = &H80000005 'HKEY_CURRENT_CONFIG
Const ForReading = 1
Const TristateFalse = 0
Const ForAppending = 8
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wshshell = WScript.CreateObject("WScript.Shell")
strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
strUSERPROFILE = wshShell.ExpandEnvironmentStrings( "%USERPROFILE%" )
strTEMP = wshShell.ExpandEnvironmentStrings( "%temp%" )
ScriptName = split(WScript.ScriptName,".")(0)
homepath = left(WScript.ScriptFullName,len(WScript.ScriptFullName)-len(WScript.ScriptName)-1)


dim TAGFILE
TAGFILE = checkcondition("arg","TAGFILE")
wscript.echo TAGFILE


' #################################################################### Description des fonctions ########################################################

' #################################
' # checkkey HK strKeyPath RegKey :
' #################################
' Si la fonction est vraie alors la clé HK\strKeyPath\RegKey existe
' (HK = HKCR, ou HKCU, ou HKLM, ou HKU , ou HKCC)

' ########################
' # createfolder(Folder) :
' ########################
' Utiliser la fonction createfolder(Folder) pour créer le dossier Folder s'il n'existe pas
' ATTENTION: IL FAUT UTILISER LE CHEMIN FQDN

' ########################
' # checkcondition(emplacement,value) :
' ########################
' checkcondition("arg",'valeur') => si l'argument /'valeur' existe alors checkcondition = 'valeur'
' checkcondition("Folder",'valeur') => si 'le répertoire (chemin complet)' existe alors checkcondition = 'le répertoire (chemin complet)'
' checkcondition("File",'valeur') => si 'le fichier (chemin complet)' existe alors checkcondition = 'le fichier (chemin complet)'

' ########################
' #  checkarchitecture :
' ########################
' checkarchitecture = "64" ou checkarchitecture = "86"

' ########################
' # update(source,destination) :
' ########################
' fait un robocopy /MIR de source vers destination en créant destination si elle n'existe pas au préalable

' ########################
' # LOG(Message) :
' ########################
' si l'argument DEBUG est utilisé alors les messages de log et les commandes apparaitront en echo

' ########################
' # cmd(var) :
' ########################
' si l'argument DEBUG est utilisé alors les commande apparaitront en echo sinon elles seront executées


' #################################################################### Description des fonctions ########################################################

 

 

'####################################### Fonctions #########################################

'################### lignes de commande de deploiement:
function update(source,destination)
if isempty(checkcondition("arg","debug")) then
createfolder(destination)
wshshell.run "%comspec% /C ROBOCOPY /MIR " & chr(34) & source & chr(34) & " " & chr(34) & destination & chr(34),0,true
else
    wscript.echo "---------" & VbCrLf & "Création du répertoire " & "[" & destination & "]," & VbCrLf & "S'il n'éxiste pas." & VbCrLf & "---------"
    wscript.echo "ROBOCOPY: " & "[" & source & "]" & " -> " & "[" & destination & "]"
end if
end function

function checkkey(HK,strKeyPath,RegKey)
if isempty(checkcondition("arg","debug")) then
    dim oReg,arrSubKeys,subkey,bfound
    Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
    oReg.EnumKey HK, strKeyPath, arrSubKeys
    For Each subkey In arrSubKeys
        checkkey = (lcase(subkey) = lcase(RegKey))
        if checkkey then exit for
    Next
else
    wscript.echo "Verification de l'existance de la clé : ["& HK & "\" & strKeyPath & "\" & RegKey & "]"
end if
end function

function LOG(logmessage)
dim dateStamp,logOutput
if isempty(checkcondition("arg","debug")) then
    dateStamp = Now()
    Set logOutput = objFSO.OpenTextFile(logfile, ForAppending, True, TristateTrue)
    if logmessage = "" then
    logOutput.WriteLine("")
    else
    logOutput.WriteLine(cstr(dateStamp) & " -" & vbTab & logmessage)
    end if
    logOutput.Close
else
    if not logmessage = "########################" or logmessage = "" then
    wscript.echo logmessage
    end if
end if
End function

function createfolder(Folder)
If not objFSO.FolderExists(Folder) Then
Set objFolder = objFSO.CreateFolder(Folder)
End If
End function

function checkcondition(emplacement,value)
if emplacement = "arg" then
    if WScript.Arguments.Named.Exists(value) then
        if isempty(WScript.Arguments.Named(value)) then
        checkcondition = true
        else
        checkcondition = WScript.Arguments.Named(value)
        end if
    end if
elseif emplacement = "Folder" then
    if objFSO.FolderExists(value) then
    checkcondition = value
    end if
elseif emplacement = "File" then
    if objFSO.FolderExists(value) then
    checkcondition = File
    end if
end if
End function

function checkarchitecture
If objFSO.FolderExists("c:\Program Files (x86)") Then
checkarchitecture = "64"
else
checkarchitecture = "86"
end if
End function

function cmd(var)
if isempty(checkcondition("arg","debug")) then
cmd = wshshell.run(var,0,true)
else
wscript.echo var
end if
End function

 

 

Commenter cet article