28

找出notepad.exe和mspaint.exe在哪里可以在不同版本的Windows上工作的最佳方法是什么?

我是否应该通过 获取 Windows 目录SHGetFolderPath(NULL, CSIDL_WINDOWS, NULL, SHGFP_TYPE_CURRENT, dir),然后遍历所有子目录以查找这两个文件?

(假设我对 Windows 文件夹之外的任何内容都不感兴趣。)

4

11 回答 11

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%,您可以使用不同的环境变量替换您自己的搜索路径。

于 2009-02-06T07:28:29.483 回答
19

如果您安装了 Microsoft Platform SDK(2003 年 2 月的版本是最后一个与 Microsoft VC6 一起工作的版本),您可以获取该where.exe程序(它是 38K,如果您 gzip 则只有 18K)并运行

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
于 2009-02-06T14:16:30.020 回答
3

检查键 HKEY_CLASSES_ROOT\Applications\notepad.exe 在本地化版本上是否相同。也许键名相同,编辑/打开的值指向本地化的 exe。
例子:

英文:
HKEY_CLASSES_ROOT\Applications\notepad.exe\shell\edit\command
%SystemRoot%\system32**NOTEPAD.EXE** %1

荷兰语:
HKEY_CLASSES_ROOT\Applications\notepad.exe\shell\edit\command
%SystemRoot%\system32**kladblok.exe** %1

如果是这种情况,那么它只是要检查注册表中的那个键(mspaint 也是如此)。

于 2009-02-06T08:24:09.357 回答
2

类型:

%windir%\system32\notepad.exe 在路径栏中的东西

或者

C:\Windows\System32 并找到 notepad.exe

*C 是您的操作系统所在的硬盘驱动器 :)

于 2012-03-05T15:56:02.720 回答
2

我认为从小处着手,您应该获取windir环境变量并在子文件夹%windir%\system32\中查找mspaintand notepad。他们很可能会在那里。

但是,如果失败了,那就求助于更暴力的搜索。

于 2009-02-06T07:30:24.347 回答
2

通常,您只需执行它们。它们位于每个 Windows 版本的系统路径上。

您可以使用ExpandEnvironmentStrings. 您要扩展的环境变量是WINDIR.

在过去,您可以使用GetWindowsDirectoryor GetSystemDirectory,但我认为它们已被弃用。

于 2009-02-06T07:47:13.877 回答
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);
于 2009-02-08T02:49:51.747 回答
1

使用 WinAPI 函数 GetWindowsDirectory() 获取 Windows 文件夹,使用 GetSystemDirectory() 获取 Windows\System 文件夹。保证至少可以与 Win95 起的所有 Windows 版本一起使用;我认为它们在 Win 3.x 中也可用。

于 2009-02-06T17:59:30.863 回答
0

尝试打开 DOS 提示符,切换到 Windows 文件夹并执行以下操作:

dir notepad.exe /s

DOS万岁:)

于 2009-02-06T07:28:26.067 回答
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\Microsoft\Windows\CurrentVersion\App Paths

进一步的可能是Start Menu\Programs\Accessories通过使用 和 来检查 ,SHGetFolderPathCSIDL_STARTMENU := 11CSIDL_COMMON_STARTMENU := 22lnk 文件中检索目标。

于 2017-02-05T12:15:10.157 回答
-2

转到 system32 文件夹并在“文件名”栏中键入“notepad.exe”。

于 2014-08-13T17:56:23.577 回答