How to write and read windows registry data with php?

Asked

Viewed 388 times

1

I need to write and read data in windows registry with php , how to do ?

  • 2

    I did not understand the negative votes - it is a good question.

  • OK Para ler, vc faz o reg export. Algo assim: reg export Hkey_local_Machine\Software\blabla C:\export.txt. Isso gera um txt e então vc faz a leitura do txt com o php e abstrai o que precisa ,,,,, To read this procedure <?php reg export Hkey_local_Machine\Software\blabla C:\export.txt ?> and create ?

  • 2

    OK, Daniel Omine , I await Reply ! Thank you.

  • Thank you ! Daniel Omine , Thank you very much.

1 answer

4


To write to the Windows registry, run the command reg import

<?php
exec('reg import c:\arquivo.reg');

To read a Windows record, run the command reg export

<?php
// Exporta o registro para um arquivo texto
exec('reg export Hkey_local_Machine\Software\blabla C:\arquivo.reg');

// Em seguida, faz a leitura desse arquivo
$registro = file_get_contents('C:\arquivo.reg');

// Agora você trabalha com funções de manipulação de string para abstrair o que necessita da variável `$registro`.

The ".reg file" will have something like this

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\leroLero]
"parametro1"=valor
"parametro2"=valor
"parametro3"=valor

So you abstract what matters is the parameters and the respective values.

*How to manipulate the string is another subject. You can ask a new question to avoid making the topic "too broad", which is reason for closing.

Interesting topic (SO-en): https://stackoverflow.com/questions/579195

  • Thank you ! Daniel Omine , Thank you very much. Vou adaptar aqui e também vou ler o Tópico .

  • I open a topic now to => *How to manipulate the string ?

  • https://answall.com/questions/226381/como-manipular-a-string

  • just one more question at which point I am loading the value of my variables into the file ? here => $registro = file_get_contents('C:\arquivo.reg'); ?

  • @Daniel to what extent this solution will work with PHP if using a server based Linux? and if you want to run it on the client and not on the server? (Pure Interest) because I have used an approximation with vbscript to run commands on client machines

  • Linux does not have a "regedit" as in Windows. The structure and tools are different. If you were to make it to Linux, simply save text files in private places where the user would not have access. Incidentally, this could also be applied here but the AP requires it to be done in the Windows registry. It’s a matter of opinion. The logic is the same, only changes the resources. @Gonsalosousa

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.