| Thread overview | |||||||||
|---|---|---|---|---|---|---|---|---|---|
|
August 29, 2015 How to use Registry Windows ? | ||||
|---|---|---|---|---|
| ||||
Hello,
I can't seem to use Registry, I tried to many attraction ways but I have every time an error "Value cannot be set".
Exemple code :
module main;
import std.stdio;
import std.windows.registry;
void main(string[] args)
{
version(Windows)
{
Key registryKey = Registry.localMachine()
.createKey("Software")
.createKey("Microsoft")
.createKey("Windows")
.createKey("CurrentVersion")
.createKey("Run");
registryKey.setValue("key", "value");
}
}
| ||||
August 29, 2015 Re: How to use Registry Windows ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to medhi558 | On 29/08/15 9:14 PM, medhi558 wrote:
> Hello,
> I can't seem to use Registry, I tried to many attraction ways but I have
> every time an error "Value cannot be set".
>
>
> Exemple code :
>
> module main;
>
> import std.stdio;
> import std.windows.registry;
>
> void main(string[] args)
> {
> version(Windows)
> {
> Key registryKey = Registry.localMachine()
> .createKey("Software")
> .createKey("Microsoft")
> .createKey("Windows")
> .createKey("CurrentVersion")
> .createKey("Run");
>
>
> registryKey.setValue("key", "value");
> }
> }
Humm, try:
auto regKey = Registry.localMachine()
.getKey("Software")
.getKey("Microsoft")
.getKey("Windows")
.getKey("CurrentVersion")
.getKey("Run");
regKey.setValue(...);
| |||
August 29, 2015 How to use Registry Windows ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to medhi558 | It doesn't always work the same error. | |||
August 29, 2015 Re: How to use Registry Windows ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to medhi558 | On Saturday, 29 August 2015 at 09:35:47 UTC, medhi558 wrote:
> It doesn't always work the same error.
Is your program running with administrator rights? Unprivileged programs may not write to HKEY_LOCAL_MACHINE by default.
| |||
August 29, 2015 Re: How to use Registry Windows ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Vladimir Panteleev | I just tried with administrator rights, but it doesn't work. | |||
August 29, 2015 Re: How to use Registry Windows ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to medhi558 | On Saturday, 29 August 2015 at 09:44:06 UTC, medhi558 wrote: > I just tried with administrator rights, but it doesn't work. You need to use a REGSAM value (e.g. KEY_ALL_ACCESS) to open the key with write access: /////////////////// test.d /////////////////// import std.windows.registry; void main() { auto regKey = Registry.currentUser() .getKey("Software") .getKey("Microsoft") .getKey("Windows") .getKey("CurrentVersion") .getKey("Run", REGSAM.KEY_ALL_ACCESS); regKey.setValue("Calculator", "calc.exe"); } ////////////////////////////////////////////// | |||
August 29, 2015 Re: How to use Registry Windows ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Vladimir Panteleev | Thank you it works. | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply