Registryeinträge erzeugen



  • Hallo Leute,

    ich hab hier folgende Aufgabe weiss aber noch nicht so recht wie ich das anstellen soll. Vielleicht hat ja von euch jemand eine Lösung.

    Ich soll eine GUI und C++ Programm schreiben in dem nach Eingabe einer Nr. automatisch ein Registryeintrag erzeugt werden soll. Vorhanden hab ich die Registrybefehle schon in Form von z.B.

    %windir%\system32\reg.exe" add "HKEY_CURRENT_USER\Software\Activcard\ActivPack\ActivPackSimpleSignOnPilot\Autoconnect" /v "Title" /t "REG_SZ" 
    /d "Cisco Systems VPN Client" /f>NUL
    

    Im .NET hab ich herausgefunden das man deratige Befehle mit

    Process::Start("programm.exe")
    

    ausführen könnte nur wüsste ich gern wie 🙂

    Würde mich über Ideen freuen



  • Entweder machst du das einfach so:

    using namespace Microsoft::Win32;
    
        RegistryKey ^ reg = Registry::CurrentUser;
        reg = reg->CreateSubKey("Software\\Activcard\\ActivPack\\ActivPackSimpleSignOnPilot\\Autoconnect");
        reg->SetValue("Title","Cisco Systems VPN Client",RegistryValueKind::String);
    

    So würde ich das eher machen als über den Befehl.

    Weil bei dem befehl müsstest du afaik erst mal %windir% mit dem Pfad ersetzen der in der umgebungsvariablen steht.

    BR
    😉



  • he Dai,
    hier mal zwei Description-Methoden zum Ein/Austragen eines Dienstes:
    Musst halt evtl. noch die ManagedPointers umschreiben... 😃

    using namespace Microsoft::Win32;
    
    void AddServiceDescriptionToRegistry(String* serviceName, String* description) {
    
          RegistryKey* system;
          RegistryKey* currentControlSet; //HKEY_LOCAL_MACHINE\Services\CurrentControlSet
          RegistryKey* services; //...\Services
          RegistryKey* service; //...\<Service Name>
          RegistryKey* config; //...\Parameters - this is where you can put service-specific configuration
    
          try {
    
            //Open the HKEY_LOCAL_MACHINE\SYSTEM key
            system = Registry::LocalMachine->OpenSubKey("System");
            //Open CurrentControlSet
            currentControlSet = system->OpenSubKey("CurrentControlSet");
            //Go to the services key
            services = currentControlSet->OpenSubKey("Services");
            //Open the key for your service, and allow writing
            service = services->OpenSubKey(serviceName, true);
            //Add your service's description as a REG_SZ value named "Description"
            service->SetValue("Description", description);
            //(Optional) Add some custom information your service will use...
            config = service->CreateSubKey("Parameters");
          }
    
          catch(Exception* ex) {
            //Log.Error("Error occurred {0}.", e);
          }
        }
    
        /// <summary>
        /// Removes the service description from the registry.
        /// </summary>
        /// <param name="serviceName"></param>
        void RemoveServiceDescriptionFromRegistry(String* serviceName) {
    
          RegistryKey* system;
          RegistryKey* currentControlSet; // HKEY_LOCAL_MACHINE\Services\CurrentControlSet
          RegistryKey* services; //...\Services
          RegistryKey* service; //...\<Service Name>
          RegistryKey* config; //...\Parameters - this is where you can put service-specific configuration
    
          try {
    
            //Drill down to the service key and open it with write permission
            system = Registry::LocalMachine->OpenSubKey("System");
            currentControlSet = system->OpenSubKey("CurrentControlSet");
            services = currentControlSet->OpenSubKey("Services");
            service = services->OpenSubKey(serviceName, true);
            //Delete any keys you created during installation (or that your service created)
            service->DeleteSubKeyTree("Parameters");
          }
    
          catch(Exception* ex) {
            //Log.Error("Error occurred {0}.", e);
          }
        }
    


  • Super danke euch, hat soweit auch alles geklappt. Habe nun folgendes Problem:

    Möchte aus einer Variablen einen String aus einer Textbox einlesen und diesen in der Registry als Binary-Wert abspeichern.

    Also sprich Ich gebe in eine Textbox 12345678 ein und in der Registry soll das als Reg_Binary Wert gespeichert werden

    Irgendwie geht da was nicht weiss da einer was ?

    Wäre super nett


Anmelden zum Antworten