2009-02-06 257 views
26

找出notepad.exe和mspaint.exe可以在各種版本的Windows上工作的最佳方式是什麼?查找notepad.exe和mspaint.exe的路徑

我應該通過SHGetFolderPath(NULL, CSIDL_WINDOWS, NULL, SHGFP_TYPE_CURRENT, dir)獲取Windows目錄,然後遍歷所有子目錄以查找這兩個文件?

(假設我沒有興趣在Windows文件夾以外的任何東西。)

+0

無論你決定什麼樣的解決方案,都要準備*不*找到它們。我在一些系統上刪除了一個或兩個(爲什麼我應該保留記事本。當我有notepad ++時:) exe文件 – 2010-08-07 00:06:45

+9

@Stephen:刪除這樣輕量級的小東西會不會真的釋放任何資源,而只是引入破壞某些程序的風險? – chiccodoro 2010-09-30 13:42:36

回答

0

嘗試打開一個DOS提示符下,切換到Windows文件夾,並做到:

dir notepad.exe /s 

萬歲DOS :)

+0

技術上正確,但蠻力&只適用於Windows文件夾內的東西 – 2009-02-06 14:17:19

41

這適用於我有權訪問的每個Windows盒子(XP +)。

c:\> for %i in (cmd.exe) do @echo %~$PATH:i 
C:\WINDOWS\system32\cmd.exe 

c:\> for %i in (python.exe) do @echo %~$PATH:i 
C:\Python25\python.exe 

偉大的事情是,你不使用實際%PATH%,您可以通過使用不同的環境變量代替你自己的搜索路徑。

+0

它不會在許多本地化版本的Windows上執行,因爲可執行文件的命名可能不同。 – peSHIr 2009-02-06 07:30:42

+0

然後您替換本地化的名稱。這將是任何解決方案的問題,除非您認爲Win32 API中有某個WIN_NOTEPAD_REALNAME常量。 – paxdiablo 2009-02-06 07:37:49

2

我覺得從小開始你應該得到windir環境變量,並在子文件夾%windir%\system32\中查找mspaintnotepad。 他們很可能會在那裏。

但是,如果失敗了,那麼再訴諸一個更蠻力的搜索。

2

通常情況下,您只需執行它們。他們在每個Windows版本的系統路徑中。可以使用ExpandEnvironmentStrings。您要擴展的環境變量是WINDIR

在過去,您可以使用GetWindowsDirectoryGetSystemDirectory,但我認爲它們已被棄用。

3

檢查本地化版本上的HKEY_CLASSES_ROOT \ Applications \ notepad.exe鍵是否相同。也許鍵名是相同的,編輯/打開的值指向本地化的exe。
實施例:

英文:
HKEY_CLASSES_ROOT \應用\ Notepad.exe的\殼\編輯\命令
%SYSTEMROOT%\ SYSTEM32 ** ** NOTEPAD.EXE%1

荷蘭語:
HKEY_CLASSES_ROOT \應用程序\ NOTEPAD.EXE \殼\編輯\命令
的%SystemRoot%\ SYSTEM32 ** ** kladblok.exe%1

如果那是的話,那麼它只是檢查註冊表中查找鍵(同用於mspain T)。

18

如果您已經安裝了Microsoft平臺SDK(the February 2003 version是最後一個與微軟VC6的作品),你可以抓住where.exe程序(它是38K,只有18K,如果你gzip壓縮它),然後運行

where notepad.exe 
where命令

幫助:

WHERE [/R dir] [/Q] [/F] [/T] pattern... 

Description: 
    Displays the location of files that match the search pattern. 
    By default, the search is done along the current directory and 
    in the paths specified by the PATH environment variable. 

Parameter List: 
    /R  Recursively searches and displays the files that match the 
      given pattern starting from the specified directory. 

    /Q  Returns only the exit code, without displaying the list 
      of matched files. (quite mode) 

    /F  Displays the matched filename in double quotes. 

    /T  Displays the file size, last modified date and time for all 
      matched files. 

    pattern Specifies the search pattern for the files to match. 
      Wildcards * and ? can be used in the pattern. The 
      "$env:pattern" and "path:pattern" formats can also be 
      specified, where "env" is an environment variable and 
      the search is done in the specified paths of the "env" 
      environment variable. These formats should not be used 
      with /R. The search is also done by appending the 
      extensions of the PATHEXT variable to the pattern. 

    /?  Displays this help message. 

    NOTE: The tool returns an error level of 0 if the search is 
     successful, of 1 if the search is unsuccessful and 
     of 2 for failures or errors. 

Examples: 
    WHERE /? 
    WHERE myfilename1 myfile????.* 
    WHERE $windir:*.* 
    WHERE /R c:\windows *.exe *.dll *.bat 
    WHERE /Q ??.??? 
    WHERE "c:\windows;c:\windows\system32:*.dll" 
    WHERE /F /T *.dll 
0

使用WinAPI的函數GetWindowsDirectory()來獲取Windows文件夾,GetSystemDirectory()獲得Windows \ System文件夾。至少從Win95開始,它們保證可以與所有Windows版本兼容;我認爲他們也可以在Win 3.x中使用。

1

既然您用WinAPI標記了問題,我會使用SearchPath()例如以下內容將填充結果變量path

//Get the full path to notepad 
char path[MAX_PATH] = { 0 }; 
LPSTR* ptr = NULL; 
DWORD dwRet = SearchPath(NULL, "notepad.exe", NULL, MAX_PATH, (LPSTR)path, ptr); 
3

類型:

%WINDIR%\ SYSTEM32 \ NOTEPAD.EXE 路徑欄中thinggy

C:\ Windows \ System32下 找到NOTEPAD.EXE

* C是您的操作系統所在的硬盤驅動器:)

-1

轉到system32文件夾並在「文件名」欄中輸入「notepad.exe」。

0

總之,我覺得,最好的辦法是 檢查 Windows\System32目錄 和HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths註冊表項。

更一般地說,我發現最好的方法 是模仿ShellExecuteEx
應用程序註冊(Windows)中
https://msdn.microsoft.com/en-us/library/windows/desktop/ee872121(v=vs.85).aspx

該文件在以下位置尋找:
•當前工作目錄

取之。
•僅限Windows目錄(不搜索子目錄)。
?Windows \ System32目錄。
•PATH環境變量中列出的目錄。
•推薦:HKEY_LOCAL_MACHINE \ SOFTWARE \微軟\的Windows \ CurrentVersion \ App路徑

進一步的可能是通過使用SHGetFolderPathCSIDL_STARTMENU := 11CSIDL_COMMON_STARTMENU := 22檢查Start Menu\Programs\Accessories, 和檢索目標從LNK文件 。