たぶん、普通にWindows アップデートとかされておれば、Framework 3.5 用の VB をビルドするコンパイラである vbc.exe が使えるとおもうのですが、そのvbc.exe を使った簡単なビルドセットです。
@echo off setlocal set PATH=%windir%\Microsoft.NET\Framework\v3.5;%PATH% vbc httpdownload.vb
バッチファイルを使って現在の環境に影響しないように一時的に環境変数をセットしてビルドします。Framework2.0 用も用意しており、おまけとしてC# 用のコードも付加しています。 プログラムが解らない人は、httpdownload.exe をそのままお使いいただけます。 httpdownload.exe URL "ローカルパス" [s] ※ s を指定しないと、ダウンロードしたディレクトリをエクスプローラで開きます
Imports System.IO ' Path Imports System.Diagnostics ' Process Imports System.Runtime.InteropServices ' DllImport Module MyModule <DllImport("urlmon.dll", CharSet:=CharSet.Unicode)> _ Private Function URLDownloadToFile( _ ByVal pCaller As Integer, _ ByVal szURL As String, _ ByVal szFileName As String, _ ByVal dwReserved As Integer, _ ByVal lpfnCB As Integer _ ) As Integer End Function ' ********************************** ' * Win32 API でHTTPダウンロード ' ********************************** Sub Main() Dim argv As String() argv = System.Environment.GetCommandLineArgs() Dim ret As Integer Dim str As String If argv.Length >= 3 Then ret = URLDownloadToFile( 0, argv(1), argv(2), 0, 0 ) if ret = 0 then str = Path.GetFullPath( argv(2) ) str = Path.GetDirectoryName( str ) if argv.Length = 4 then if argv(3) = "s" then else ' 第3引数に s を指定しない場合は ' エクスプローラを開く Process.Start("explorer.exe","/e,"+str) end if else ' 第3引数に s を指定しない場合は] ' エクスプローラを開く Process.Start("explorer.exe","/e,"+str) end if end if end if End Sub End Module ' 古い vb の定義 ' Private Declare Function URLDownloadToFile Lib "urlmon" Alias _ ' "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal _ ' szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long ' ▼ ' http://support.microsoft.com/kb/244757/ja
VB の中は、Framework では無く Win32API を使っています。URLDownloadToFile という単純な API があるので、簡単ですが、VC でビルドするには環境設定がたいへんですが、VB.net だととても簡単なので。
************************************************************ * httpdownload.exe * ( http ダウンローダ ) ************************************************************ ************************************************************ * 実行方法 ************************************************************ そのまま使う場合は、以下のように指定します httpdownload.exe ダウンロードURL "ダウンロードパス" [s] ダウンロードパスは、a.lzh のようにカレントでもかまいません s を指定しないと、ダウンロード後にエクスプローラが起動してダウンロードしたディレクトリを開きます ************************************************************ * 自分でビルドしたい場合 ************************************************************ Framework3.5 でビルドする場合は、build_35.bat を実行します。以下のファイルがあれば動作するばずです C:\WINDOWS\Microsoft.NET\Framework\v3.5\vbc.exe ■ 同梱している httpdownload.exe は、3.5 でビルドしています Framework2.0 でビルドする場合は、build_2.bat を実行します。以下のファイルがあれば動作するばずです C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\vbc.exe ************************************************************ * ソースコード ************************************************************ ■ httpdownload.vb ■ httpdownload2.cs C# 用です。build_35.bat が動く場合、vbbuild_35_cs.bat でビルドできるはずです ************************************************************ * その他 ************************************************************ ■ 著作権その他 このプログラムはフリーです。どうぞ自由に御使用ください。 著作権は作者である私(lightbox)が保有しています。 また、本ソフトを運用した結果については、作者は一切責任を 負えせんのでご了承ください。
以下は C# のコードですが、VB.NET -> C# 変換 で変換してビルドすると少しだけエラーが出るので修正してあります
using System.IO; using System.Diagnostics; using System.Runtime.InteropServices; static class MyModule { [DllImport("urlmon.dll", CharSet = CharSet.Unicode)] private static extern int URLDownloadToFile(int pCaller, string szURL, string szFileName, int dwReserved, int lpfnCB); // ********************************** // * Win32 API でHTTPダウンロード // ********************************** public static void Main() { string[] argv = null; argv = System.Environment.GetCommandLineArgs(); int ret = 0; string str = null; if (argv.Length >= 3) { ret = URLDownloadToFile(0, argv[1], argv[2], 0, 0); if (ret == 0) { str = Path.GetFullPath(argv[2]); str = Path.GetDirectoryName(str); if (argv.Length == 4) { if (argv[3] == "s") { } else { // 第3引数に s を指定しない場合は // エクスプローラを開く Process.Start("explorer.exe", "/e," + str); } } else { // 第3引数に s を指定しない場合は] // エクスプローラを開く Process.Start("explorer.exe", "/e," + str); } } } } } // 古い vb の定義 // Private Declare Function URLDownloadToFile Lib "urlmon" Alias _ // "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal _ // szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long // ▼ // http://support.microsoft.com/kb/244757/ja