WEB に VBScript ライブラリ
特に実用的なコードではありませんし、タイプと言っても WSH か HTA か ASP
なので、使い方が相当違うのでライブラリ側を完全の共用する場合にのみ必要
になって来ます。
Msxml2.ServerXMLHTTP の作成として CreateObject を使っていますが、単純な
スクリプトの場合の場合は必ず最初にこの関数だけはクライアントに必要なので
スクリプトのタイプは無視してどれでも一応実行可能な CreateObject で作成し
ています。
( 本来は、WSH は、WScript.CreateObject で、ASP は、Server.CreateObject )
' 関数のソースコードを読みだして、関数として定義
strResult = HTTPGet( "http://toolbox.winofsql.jp/vbs/createobject.php" )
if not IsEmpty( strResult ) and Left( strResult, 3 ) = "REM" then
' 関数定義の実行
ExecuteGlobal strResult
else
if IsEmpty( strResult ) then
MsgBox(Err.Description)
else
MsgBox(strResult)
end if
Wscript.Quit
end if
' 実行中のスクリプトのタイプ
MsgBox( ScriptType() )
Function HTTPGet( strUrl )
Dim http
Set http = CreateObject( "Msxml2.ServerXMLHTTP" )
on error resume next
Call http.Open("GET", strUrl, False )
if Err.Number <> 0 then
HTTPGet = Empty
Exit Function
end if
on error goto 0
Call http.Send()
HTTPGet = http.responseText
End Function
以下は、php でホスティングしている VBScript の関数です
<?
header( "Content-Type: text/plain; Charset=shift_jis" );
header( "pragma: no-cache" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );
header( "Cache-control: no-cache" );
?>
REM **********************************************************
REM 実行中のスクリプトのタイプの取得
REM 1:WSH, 2:HTA, 3:ASP, 0:不明
REM **********************************************************
Function ScriptType( )
Dim nType
nType = 0
if IsObject( Wscript ) then
nType = 1
else
if IsObject( window ) then
nType = 2
else
if IsObject( Server ) then
nType = 3
end if
end if
end if
ScriptType = nType
End Function
関連する記事
VBScriptの関数定義をWEB上に置いて、Msxml2.ServerXMLHTTP で読みだして PCで使用する