簡體   English   中英

VBScript說“此應用程序沒有與指定文件關聯”?

[英]VBScript saying “No Application is associated with the specified file for this operation”?

我正在編寫一個簡單的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)(空):此應用程序沒有與指定文件關聯。

據我所知,我確實在做在線示例告訴我的事情,但我似乎無法復制它。 我究竟做錯了什么?

我運行了您的腳本,它在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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM