VBScript说;没有应用程序与此操作的指定文件相关联";?

VBScript说;没有应用程序与此操作的指定文件相关联";?,vbscript,Vbscript,我正在编写一个简单的VBScript,以便使用eventcreate写入自定义windows事件日志 FOR I = 0 to 5 Set WshShell = WScript.CreateObject("WScript.Shell") strCommand = "eventcreate /l Application /t Information /so Test-Log /id 66 /d TEST" WshShell.Run strCommand Next 但是,每

我正在编写一个简单的VBScript,以便使用eventcreate写入自定义windows事件日志

FOR I = 0 to 5
    Set WshShell = WScript.CreateObject("WScript.Shell")
    strCommand = "eventcreate /l Application /t Information /so Test-Log /id 66 /d TEST"
    WshShell.Run strCommand
Next
但是,每当我尝试通过命令提示符运行它时,都会收到以下消息:

C:\testlog.vbs(6,5)(null):没有应用程序与此操作的指定文件关联


据我所知,我所做的正是在线示例告诉我要做的,我似乎无法复制它。我做错了什么?

我运行了你的脚本,它在win 7笔记本电脑上按预期工作。确保您正在运行具有管理员权限的脚本。我稍微修改了脚本,将
Set
语句移出
for…Next
循环。无需在每个循环上继续设置
WshShell
对象,在本例中,为整个脚本设置一次即可

Dim WshShell, strCommand 
Set WshShell = WScript.CreateObject("WScript.Shell")
For I = 0 to 5
    strCommand = "eventcreate /l Application /t Information /so Test-Log /id 66 /d TEST"
    WshShell.Run strCommand
Next

我运行了你的脚本,它在Win7笔记本电脑上按预期工作。确保您正在运行具有管理员权限的脚本。我稍微修改了脚本,将
Set
语句移出
for…Next
循环。无需在每个循环上继续设置
WshShell
对象,在本例中,为整个脚本设置一次即可

Dim WshShell, strCommand 
Set WshShell = WScript.CreateObject("WScript.Shell")
For I = 0 to 5
    strCommand = "eventcreate /l Application /t Information /so Test-Log /id 66 /d TEST"
    WshShell.Run strCommand
Next

我不知道发生了什么事。我重新启动了电脑,然后它工作正常。谢谢你的回答!我不知道发生了什么事。我重新启动了电脑,然后它工作正常。谢谢你的回答!