digitalmars.D.learn - Startup from registry program doesn't work
- Sam Hu (38/38) Nov 26 2009 Greetings!
- Richard Webb (1/1) Nov 26 2009 Do you need to be calling RegOpenKeyEx with KEY_WRITE instead of KEY_REA...
- Sam Hu (5/7) Nov 30 2009 Thanks,I changed to KEY_WRITE and the function now return true when the ...
- Richard Webb (3/3) Dec 01 2009 Is the
- Sam Hu (2/8) Dec 01 2009 Solved.Thank you so much for your help!
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 ?Thanks,I changed to KEY_WRITE and the function now return true when the app executes.However the specified app dosn't start up automatically,when I check the startup settings by some third party software(say,SpySpot-Search and Destroy),I found the setting is : 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