2008年2月7日木曜日

[VBScript]CABファイルの作成

'* VBScript ********************************************************************
'
' 名称: sample_create_cab.vbs
'
' 作成者:
'
' 履歴:
'
' 説明: CABファイルの作成。
'
'*******************************************************************************

Option Explicit

'===============================================================================
'
' 名称: CreateCab
'
' 説明: CABファイルの作成
'
' 引数: sSrcPath 圧縮元のファイル
' sDstPath 圧縮先のファイル(CABファイル)
'
' 戻り値: 成功...True 失敗...True
'
'===============================================================================
Function CreateCab(sSrcPath, sDstPath)

Dim oCAB
Dim oShell

CreateCab = False

Set oCAB = WScript.CreateObject("MakeCab.MakeCab.1")
Set oShell = WScript.CreateObject("WScript.Shell")

On Error Resume Next

Call oCAB.CreateCab(sDstPath,False,False)
If Err.Number <> 0 Then
If Err.Number = 450 Then
Call oCAB.CreateCab(sDstPath,False,False,False)
Err.Clear
Else
Call oShell.LogEvent( 1, Err.Number & " " & Err.Description )
Err.Clear
Exit Function
End If
End If
Call oCAB.AddFile(sSrcPath,sSrcPath)
Call oCAB.CloseCab()


On Error GoTo 0

Set oShell = Nothing
Set oCAB = Nothing

CreateCab = True

End Function

Const cSrcPath = "c:\sample.txt"
Const cDstPath = "c:\sample.cab"

If CreateCab(cSrcPath, cDstPath) Then
WScript.Echo("成功")
Else
WScript.Echo("失敗")
End If

0 件のコメント: