将程序设置成为开机自动执行的程序
(
十二
)
本文讲述,如何把程序设置为开机自动执行
1.
创建一个对话框工程:
SetWSAutoRun
2.
添加一个复选框,变量为
m_chset
,添加一个“确定”按钮,代码如下:
HKEY
sub
;
char
bufname
[200];
::
GetModuleFileName
(
NULL
,
bufname
,200);
CString
str
;
str
.
Format
(
"%s"
,
bufname
);
CString
skey
=
"Software//Microsoft//Windows//CurrentVersion//Run"
;
::
RegCreateKey
(
HKEY_LOCAL_MACHINE
,
skey
,&
sub
);
if
(
m_chset
.
GetCheck
())
{
::
RegSetValueEx
(
sub
,
"StartAutoRun"
,
NULL
,
REG_SZ
,(
const
BYTE
*)
str
.
GetBuffer
(0),
str
.
GetLength
());
}
else
{
::
RegDeleteValue
(
sub
,
"StartAutoRun"
);
完成。