'Parse the command line.
call ParseCommand()
WScript.Sleep 9000
Dim objFSO, objTextFile
Dim NomFichier, CheminFichier, CheminScriptActuel, ScriptFileName, Position
Dim varLogger
'Déclaration des constantes
Const ForReading = 1
Const ForWritting = 2
Const ForAppending = 8
ScriptFileName = wscript.scriptname
Position = InstrRev(ScriptFileName,".")
if (Position > 0) Then ScriptFileName = Left(ScriptFileName, Position - 1)
NomFichier = ScriptFileName & "_Log.txt"
CheminScriptActuel = Left(wscript.scriptfullname,Len(wscript.scriptfullname)-Len(wscript.scriptname)-1)
CheminFichier = CheminScriptActuel & "\" & NomFichier 'Déclaration du chemin et du nom du fichier
Set WSHShell = CreateObject("WScript.Shell")
'vHomeDrive = WSHShell.ExpandEnvironmentStrings("%HOMEDRIVE%")
vUserName = WSHShell.ExpandEnvironmentStrings("%USERNAME%")
'wscript.echo vUserName
If varLogger = "1" Then
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(CheminFichier, ForWritting, True)
objTextFile.WriteLine("Avant" & Now) 'On ecrit la date et l'heure dans le fichier
objTextFile.WriteLine("vUserName : " & vUserName)
End IF
If (Lcase(vUserName) = "username1") Or (Lcase(vUserName) = "username2") Then
If varLogger = "1" Then objTextFile.WriteLine("Le UserName va être traité")
'wscript.echo "Pouet"
Set WSHNetwork = CreateObject("WScript.Network")
WSHNetwork.SetDefaultPrinter "HP LaserJet Professional P1606"
Set WSHNetwork = Nothing
Else
If varLogger = "1" Then objTextFile.WriteLine("Le UserName n'est pas à traiter")
End If
If varLogger = "1" Then
objTextFile.WriteLine("Apres " & Now) 'On ecrit la date et l'heure dans le fichier
objTextFile.Close 'Fermeture du fichier
Set objTextFile = Nothing
Set objFSO = Nothing
End If
wscript.echo "Script Done."
Function ParseCommand()
'
' Parses the command line and fills the script variables
' with the appropriate values.
'
Dim ArgCount
Dim objArgs
Set objArgs = Wscript.Arguments
ArgCount = 0
if objArgs.Count = 0 then
wscript.echo "No arguments specified."
wscript.echo
call Help()
end if
While ArgCount < objArgs.Count
Select Case LCase(objArgs(ArgCount))
Case "-logger"
ArgCount = ArgCount + 1
varLogger=LCase(objArgs(ArgCount))
varLogger = Cstr(varLogger)
wscript.echo "varLogger : " & varLogger
Case Else:
wscript.echo "Invalid command."
wscript.echo
call Help()
wscript.quit
End Select
ArgCount = ArgCount + 1
Wend
End Function
sub Help()
'
' Display command-line syntax for the script.
'
wscript.echo "Script Function details"
wscript.echo "Syntax:"
wscript.echo
wscript.echo "-varLogger ""Log on a file or not"""
wscript.echo
wscript.echo "Example :"
wscript.echo "C:\MyScript.vbs -logger 1"
'wscript.quit
End Sub
Lien vers le fichier : cliquez ici
Exemple de déclenchement par GPO
Exemple de log généré quand demandé
Article(s) précédent(s)
Article(s) en relation(s)