0
I need to make a php script to change/create the value of a windows environment variable
shell_exec("setx VAR_TEST '2' /M");
The command runs but does not change the value of the variable, I run using prompt as administrator.
0
I need to make a php script to change/create the value of a windows environment variable
shell_exec("setx VAR_TEST '2' /M");
The command runs but does not change the value of the variable, I run using prompt as administrator.
0
In fact the value is altered, but the associated access of the volar updated occurs in a new instance/session.
The shell_exec("setx VAR_TEST '2' /M")
will create the variable or change its value if the variable already exists.
Understand that the Setx
only access the variable with its "updated" value in a new instance/session, before that so that you have "updated" access to the value of a created/changed variable in the same instance/session, or even to check that your creation/change action was correctly, recommend reading the values of the registry keys where the command setx
will make the effective registration/creation of entries and their values:
HKLM\Environment == para todos usuários
when used:/m
HKCU\Environment == para o usuário atual
Hence the tip to write and read directly in the windows registry directly on php, you do not need to invoke the shell/cmd to execute the setx
that will write, for only in the next instance/session you have updated access to the value/variable.
I suggest you check these links on how to read/write/delete variables/values in the Windows Registry via PHP:
Browser other questions tagged php windows cmd
You are not signed in. Login or sign up in order to post.
And how do you check whether there was the change or not?
– Woss
@Woss just reading HKLM Environment\*Variable
– It Wasn't Me