用vbs创建隐藏的txt文件

create hidden txt file with vbs

我目前有一个 vbscript 可以在一个目录中创建一个 txt 文件并打开它,但我喜欢这样做以便隐藏该文件, 目前我有这个代码:

Set objFSO=CreateObject("Scripting.FileSystemObject")

outFile="C:\Users\User\Desktop\New map"
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.Write "test line 1" & vbCrLf
objFile.Write "test line 2" & vbCrLf
objFile.Close

CreateObject("WScript.Shell").Run("""C:\Users\User\Desktop\New map""")

你可以这样设置属性

Const cHidden = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")

outFile = "C:\Users\User\Desktop\New map"
Set objFile = objFSO.CreateTextFile(outFile, True)
objFile.Write "test line 1" & vbCrLf
objFile.Write "test line 2" & vbCrLf
objFile.Close

Set mapFile = objFSO.GetFile(outFile)
mapFile.Attributes = cHidden

CreateObject("WScript.Shell").Run Chr(34) & outFile & Chr(34)

快速参考 --> https://www.thevbprogrammer.com/ch06/06-09-fso.htm https://ss64.com/vb/filesystemobject.html