Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the exact path of notepad.exe in order to associate a file extension

I need to associate a file extension I have created “.rulog” with notepad.exe as part of a setup project installation for a windows 7 machine (it’s here since we require admin privileges to write to the registry).

Basically I need to obtain programmatically the exact path of the notepad.exe. Now, I understand that it typically lives in C:\Windows\system32. This is part of PATH system environment variable, so I guess I could loop through all the PATH variables and test if “notepad.exe” exists by combining “notepad.exe” with the current path using File.Exists. However this feels very clumsy.

Essentially I need to add an entry to

Computer\HKEY_CLASSES_ROOT\.rulog\shell\open\command\ 

with the value of the path of notepad.

Incidentally I can see that .txt in:

Computer\HKEY_CLASSES_ROOT\.txt\ShellNew

has a value for ItemName of

“@%SystemRoot%\system32\notepad.exe,-470”

Perhaps I can just copy this value? Or is this dangerous?(e.g. does not exist).

like image 903
Jeb Avatar asked Jan 12 '12 17:01

Jeb


People also ask

How do I find the path of notepad?

It depends, If you opened the file directly, (which then opened notepad), you can see the 'command line' in task manager, it will have the file path listed. (to see command line, open task manager, go to details page, right click the column header and select columns).

What is the path of notepad in Windows 10?

Ways to Open Notepad on Your Windows 10 MachineTurn Notepad on in the Start menu. Select the Start button on the taskbar and then choose Notepad. Find it by searching. Type note in the search box and select Notepad in the search results.

Where is Notepad ++ EXE located?

For most installations (64-bit), the path will be: C:\Program Files (x86)\Notepad++\notepad++.exe.

How do I get notepad exe?

Go to C Drive (or whichever partition you've installed Windows on), followed by Windows > System32 folder. Scroll down and you should find Notepad.exe program. Right-click on the icon and select Send to > Desktop. Alternatively, copy and paste C:\Windows\System32\Notepad in your file explorer and press the Enter key.


2 Answers

You can use:

Environment.GetEnvironmentVariable("windir") + "\\system32\\notepad.exe";

Or even easier:

Environment.SystemDirectory + "\\notepad.exe";

That way it doesn't matter which drive the os is on.

like image 166
Bali C Avatar answered Sep 17 '22 22:09

Bali C


Copying the value with %systemroot% should be just fine. If it works for the OS, it should work for you!

like image 41
John Gardner Avatar answered Sep 21 '22 22:09

John Gardner