Thursday 26 April 2018

VB Script: UnZip a compressed folder using script.

Have faced issues on deploying an application through SCCM, Install source has many sub-directories within it and getting long file path name error while copying to Distribution point from file-share.
so zipped the whole source and written a script to unzip the install file,Directories before starting the installation using script.

Below are the sample script to UnZip a zipped folder.

Script:
Option Explicit
Dim input,oshell,scriptpath
Dim intOptions, objShell, objSource, objTarget
Set oShell = WScript.CreateObject("WScript.Shell")
ScriptPath = Left(WScript.ScriptFullName, InstrRev(WScript.ScriptFullName, "\"))
oShell.CurrentDirectory = ScriptPath

Input = InputBox("Enter your Zip file name","UnZipping Folder!!!")
Extract Scriptpath & input &".zip", scriptpath

Sub Extract( ByVal myZipFile, ByVal myTargetDir )
    Set objShell = CreateObject( "Shell.Application" )
    Set objSource = objShell.NameSpace( myZipFile ).Items( )
    Set objTarget = objShell.NameSpace( myTargetDir )
    intOptions = 20
    objTarget.CopyHere objSource, intOptions
   
    Set objSource = Nothing
    Set objTarget = Nothing
    Set objShell  = Nothing

End Sub

Steps to DO:
1. Copy code and save the script as XXX.vbs
2. Run the script as Administrator.
3. Enter the Zip file Name without extension.

4. Click Ok, it will UnZip the folder on your script directory.

Note: Keep the Zipped folder along with your script to run without errors.

No comments:

Post a Comment