Jeb*_*Jeb 6 .net c# registry notepad path
我需要将我创建的文件扩展名".rulog"与notepad.exe相关联,作为Windows 7计算机的安装项目安装的一部分(因为我们需要管理员权限才能写入注册表).
基本上我需要以编程方式获取notepad.exe的确切路径.现在,我知道它通常存在于C:\ Windows\system32中.这是PATH系统环境变量的一部分,所以我想我可以循环遍历所有PATH变量,并通过使用File.Exists将"notepad.exe"与当前路径组合来测试是否存在"notepad.exe".然而,这感觉非常笨拙.
基本上我需要添加一个条目
Computer\HKEY_CLASSES_ROOT\.rulog\shell\open\command\
Run Code Online (Sandbox Code Playgroud)
与记事本的路径的价值.
顺便说一句,我可以看到.txt:
Computer\HKEY_CLASSES_ROOT\.txt\ShellNew
Run Code Online (Sandbox Code Playgroud)
ItemName的值为
“@%SystemRoot%\system32\notepad.exe,-470”
Run Code Online (Sandbox Code Playgroud)
也许我可以复制这个值?或者这是危险的吗?(例如不存在).
您可以使用:
Environment.GetEnvironmentVariable("windir") + "\\system32\\notepad.exe";
Run Code Online (Sandbox Code Playgroud)
甚至更容易:
Environment.SystemDirectory + "\\notepad.exe";
Run Code Online (Sandbox Code Playgroud)
这样,操作系统所在的驱动器无关紧要.