Greetings!

Below program is purpose to execute a program(exe) from registry upon system 
startup.It was built successfuly,but unfortunately it does not work as 
expected,nothing would happen.It prints:

"Oh..no,not a good doctor."

when the program runs.

What's problem?It is under DMD2.036 under windows xp.

Thanks for your help in advance.


import *.*;//everything needed

BOOL StartupThruRegistry(char* pFileName)
{
        DWORD rc;

        DWORD length=pFileName.sizeof;
        DWORD type=REG_SZ;
        HKEY hKey;

        rc=RegOpenKeyEx(HKEY_CURRENT_USER,
                "Software\\Microsoft\\Windows\\CurrentVersion\\Run",
                0,KEY_READ,&hKey);
        if(rc==ERROR_SUCCESS)
        {
                rc=RegSetValueEx(hKey,toStringz("Startup"),0,
                                type,cast(ubyte*)pFileName,length);
                RegCloseKey(hKey);
        }
        if(rc==ERROR_SUCCESS)
                return TRUE;
        else
                return FALSE;
}

int main(string[] args)
{
        
        string filename="c:\\windows\\explorer.exe";

        if(!StartupThruRegistry(cast(char*)toStringz(filename)))
        {
                writeln("Oh..no,not a good doctor.");
        
        }
        return 0;
}

Reply via email to