那位知道注册表里头那个开机自动运行的RUN键下面的各个项目的启动顺序?我曾经试过,用两个程序,
aaa.exe:
MessageBox(0,pchar(formatdatetime('hh:nn:ss.zzz',now)),'aaa application',MB_OK); 
bbb.exe,同理;
然后一起放在那里,多次logoff测试,发现先后顺序,时差并不确定;
这个想法的由来是某台机器上有3721与病毒共存,rundll32直接杀不掉;想写一个application,放在那里,开机的时候跟3721抢时间把它的键删掉,或者修改键值;但每次我都发现没赶上时间。

解决方案 »

  1.   

    #include <vcl.h>
    #include <registry.hpp>
    #pragma hdrstop
    USERES("Logon.res");
    //---------------------------------------------------------------------------
    WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
    {
        try
        {
            //添加部分开始
            int num=0;        //创建注册表堆对象指针
            TRegistry *Registry = new TRegistry;        //定位注册表根键
            Registry->RootKey = HKEY_USERS;        //如果打开主键失败
            if(!Registry->OpenKey(".DEFAULT\\Logon\\Records", false))
            {
                //创建主键
                Registry->CreateKey(".DEFAULT\\Logon\\Records");            if(!(Registry->OpenKey(".DEFAULT\\Logon\\Records", false)))
                {
                    return 0;
                }
                else
                {
                    TRegistry *Reg = new TRegistry; // ①
                    Reg->RootKey = HKEY_LOCAL_MACHINE;                //只有写到下面的目录下面才能够每次开机时就运行该程序。
                    //这就是你想要的啦。。
                    Reg->OpenKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run",false);                //在注册表中注册本程序
                    Reg->WriteString("Logon",Application->ExeName);
                    Reg->CloseKey();
                    delete Reg;                Application->MessageBox("登录程序注册成功!","结果",MB_OK); // ②
                    Registry->WriteInteger("开机次数",num);
                    Registry->WriteString("程序注册时间",Date()+Time());
                    return 0;
                }
            }
            else
            {
                num = Registry->ReadInteger("开机次数"); // ③            //记录开机次数
                Registry->WriteInteger("开机次数",num+1);
                //记录开机时间
                Registry->WriteString("第"+AnsiString(num+1)+"次开机",Date()+Time());
            }        Registry->CloseKey();
            delete Registry;
            //添加部分结束        Application->Initialize();
            //Application->CreateForm(__classid(TForm1), &Form1);
            Application->Run();
        }
        catch (Exception &exception)
        {
             Application->ShowException(&exception);
        }
        return 0;
    }
      

  2.   

    MessageBox(0,pchar(formatdatetime('hh:nn:ss.zzz',now)),'aaa application',MB_OK);就是程序的所有内容,程序本身并没有必要写注册表,由我自己手动写入,现在就是发现,子键名称顺序并不对应启动顺序(程序运行时有messagebox显示时间,然而有时程序启动的顺序与显示时间也不一致)