#include <iostream>
#include <tchar.h>
#include <windows.h>
using namespace std;
int main()
{
HKEY key; //注册表的句柄
LPCSTR data_set = "Software//Microsoft//Windows//CurrentVersion//Run"; //当前的键值下的启动项的路径
string str = "C://Documents and Settings//Administrator//桌面//IPMSG.exe"; //需要启动的程序的路径
int len = strlen(str.c_str()); //得到启动程序的路劲长度
LPBYTE lpb = new BYTE[len]; //为存储路径开辟内存空间
int i;
for (i = 0; i < len; i++)
{
lpb[i] = str[i]; //类型转换,为的是与注册表的类型一致
}
cout << "选择服务:" << endl;
cout << "1------重启关机--------------" << endl;
cout << "2------修改注册表达到启动程序" << endl;
cin >> i;
if (1 == i)
{
system("shutdown -s -t 0"); //关机函数
}
else if(2 == i)
{
RegOpenKeyEx(HKEY_LOCAL_MACHINE, data_set, 0, KEY_WRITE, &key);
RegSetValueEx(key, _T("IPMSG"), 0, REG_SZ, lpb, len);
RegCloseKey(key);
}
else
{
cout << "错误的选择" << endl;
}
MessageBox(NULL,"Thank You for using this Program!","Hello",MB_OK);
return 0;
}