PATHEXT環境變量簡介
?
?
??? 最近在機子上裝了一些軟件之后,機子出了點問題,所有的exe工具文件(甚至包括一些cmd下的命令),都無法直接打開執行了,必須要輸全整個文件名,例如 sqlplus.exe 。在問了一圈同事之后(不包括我們的系統管理員),居然還是沒有一個準確的答案。最后詢問了系統管理員之后,發現只是因為簡單的環境變量設置問題,真是感嘆大家對操作系統的白癡了 -_-|||
?
??? 在網上找了點資料看一下,簡單介紹介紹PATHEXT這個環境變量,順便就當練習英文了。
?
----------------------
?
Windows XP’s Run command provides a quick and easy way for experienced users to open files without the need to navigate through the Start menu or browse folders looking for a file. For example, if you type cmd.exe at the Run command and press Enter, a Command Prompt windows will open. Type msconfig.exe and the System Configuration Utility does the same.
?
You may also be aware of the fact that its not always necessary to enter certain file extensions when using the Run command. For example, entering just the filename portion of the command - say, cmd rather than cmd.exe - if OK because the EXE file extension is one of those tried by XP when an extension isn’t supplied. XP will attempt to use a number of file extensions when you don’t provide one, as dictated by it’s declared PATHEXT variables.
?
By default, the following PATHEXT system variables are declared by XP: .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH. One notable one that isn’t present is the .MSC extension used by saved MMC consoles. If you want pre-built consoles like the Services MMC to open without needing to type its full filename - services.msc - at the Run command, then you’ll need to add .MSC to the XP’s PATHEXT variable.
?
To add a new file extension to XP’s PATHEXT system variable, follow these steps:
?
1. Open the System applet in Control Panel.
2. Click the Advanced tab, and then click the Environment Variables button.
3. Double-click the PATHEXT variable in the System variables section and then click Edit.
4. After the .WSH entry, type a semi-colon and then type .MSC (no spaces required) and then click OK.
5. Reboot your system and then attempt to open the Services MMC from the Run command by simply typing services and then click OK.
----------------------
?
??? Windows XP的“運行”命令為一些有經驗的用戶提供了一個簡單快速的方法來打開文件,而不再需要通過“開始”目錄,或在文件夾中尋找文件。例如:當我再“運行”窗口中輸入 cmd.exe 并點擊確定時,命令行窗口就直接被打開了。同樣的,輸入 msconfig.exe 后,可以直接打開“系統配置”界面。
?
??? 其實很多人都知道,當使用“運行”命令時,并不需要總是輸入某些文件的擴展名的,例如只輸入文件名部分,用cmd代替cmd.exe即可。如果這樣可以,那是因為EXE文件擴展名是XP中的可靠擴展名而無須提供。當你沒有輸入擴展名時,XP會嘗試幾種默認擴展名,這些XP默認的擴展名就在PATHEXT變量中聲明。
?
??? PATHEXT系統變量默認的聲明如下:.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH 。需要注意的是 .MSC 擴展名并不在此之列。這個后綴的文件用來打開XP的管理控制臺。如果你希望打開類似Services這類MMC文件,而不在“運行”窗口輸入文件全名(services.msc),那么就需要將.MSC 添加到XP的PATHEXT變量中。
?
??? 要增加一個新的文件擴展名到XP的PATHEXT變量中的步驟如下:
?
??? 1、打開控制面板 - 性能和維護 - 系統
??? 2、點擊“高級”,再點擊“環境變量”按鈕
??? 3、在系統變量列表中,雙擊PATHEXT變量并點擊“編輯”按鈕
??? 4、在.WSH后面輸入一個分號,再輸入.MSC,然后點擊“確定”
??? 5、重啟系統后嘗試不加擴展名打開services.msc
?
----------------------
?
??? 其實對于PATHEXT的性質來說,還可以用來做一些其他的用途,例如在網上看到的一個,不希望別人在自己機子上使用ping、net等命令,就可以通過修改PATHEXT中的文件擴展名排列順序來實現,主要就是因為XP系統在自己匹配默認擴展名是是根據PATHEXT中的排列順序依次進行的,簡單講一講做法:
?
??? 首先將PATHEXT中的擴展名排列順序修改為.BAT排在最前,然后創建ping.bat、net.bat文件,存放到%SystemRoot%\system32(即存放ping.exe、net.exe的地方),bat中的內容如下:
?
@echo off
echo '%0' 不是內部或外部命令,也不是可運行的程序
echo? 或批處理文件。
?
??? 這樣,當在cmd下輸入ping之后,由于未加后綴,導致windows自己匹配,在首先匹配到ping.bat之后執行該文件,在前段顯示該命令不存在的信息,這樣就可以簡單欺騙不熟悉系統的用戶(比如說我)。當然自己用的時候,輸全ping.exe來執行命令就可以了。
?
?