今天的一个程序需要在注册表中添加开机启动,于是想到用程序实现,Google & MSDN 了一下,其实还是很容易实现。
比如我需要在开机的时候,让系统自动运行 C:/Program Files/UDP Clt.exe。步骤如下:
1. #include <windows.h>
2. 调用 platform SDK:
::RegCreateKeyEx() 创建/打开注册表的键值, 查阅MSDN如下:
LONG RegCreateKeyEx(
HKEY hKey, // handle to an open key
LPCTSTR lpSubKey, // address of subkey name
DWORD Reserved, // reserved
LPTSTR lpClass, // address of class string
DWORD dwOptions, // special options flag
REGSAM samDesired, // desired security access
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
// address of key security structure
PHKEY phkResult, // address of buffer for opened handle
HKEY hKey, // handle to an open key
LPCTSTR lpSubKey, // address of subkey name
DWORD Reserved, // reserved
LPTSTR lpClass, // address of class string
DWORD dwOptions, // special options flag
REGSAM samDesired, // desired security access
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
// address of key security structure
PHKEY phkResult, // address of buffer for opened handle