程序启动时运行
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
void __fastcall TForm1::Button1Click(TObject *Sender) { TRegistry* Reg; char AppFileName[256]; if( Edit1->Text=="" ) // 判断文件名是否为空 { MessageBox(Handle,"应用程序名称不可以为空。","错误",MB_OK+MB_ICONERROR); exit(0); } Edit1->GetTextBuf(AppFileName, 256); Reg = new TRegistry(); try { Reg->RootKey = HKEY_LOCAL_MACHINE; if( Reg->OpenKey("Software//Microsoft//Windows//CurrentVersion//Run", FALSE) ) { // 在注册表中添加数值 Reg->WriteString("StartUp1",AppFileName); } else MessageBox(Handle,"打开注册表失败。","错误",MB_OK|MB_ICONERROR); } catch(...) { Reg->CloseKey(); Reg->Free(); } } |