2016-02-26 81 views
-1

因此,我使用AutoHotKey來安全地使用here中的腳本刪除我的USB設備。與單擊任務欄中的項目相比,唯一的缺點是後者會顯示一條消息,或者像「您現在可以安全地移除設備」或「您的設備正忙,現在無法彈出」,而AHK腳本會不。是否有可能使AutoHotKey在(成功)卸載USB設備時顯示消息?

問題是:是否有可能/如何通過AHK彈出時顯示此類消息?或者,分解任務,如何a)檢查驅動器是否成功卸載並b)顯示相應的消息?

(我知道,將適當要求在線程1,但我有問題,註冊在那裏,一些過濾器不允許使用我的郵件/ IP登記,不記得確切)

+0

什麼是在這些情況下的ErrorLevel的值是多少? – 2501

+0

好的,感謝Forivin,我現在明白,使用語法'MsgBox,我的消息沒有必要的引號符號'顯示消息。在每個返回位置之前,我已經添加了4條消息,第一條有意義的是'MsgBox,看起來像沒有E驅動器。「和其他人進行進一步調查。現在我理解了AHK的語法,但仍然不知道ErrorLevel是什麼(或如何使用它)。我猜如果最後一個'返回'已經到達,彈出成功完成了,但我會測試一下。 – YakovL

回答

2

在它說螺紋:

的ErrorLevel
-1無效的驅動器號。
-2既不是CD/DVD驅動器,也不是USB大容量存儲設備。
-3彈出失敗。請參閱A_LastError(範圍1 - 13)至identify the reason。最常見的將是A_LastError = 6這是
PNP_VetoOutstandingOpen請求的操作因未解決的打開句柄而被拒絕。

所以,我要說,這應該做的工作:

USB_ERROR_LIST := [ "The specified operation was rejected for an unknown reason." 
        , "The device does not support the specified PnP operation." 
        , "The specified operation cannot be completed because of a pending close operation." 
        , "A Microsoft Win32 application vetoed the specified operation." 
        , "A Win32 service vetoed the specified operation." 
        , "The requested operation was rejected because of outstanding open handles." 
        , "The device supports the specified operation, but the device rejected the operation." 
        , "The driver supports the specified operation, but the driver rejected the operation." 
        , "The device does not support the specified operation." 
        , "There is insufficient power to perform the requested operation." 
        , "The device cannot be disabled." 
        , "The driver does not support the specified PnP operation." 
        , "The caller has insufficient privileges to complete the operation." ] 

#vk4A:: 
    Eject("D:") 
    If (ErrorLevel = -1) 
     MsgBox, Invalid drive letter. 
    Else If (ErrorLevel = -2) 
     MsgBox, Neither a CD/DVD drive, nor a USB Mass Storage device. 
    Else If (ErrorLevel = -3) { 
     MsgBox, % "Eject failed:`n" USB_ERROR_LIST[A_LastError] 
    } Else { 
     MsgBox, The USB device can now be safely removed from the computer. 
    } 
Return 
+0

您能否介紹一下更詳細的使用方法?目前我使用'Eject'這個方法:'#vk4A :: Eject(「E」)';我在哪裏可以放置這些額外的線路,以及如何處理「MsgBox,USB設備現在可以安全移除」的「無錯誤」情況?我已經改變了函數本身的內容,但似乎你暗示了其他一些技巧。 – YakovL

+0

... Eject調用在If語句之前進行。對於沒有錯誤的情況,在If語句中添加一個「Else」。 – Forivin

+0

看起來你的建議是正確的,但腳本存在問題。我試圖在我的USB記憶棒上打開一個文檔,並通過按鍵梳理彈出後者 - 它告訴我「現在可以安全地移除USB設備[..]」,但很明顯,它實際上可以' t(它不會根據任務欄/資源管理器彈出)。同樣的故事,如果我在'Eject'裏面添加'Msg',在每個'return'之前(必要時添加括號),並且在最後一個'return'之前添加'Msg',這兩種情況都會在USB彈出和不在時顯示(因爲該文檔被打開)。 – YakovL

相關問題