今天的一个程序需要在注册表中添加开机启动,于是想到用程序实现,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,
&
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,
&

这段代码演示了如何在Windows环境下使用API函数RegCreateKeyEx和RegSetValueEx来创建和设置注册表键值。程序首先尝试打开或创建`SOFTWAREMicrosoftWindowsCurrentVersionRun`子键,然后写入`UDP Clt.exe`的路径到该键下,以实现启动时运行该程序。
最低0.47元/天 解锁文章
2799

被折叠的 条评论
为什么被折叠?



