Windows Registry Fehler



  • mein programm soll sich in den autostart schreiben, das klappt auch, allerding setzt das programm hinter den Wert drei punkte (link):
    dercoder.de.ohost.de/reg.jpg
    hier der code:

    #include <windows.h>
    using namespace std;
    
    char MyApp[MAX_PATH];
    char SysDir[MAX_PATH];
    HMODULE HMod;
    HKEY hKey;
    
    int main() {
        //HMod = GetModuleHandle(NULL);
        GetModuleFileName(HMod, MyApp, sizeof(MyApp));
        GetSystemDirectory(SysDir, sizeof(SysDir));
        strcat(SysDir, "\\MyApp.exe");
        CopyFile(MyApp, SysDir, 0);
    
    	RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_SET_VALUE, &hKey);
    	RegSetValueEx(hKey, "MyApp", 0, REG_SZ, (const unsigned char*)SysDir, MAX_PATH);
    	RegCloseKey(hKey);
    }
    


  • MSDN schrieb:

    If the function succeeds, the return value is the length, in TCHARs, of the string copied to the buffer, not including the terminating null character



  • und das heißt auf deutsch?
    sry bin nicht so gut in englisch
    google translate sagt "Wenn die Funktion erfolgreich ist, der Rückgabewert ist die Länge, in TCHARs, der String in den Puffer kopiert, ohne die Einstellung Null-Zeichen"



  • Sorry, das war für GetSystemDirectory().
    Ich hab jetzt aber keine Lust zu schauen was da genau gemacht werden muss.
    Lies die Doku für alle Funktionen die du nutzt.



  • niemand anders ne idee?


  • Mod

    Ja! Der Tipp wirkt bei fast 90% der Anfragen in diesem Forum:

    Lies einfachmal die Doku:
    RegSetValueEx
    http://msdn.microsoft.com/en-us/library/ms724923(VS.85).aspx

    cbData [in]
    The size of the information pointed to by the lpData parameter, in bytes. If the data is of type REG_SZ, REG_EXPAND_SZ, or REG_MULTI_SZ, cbData must include the size of the terminating null character or characters.

    Anmerkung: Dein Programm wird unter Vista nicht funktionieren, sofern es nicht elevated läuft. Dein programm wird unter XP und Windows 2000 nicht funktionieren wenn es ncht als Admin läuft.



  • Martin Richter schrieb:

    Anmerkung: Dein Programm wird unter Vista nicht funktionieren, sofern es nicht elevated läuft. Dein programm wird unter XP und Windows 2000 nicht funktionieren wenn es ncht als Admin läuft.

    Dagegen kann man aber auch nix tun, oder? Was meinst du genau mit "elevated"? "Run as administrator"?



  • kannste mir den iwie am code etwas umschreiben, wie das gehen würd mit den nullstellen? bin noch kein Pr0 in c++


Anmelden zum Antworten