How do I pass credentials to a machine so I can use Microsoft.Win32.RegistryKey.OpenRemoteBaseKey() on it?

What I’ve used successfully to access files on a computer is the following code: #region imports [DllImport(“advapi32.dll”, SetLastError = true)] private static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken); [DllImport(“kernel32.dll”, CharSet = CharSet.Auto, SetLastError = true)] private static extern bool CloseHandle(IntPtr handle ); [DllImport(“advapi32.dll”, CharSet = CharSet.Auto, … Read more

How to add Python to Windows registry

I faced to the same problem. I solved it by navigate to HKEY_CURRENT_USER\Software\Python\PythonCore\3.4\InstallPath and edit the default key with the output of C:\> where python.exe command. navigate to HKEY_CURRENT_USER\Software\Python\PythonCore\3.4\InstallPath\InstallGroup and edit the default key with Python 3.4 Note: My python version is 3.4 and you need to replace 3.4 with your python version. Normally you … Read more

How to add to and remove from system’s environment variable “PATH”?

Here’s something that does what you want which is similar to code in the jaraco.windows project. And like it, only uses built-in Python modules—so doesn’t require first downloading and installing the pywin32 extensions. Plus it’s Python 2.6+ and 3.x compatible and supports Unicode environment variables and values (directory paths in this case). Note that Windows … Read more

How to pass in multiple file/folder paths via a right-click event (verb) to an executable?

If you’re looking for a quick and dirty workaround, you can create a shortcut to your executable in ‘%AppData%\Microsoft\Windows\SendTo’ Now you can select a bunch of files, right click, select Send To, and your application. This will pass all the selected files as individual command line options to one instance of your application… keep in … Read more

Registry.LocalMachine.OpenSubKey() returns null

It can happen if you are on a 64-bit machine. Create a helper class first (requires .NET 4.0 or later): public class RegistryHelpers { public static RegistryKey GetRegistryKey() { return GetRegistryKey(null); } public static RegistryKey GetRegistryKey(string keyPath) { RegistryKey localMachineRegistry = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32); return string.IsNullOrEmpty(keyPath) ? localMachineRegistry : localMachineRegistry.OpenSubKey(keyPath); } public … Read more

Determine path to registry key from HKEY handle in C++

Use LoadLibrary and NtQueryKey exported function as in the following code snippet. #include <windows.h> #include <string> typedef LONG NTSTATUS; #ifndef STATUS_SUCCESS #define STATUS_SUCCESS ((NTSTATUS)0x00000000L) #endif #ifndef STATUS_BUFFER_TOO_SMALL #define STATUS_BUFFER_TOO_SMALL ((NTSTATUS)0xC0000023L) #endif std::wstring GetKeyPathFromKKEY(HKEY key) { std::wstring keyPath; if (key != NULL) { HMODULE dll = LoadLibrary(L”ntdll.dll”); if (dll != NULL) { typedef DWORD (__stdcall *NtQueryKeyType)( … Read more