有時候,一些本地命令,比如net.exe,在執行過程中,會返回數字編號形式的錯誤信息。很郁悶的是,我們不知道這些數字代表什么意思。以前,我們可以使用如下的方式去獲取數字代表的信息:
代碼如下:
PS> net helpmsg 3534
The service did not report an error.
PS> net helpmsg 1
Incorrect function.
PS> net helpmsg 4323
The transport cannot access the medium.
其實有一個更好的方法,那就是使用winrm.exe,它不僅可以實現上面的功能,而且還要更加強大!同樣的,看看對上面三個錯誤的翻譯:
代碼如下:
PS> winrm helpmsg 3534
The service did not report an error.
PS> winrm helpmsg 1
Incorrect function.
PS> winrm helpmsg 4323
The transport cannot access the medium.
OK,看到了吧,結果是一樣的。其實,net.exe只能翻譯中一個特定規范內的錯誤信息(具體怎么樣一個特定的規范,洪哥也不是很清楚),而winrm.exe則要更加強大,比如它可以轉換“特定的遠程”錯誤代碼:
代碼如下:
PS> winrm helpmsg 0x80338104
The WS-Management service cannot process the request. The WMI service returned an 'access denied' error.
PS> net helpmsg 0x80338104
The syntax of this command is:
NET HELPMSG
message#
上面可以看出來,winrm.exe正確的翻譯出了0x80338104的錯誤信息,而net.exe沒有做到。其實,這個命令可能跟PowerShell沒有什么直接的關系,但也算是一個Shell命令吧,我們可以使用它去翻譯任何低級的API錯誤代碼,并且堅定的相信它得到的結果。
新聞熱點
疑難解答