ファイル選択ダイアログを開く

  InternetExplorer.Application の利用



スクリプトからファイル選択ダイアログを開く方法は、XP を除く OS では正式に用意されていません。ですから、完全なコントロールはできませんが、InternetExplorer.Application を使用するとなんとか使う事ができます
( 但し Cscript.exe からは実行できません )

' 管理者として実行を強制する
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 Fso = WScript.CreateObject( "Scripting.FileSystemObject" )
' テンポラリフォルダ
TempDir =  Fso.GetSpecialFolder(2)
on error resume next
' テンポラリフォルダに空の "local.htm" を作成
Set objHandle = Fso.CreateTextFile( TempDir & "\local.htm", True, True )
if Err.Number <> 0 then
	Wscript.Quit
end if
objHandle.Close
on error goto 0

' IE を操作するオブジェクト
Set IEDocument = WScript.CreateObject( "InternetExplorer.Application" )
' テンポラリフォルダに作成したファイルを開く
IEDocument.Navigate( TempDir & "\local.htm" )
' 『ファイルを開く』為のコンテンツを作成
IEDocument.document.getElementsByTagName("BODY")(0).innerHTML = "<input id=FilePath type=file>"
' 『ファイルを開く』為に、ボタンをクリックする
IEDocument.document.getElementById("FilePath").click
' ファイルを選択していない場合は終了
if IEDocument.document.getElementById("FilePath").value = "" then
	OpenLocalFileName = ""
	IEDocument.Quit
	Set IEDocument = Nothing
	Wscript.Quit
end if

' 選択したファイルのパスを戻す
Wscript.Echo IEDocument.document.getElementById("FilePath").value

' IE を終了
IEDocument.Quit
Set IEDocument = Nothing








  UserAccounts.CommonDialog



Windows XP は以下のようにして実現できます

  
Set objDialog = CreateObject("UserAccounts.CommonDialog")

objDialog.Filter = "全て|*.*|テキスト|*.txt"
objDialog.InitialDir = "C:\"
nRet = objDialog.ShowOpen
 
if nRet = 0 then
	Wscript.Quit
End If

WScript.Echo objDialog.FileName
  

Microsoft へのリンク










  infoboard   管理者用   
このエントリーをはてなブックマークに追加





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ