Friday, July 22, 2011

VBScript to copy a file from Source directory

The below script is used to copy "vpnclient_setup.msi file" from the Source directory to "[ProgramFilesFolder]Cisco Systems\Install\", if the directory exists and if it doesn't exists, this script will create a folder named "Install" and will copy the file. This is achieved by declaring "SOURCEDIR" as a session property and copying from there.

Note: This script should be placed at the end of the "Execute Immediate" sequence for it to work.

*************************************************

Dim objfso,wshshell,str

Set wshshell = createobject("wscript.shell")

PF = wshshell.expandenvironmentstrings("%ProgramFiles%")

Set objFSO = CreateObject("Scripting.FileSystemObject")

str = Session.Property("SOURCEDIR")

Set oFile1 = objfso.GetFile(str & "\vpnclient_setup.msi")

If objfso.FolderExists(PF & "\Cisco Systems\Install") Then

objFSO.CopyFile oFile1, PF & "\Cisco Systems\Install\", True

Else

Set objFolder = objFSO.CreateFolder (PF & "\Cisco Systems\Install")

objFSO.CopyFile oFile1, PF & "\Cisco Systems\Install\", True

End If

*************************************************

No comments:

Post a Comment