Result = IsComExist( "Lbox.BatchHelper" )
if Result <> "" then
WScript.Echo Result
end if
' **********************************************************' COM が登録されているかどうか' **********************************************************
Function IsComExist( strProgID )
Dim strValue
on error resume next
strValue = WshShell.RegRead("HKCR\" & strProgID & "\CLSID\")
if Err.Number <> 0 then
IsComExist = ""
Exit Function
end if
strValue = "HKCR\CLSID\" & strValue
strValue = strValue & "\InprocServer32\"
strValue = WshShell.RegRead(strValue)
if Err.Number <> 0 then
IsComExist = ""
Exit Function
end if
strValue = WshShell.ExpandEnvironmentStrings( strValue )
on error goto 0
IsComExist = strValue
End Function
システムディレクトリの取得
Shell.Application を使用すると、システムディレクトリを取得できます
WScript.Echo GetSystemDirectory( )
' **********************************************************' システムディレクトリの取得' **********************************************************
Function GetSystemDirectory( )
Dim obj
Set obj = CreateObject( "Shell.Application" )
Set objFolder = obj.Namespace( &H25 )
Set objFolderItem = objFolder.Self
GetSystemDirectory = objFolderItem.Path
End Function
' **********************************************************' Windows Script Component が登録されているかどうか' **********************************************************
Function IsWscExist( strProgID )
Dim strValue
on error resume next
strValue = WshShell.RegRead("HKCR\" & strProgID & "\CLSID\")
if Err.Number <> 0 then
IsWscExist = ""
Exit Function
end if
strValue = "HKCR\CLSID\" & strValue
strValue = strValue & "\ScriptletURL\"
strValue = WshShell.RegRead(strValue)
if Err.Number <> 0 then
IsWscExist = ""
Exit Function
end if
on error goto 0
IsWscExist = Right( strValue, Len( strValue ) - 7 )
End Function
以下に、COM を処理した後に継続して実行するコードを示します
' ----------------------------------------------------------' Windows Script Component' ----------------------------------------------------------
strProg = "BatchWsc.wsc"
nStep = 8
strTarget = IsWscExist( "Lbox.BatchWsc" )
if strTarget = "" then
nNextStep = 12
end if
nStep = 9
if nStep >= nNextStep then
WScript.Echo strProg & _
" を既に登録されているパスで存在チェック"
if Fso.FileExists( strTarget ) then
nNextStep = 11
end if
end if
nStep = 10
if nStep >= nNextStep then
WScript.Echo strProg & _
" を登録されているパスへコピー (" & _
strTarget & ")"
Call Fso.CopyFile( strProg, strTarget )
end if
nStep = 11
if nStep >= nNextStep then
strCommand = "regsvr32.exe scrobj.dll /u /n "
strCommand = strCommand & "/i:""file://" & strTarget & """"
WScript.Echo strProg & _
" が正しく登録されているのでいったん登録解除 (" & _
strCommand & ")" ' 実行終了を待つ
Call WshShell.Run( strCommand,,True )
end if
nStep = 12
if nStep >= nNextStep then
strTarget = GetSystemDirectory( )
WScript.Echo strProg & _
" をシステムディレクトリへコピー (" & _
strTarget & ")"
if strTarget = "" then
WScript.Echo ErrMessage
WScript.Quit
end if
Call Fso.CopyFile( strProg, strTarget & "\" & strProg )
end if
nStep = 13
if nStep >= nNextStep then
strCommand = "regsvr32.exe scrobj.dll /n "
strCommand = strCommand & "/i:""file://"
strCommand = strCommand & strTarget & "\" & strProg & """"
WScript.Echo strProg & _
" をシステムディレクトリの登録ファイルで登録します (" & _
strCommand & ")" ' 実行終了を待つ
Call WshShell.Run( strCommand,,True )
end if
WScript.Echo EndMessage