在 Windows 启动时将 vbscript 输出到文本

vbscript output to text on wndows startup

我正在寻找执行以下任务的 vbscript

脚本任务

  1. 在计算机启动时执行,
    执行的方式是将它放在 windows 的启动文件夹中 C:\Documents and Settings\Admin\Start Menu\Programs\Startup

  2. 如果输出文本文件存在,写下一些文本并退出

  3. 如果文本文件不存在,那么它会回显完整的目标

代码已提供,如有任何帮助,我们将不胜感激

'create txt.vbs
'vbscript
Set WshShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
CurrentDirectory = objFSO.GetAbsolutePathName(".")
FilePath = CurrentDirectory & "\test.txt"

Existcode = objFSO.FileExists(FilePath)
' wscript.echo "FileExists code:" & Existcode

if Existcode = False then
    Existcode = objFSO.FileExists(FilePath)
    'for debugging
    wscript.echo "file not exist" & vbCrLf _
    & "FileExists code:" & Existcode

    Set objFile = objFSO.CreateTextFile(FilePath,True)
    strtext = "file created:" & vbCrLf & chr(34) & "New Line" & chr(34)
    objFile.Write strtext & vbCrLf
    objFile.Close
else
    'for debugging
    wscript.echo "file exist" & vbCrLf _
    & "FileExists code:" & Existcode & vbCrLf & vbCrLf _
    & FilePath & vbCrLf _
    & CurrentDirectory & vbCrLf
end if
wscript.echo "end"

当通过 单击 执行时,通过 批处理文件 ,脚本可以正常工作,输出如下预计

while it's executed from startup folder by windows, it show all echo that i set for debugging but doesn't create the output file neither write to text in it, but also it read it as exist i'm not sure why

vbscript 无法将文本写入启动文件夹, 然而变化如下

CurrentDirectory = objFSO.GetAbsolutePathName(".")
FilePath = CurrentDirectory & "\test.txt"

成为

DesktopDirectory = WshShell.SpecialFolders("Desktop")
FilePath = DesktopDirectory & "\test.txt"