示范NTFS 卷上的流

' CreateStream.vbs
' 示范 NTFS 卷上的流
' --------------------------------------------------------
Option Explicit
' 一些常量
Const L_NotNTFS = "Sorry, the current volume is not NTFS."
Const L_EnterFile = "Enter a file name"
Const L_TestNTFS = "Test NTFS"
Const L_StdFile = "c:\testntfs\test.txt"
Const L_EnterStream = "Enter a stream name"
Const L_StdStream = "VersionInfo"
Const L_EnterTextStream = "Enter the text of the stream"
Const L_StdContent = "1.0"
' 确保当前的卷是 NTFS
if Not IsNTFS() then
MsgBox L_NotNTFS
WScript.Quit
end if
' 查询文件名
dim sFileName
sFileName = InputBox(L_EnterFile, L_TestNTFS, L_StdFile)
if sFileName = "" then WScript.Quit
' 查询写入的流
dim sStreamName
sStreamName = InputBox (L_EnterStream, L_TestNTFS, L_StdStream)
if sStreamName = "" then WScript.Quit
' 初始化 FS 对象模式
dim fso, bExist
set fso = CreateObject("Scripting.FileSystemObject")
' 如果文件不存在,则创建它
dim ts
if Not fso.FileExists(sFileName) then
set ts = fso.CreateTextFile(sFileName)
ts.Close
end if
' 尝试读取流的当前内容
dim sFileStreamName, sStreamText
sFileStreamName = sFileName & ":" & sStreamName
if Not fso.FileExists(sFileStreamName) then
sStreamText = L_StdContent
else
set ts = fso.OpenTextFile(sFileStreamName)
sStreamText = ts.ReadAll()
ts.Close
end if
' 查询写入的流的内容
sStreamText = InputBox (L_EnterTextStream, L_TestNTFS, sStreamText)
if sStreamText = "" then WScript.Quit
' 尝试写入流中
set ts = fso.CreateTextFile(sFileStreamName)
ts.Write sStreamText
' 关闭应用程序
set ts = Nothing
set fso = Nothing
WScript.Quit
' ////////////////////////////////////////////////////////
' //“帮助程序”函数</PRE>
' IsNTFS() — 验证当前的卷是否为 NTFS
' --------------------------------------------------------
function IsNTFS()
dim fso, drv
IsNTFS = False
set fso = CreateObject("Scripting.FileSystemObject")
set drv = fso.GetDrive(fso.GetDriveName(WScript.ScriptFullName))
set fso = Nothing
if drv.FileSystem = "NTFS" then IsNTFS = True
end function
posted @ 2006-05-09 17:12  Max Woods  阅读(279)  评论(0编辑  收藏  举报