TUTOS.EU

Passer des parametres à un VbScript

Comment passer des paramètres à un vbscript en ligne de commande

'Parse the command line.
call ParseCommand()


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 "-source"
			ArgCount = ArgCount + 1
			CheminFichierSource=LCase(objArgs(ArgCount))
			wscript.echo "CheminFichierSource : " & CheminFichierSource

			Case "-cible"
			ArgCount = ArgCount + 1
			CheminFichierCible=LCase(objArgs(ArgCount))
			wscript.echo "CheminFichierCible : " & CheminFichierCible

			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 "-source ""patch to the source file"""
	wscript.echo "-cible ""patch to the result file"""
	wscript.echo
	wscript.echo "Example"
	wscript.echo
	wscript.echo "C:\ModifierFichier2.vbs -source ""c:\ZZZ.txt"" -cible ""c:\ZZZFichierModifie.txt"""
	wscript.quit
End Sub
Lien vers le fichier : cliquez ici Copier le code

2