#include <Registry.hpp>
void
__fastcall AutoRun(
bool
pRun)
... {
/**//******************************************************
** 函数名: AutoRun
** 输入: 是否设置自动运行
** 功能描述: 设置开机自动运行
******************************************************/
TRegistry *Reg = new TRegistry();
try
...{
Reg->RootKey = HKEY_LOCAL_MACHINE;
Reg->OpenKey("//SOFTWARE//Microsoft//Windows//CurrentVersion//Run//",false);
... {
/**//******************************************************
** 函数名: AutoRun
** 输入: 是否设置自动运行
** 功能描述: 设置开机自动运行
******************************************************/
TRegistry *Reg = new TRegistry();
try
...{
Reg->RootKey = HKEY_LOCAL_MACHINE;
Reg->OpenKey("//SOFTWARE//Microsoft//Windows//CurrentVersion//Run//",false);
if(!Reg->ValueExists("SndMonitor") && !pRun)
...{ //根据wwp3321 的意见补充上
return;
}
if(Reg->ValueExists("SndMonitor") && !pRun)
...{
Reg->DeleteValue("SndMonitor");
}
else
...{
if(!Reg->ValueExists("SndMonitor") )
...{
Reg->WriteString("SndMonitor",ExpandFileName(Application->ExeName));
}
else
...{
if(Reg->ReadString("SndMonitor")!=ExpandFileName(Application->ExeName))
...{
Reg->WriteString("SndMonitor",ExpandFileName(Application->ExeName));
}
}
}
}
__finally
...{
delete Reg;
}
}
备注:SndMornitor 为 数值名称,WriteString写入的才是数值数据。