PATHEXT環(huán)境變量簡介
?
?
??? 最近在機(jī)子上裝了一些軟件之后,機(jī)子出了點(diǎn)問題,所有的exe工具文件(甚至包括一些cmd下的命令),都無法直接打開執(zhí)行了,必須要輸全整個(gè)文件名,例如 sqlplus.exe 。在問了一圈同事之后(不包括我們的系統(tǒng)管理員),居然還是沒有一個(gè)準(zhǔn)確的答案。最后詢問了系統(tǒng)管理員之后,發(fā)現(xiàn)只是因?yàn)楹唵蔚沫h(huán)境變量設(shè)置問題,真是感嘆大家對操作系統(tǒng)的白癡了 -_-|||
?
??? 在網(wǎng)上找了點(diǎn)資料看一下,簡單介紹介紹PATHEXT這個(gè)環(huán)境變量,順便就當(dāng)練習(xí)英文了。
?
----------------------
?
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的“運(yùn)行”命令為一些有經(jīng)驗(yàn)的用戶提供了一個(gè)簡單快速的方法來打開文件,而不再需要通過“開始”目錄,或在文件夾中尋找文件。例如:當(dāng)我再“運(yùn)行”窗口中輸入 cmd.exe 并點(diǎn)擊確定時(shí),命令行窗口就直接被打開了。同樣的,輸入 msconfig.exe 后,可以直接打開“系統(tǒng)配置”界面。
?
??? 其實(shí)很多人都知道,當(dāng)使用“運(yùn)行”命令時(shí),并不需要總是輸入某些文件的擴(kuò)展名的,例如只輸入文件名部分,用cmd代替cmd.exe即可。如果這樣可以,那是因?yàn)镋XE文件擴(kuò)展名是XP中的可靠擴(kuò)展名而無須提供。當(dāng)你沒有輸入擴(kuò)展名時(shí),XP會嘗試幾種默認(rèn)擴(kuò)展名,這些XP默認(rèn)的擴(kuò)展名就在PATHEXT變量中聲明。
?
??? PATHEXT系統(tǒng)變量默認(rèn)的聲明如下:.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH 。需要注意的是 .MSC 擴(kuò)展名并不在此之列。這個(gè)后綴的文件用來打開XP的管理控制臺。如果你希望打開類似Services這類MMC文件,而不在“運(yùn)行”窗口輸入文件全名(services.msc),那么就需要將.MSC 添加到XP的PATHEXT變量中。
?
??? 要增加一個(gè)新的文件擴(kuò)展名到XP的PATHEXT變量中的步驟如下:
?
??? 1、打開控制面板 - 性能和維護(hù) - 系統(tǒng)
??? 2、點(diǎn)擊“高級”,再點(diǎn)擊“環(huán)境變量”按鈕
??? 3、在系統(tǒng)變量列表中,雙擊PATHEXT變量并點(diǎn)擊“編輯”按鈕
??? 4、在.WSH后面輸入一個(gè)分號,再輸入.MSC,然后點(diǎn)擊“確定”
??? 5、重啟系統(tǒng)后嘗試不加擴(kuò)展名打開services.msc
?
----------------------
?
??? 其實(shí)對于PATHEXT的性質(zhì)來說,還可以用來做一些其他的用途,例如在網(wǎng)上看到的一個(gè),不希望別人在自己機(jī)子上使用ping、net等命令,就可以通過修改PATHEXT中的文件擴(kuò)展名排列順序來實(shí)現(xiàn),主要就是因?yàn)閄P系統(tǒng)在自己匹配默認(rèn)擴(kuò)展名是是根據(jù)PATHEXT中的排列順序依次進(jìn)行的,簡單講一講做法:
?
??? 首先將PATHEXT中的擴(kuò)展名排列順序修改為.BAT排在最前,然后創(chuàng)建ping.bat、net.bat文件,存放到%SystemRoot%\system32(即存放ping.exe、net.exe的地方),bat中的內(nèi)容如下:
?
@echo off
echo '%0' 不是內(nèi)部或外部命令,也不是可運(yùn)行的程序
echo? 或批處理文件。
echo '%0' 不是內(nèi)部或外部命令,也不是可運(yùn)行的程序
echo? 或批處理文件。
?
??? 這樣,當(dāng)在cmd下輸入ping之后,由于未加后綴,導(dǎo)致windows自己匹配,在首先匹配到ping.bat之后執(zhí)行該文件,在前段顯示該命令不存在的信息,這樣就可以簡單欺騙不熟悉系統(tǒng)的用戶(比如說我)。當(dāng)然自己用的時(shí)候,輸全ping.exe來執(zhí)行命令就可以了。
?
?