WScript.FullName には、その時使用された Wscript.exe か Cscript.exe の
フルパスが入っていますので、その内容が Wscript.exe であれば、Cscript.exe
で自分自身を実行して、現在の処理は終了してやります。
引数はそのまま全てを文字列に作りなおして呼び出してやるといいです。
Set WshShell = CreateObject( "WScript.Shell" )
' フルパス
strPath = WScript.FullName
strTarget = Right( strPath, 11 )
strTarget = Ucase( strTarget )
' CSCRIPT.EXE で無い場合
if strTarget <> "CSCRIPT.EXE" then
' 自分自身ののフルパス
strMyPath = WScript.ScriptFullName
strParam = " "
' 引数を全て読みだして、スペースが含まれていた場合は再度引き渡す
' 為に " で囲み直しています
For I = 0 to Wscript.Arguments.Count - 1
if instr(Wscript.Arguments(I), " ") < 1 then
strParam = strParam & Wscript.Arguments(I) & " "
else
strParam = strParam & """" & Wscript.Arguments(I) & """ "
end if
Next
Call WshShell.Run( "cscript.exe """ & strMyPath & """" & strParam, 3 )
WScript.Quit
end if
' テストの為 強制的に GUI で結果表示
MsgBox( WScript.FullName )
For I = 0 to Wscript.Arguments.Count - 1
MsgBox( Wscript.Arguments(I) )
Next
関連する記事
VBScript : WEBWSH : Wscript で実行された場合は Cscript で実行しなおす
posted by
at 2010-06-27 12:53
|
VBScript
|

|