digitalmars.D.learn - Startup from registry program doesn't work
- Sam Hu <samhu.samhu nospam.com> Nov 26 2009
- Richard Webb <numpsyuk hotmail.com> Nov 26 2009
- Sam Hu <samhu.samhu nospam.com> Nov 30 2009
- Richard Webb <numpsyuk hotmail.com> Dec 01 2009
- Sam Hu <samhu.samhu nospam.com> Dec 01 2009
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;
}
Nov 26 2009
Do you need to be calling RegOpenKeyEx with KEY_WRITE instead of KEY_READ ?
Nov 26 2009
Richard Webb Wrote:Do you need to be calling RegOpenKeyEx with KEY_WRITE instead of KEY_READ ?
C:\\w other than c:\\windows:\\explorer.exe So where is the problem?
Nov 30 2009
Is the DWORD length=pFileName.sizeof; setting length to the size of the pointer, when you need the length of the string? That would explain why only 4 bytes have been written.
Dec 01 2009
Richard Webb Wrote:Is the DWORD length=pFileName.sizeof; setting length to the size of the pointer, when you need the length of the string? That would explain why only 4 bytes have been written.
Solved.Thank you so much for your help!
Dec 01 2009








Sam Hu <samhu.samhu nospam.com>