这是来自我已经隐藏起来的 Usenet 帖子。
来自:“Matt Williamson”
新闻组:alt.msdos.batch.nt
主题:回复:通过 VBScript 发送电子邮件
日期:2007 年 7 月 16 日星期一 09:58:19 -0400
@echo off
:BrowseFolder
set Result=
set input=%1
:: Temporary files
set vbs=%temp%\_.vbs
set tmp=%temp%\_.cmd
:: Build VBScript file
findstr "'%skip%VBS" "%~f0" > "%vbs%"
:: Run the script with WSH
cscript //nologo "%vbs%" > "%tmp%"
:: Read the output file and set Path as Env variable %Result%
for /f "delims=" %%a in (%tmp%) do %%a
echo %result% & pause
DEL %VBS%
DEL %TMP%
endlocal & goto :EOF
'
'.......................................................
'The Visual Basic Script
'
set WshShell=WScript.CreateObject("WScript.Shell") 'VBS
set shell=WScript.CreateObject("Shell.Application") 'VBS
sInput=WshShell.ExpandEnvironmentStrings("%input%") 'VBS
set folder=shell.BrowseForFolder(0,replace(sInput,chr(34),""),0) 'VBS
if typename(folder)="Nothing" Then 'VBS
wscript.echo "set Result=Dialog Cancelled" 'VBS
WScript.Quit(1) 'VBS
end if 'VBS
set folderItems=folder.Items() 'VBS
set folderItem=folderItems.Item() 'VBS
pathname=folderItem.Path 'VBS
wscript.echo "set Result="& chr(34) & pathname & chr(34) 'VBS