BatchHelper オブジェクトのメソッド等使用方法インストーラのダウンロード 解凍して、setup.wsf を実行します。
<JOB> <OBJECT id="WshShell" progid="WScript.Shell" /> <OBJECT id="Fs" progid="Scripting.FileSystemObject" /> <OBJECT id="Shell" progid="Shell.Application" /> <SCRIPT language=VBScript> ' 管理者として実行を強制する Set obj = Wscript.CreateObject("Shell.Application") if Wscript.Arguments.Count = 0 then obj.ShellExecute "wscript.exe", WScript.ScriptFullName & " runas", "", "runas", 1 Wscript.Quit end if Set obj = GetObject ("winmgmts:\\.\root\cimv2") Set objTargets = obj.ExecQuery( "select AddressWidth from Win32_Processor" ) Dim str For Each objTarget in objTargets str = objTarget.AddressWidth Next strCurPath = WScript.ScriptFullName Set obj = Fs.GetFile( strCurPath ) Set obj = obj.ParentFolder strCurPath = obj.Path Dim Lbox,bLbox,strDir,objExec Set objFolder = Shell.Namespace( &H25 ) Set objFolderItem = objFolder.Self strDir = objFolderItem.Path if str <> "32" then strDir = Replace(Ucase(strDir),"SYSTEM32", "SYSWOW64") end if Wscript.Echo "インストール先 : " & strDir on error resume next ' インストールされているかどうか strValue = WshShell.RegRead("HKCR\Lbox.BatchHelper\CLSID\") if Err.Number = 0 then ' 現在の情報でアンインストール strValue = "HKCR\CLSID\" & strValue strValue = strValue & "\InprocServer32\" strValue = WshShell.RegRead(strValue) strValue = strDir & "\regsvr32.exe /u /s """ & strValue & """" Call WshShell.Run( strValue,,true ) end if on error goto 0 ' カレントファイルをシステムディレクトリにコピー Call Fs.CopyFile( strCurPath & "\lbox.dll", strDir & "\", True ) Call Fs.CopyFile( strCurPath & "\BatchWsc.wsc", strDir & "\", True ) Call Fs.CopyFile( strCurPath & "\imgctl.dll", strDir & "\", True ) Call Fs.CopyFile( strCurPath & "\SaveJPG.dll", strDir & "\", True ) Call Fs.CopyFile( strCurPath & "\TransG32.dll", strDir & "\", True ) ' lbox.dll のインストール strValue = strDir & "\regsvr32.exe """ & strDir & "\lbox.dll""" Call WshShell.Run( strValue,,true ) on error resume next strValue = WshShell.RegRead("HKCR\Lbox.BatchWsc\CLSID\") if Err.Number = 0 then ' 現在の情報でアンインストール strValue = "HKCR\CLSID\" & strValue strValue = strValue & "\ScriptletURL\" strValue = WshShell.RegRead(strValue) strValue = strDir & "\regsvr32.exe scrobj.dll /s /u /n /i:""" & strValue & """" Call WshShell.Run( strValue,,true ) end if on error goto 0 ' BatchWsc.wsc のインストール strValue = strDir & "\regsvr32.exe scrobj.dll /n /i:file://""" & strDir & "\BatchWsc.wsc" & """" Call WshShell.Run( strValue,,true ) </SCRIPT> </JOB>
▼ 以下のようにファイルがシステムディレクトリにコピーされます
' カレントファイルをシステムディレクトリにコピー Call Fs.CopyFile( strCurPath & "\lbox.dll", strDir & "\", True ) Call Fs.CopyFile( strCurPath & "\BatchWsc.wsc", strDir & "\", True ) Call Fs.CopyFile( strCurPath & "\imgctl.dll", strDir & "\", True ) Call Fs.CopyFile( strCurPath & "\SaveJPG.dll", strDir & "\", True ) Call Fs.CopyFile( strCurPath & "\TransG32.dll", strDir & "\", True )
アンインストールは、uninstall.wsf を実行して下さい。( レジストリの情報を削除します ) 以下は、ファイルを開くダイアログの使用例です( 単一ファイルと複数選択 )
Set obj = GetObject ("winmgmts:\\.\root\cimv2") Set objTargets = obj.ExecQuery( "select AddressWidth from Win32_Processor" ) Dim str For Each objTarget in objTargets str = objTarget.AddressWidth Next if str <> "32" then str = WScript.FullName str = Right( str, 11 ) str = Ucase( str ) if str <> "CSCRIPT.EXE" then str = WScript.ScriptFullName Set WshShell = Wscript.CreateObject("WScript.Shell") 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( "c:\windows\SYSWOW64\cmd.exe /c c:\windows\SYSWOW64\cscript.exe """ & str & """" & strParam & " & pause", 3 ) WScript.Quit end if end if Set BatchHelper = Wscript.CreateObject( "Lbox.BatchHelper" ) ' 単一ファイルの選択 Path = BatchHelper.OpenFileName( _ "ファイルを開く", _ "テキスト,*.txt,ログ,*.log,全て,*.*", _ "C:\Windows\Microsoft.NET\Framework" ) ' キャンセルは、空文字が返されます if Path <> "" then BatchHelper.MsgOk( "ファイルが選択されました : " & vbCrLf & Path ) end if ' 複数ファイルの選択 Path = BatchHelper.OpenFileNames( _ "複数ファイルの選択", _ "テキスト,*.txt,ログ,*.log,全て,*.*", _ "C:\Windows\Microsoft.NET\Framework" ) ' キャンセルは、空文字が返されます if Path <> "" then BatchHelper.MsgOk( "ファイルが選択されました : " & vbCrLf & Path ) ' 複数のファイルのパスは、TABコードで分割されます aData = Split(Path, vbTab) BatchHelper.MsgOk("/" & aData(0) & "/") end if