Jump to content

Want to read a key from the registry with php


Osram

Recommended Posts

I am making some kind of licensing system and want to read a key value from the registry that identifies the PC of the client. I found some code on the internett, but which doesn't work, and I was hoping someone could explain me why.

I want to read the key from the following address: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\MachineGuid. I am fully aware that this value can be changed, but I can use it anyway. 

I have found two methods. The first is the following:

$Wshshell= new COM('WScript.Shell');
$data= $Wshshell->regRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\MachineGuid');
echo $data;

And this is the second one:

$keyhandle = reg_open_key('HKEY_LOCAL_MACHINE', 'Software\Microsoft\Cryptography\MachineGuid');
$value = reg_enum_value($keyhandle,1);
echo $value;

What am I missing to make these work, or are there other way to do it? 

Thanks in advance.

Sincerely

Link to comment
Share on other sites

Assuming that you have written the code correctly and not made any typos, what is the problem with it?  You aren't having success - so are there any messages coming back?  For you to say it doesn't work sure can't help us to see what's wrong, assuming that it is written correctly.

  • Great Answer 1
Link to comment
Share on other sites

I am not using any special IDE for editing php code. It's very seldom that I do programming in PHP. But it's maybe a good idea to get such a program anyway. As it is now, I only get the message that the page doesn't work.

Link to comment
Share on other sites

And WHAT IS that message?   That's what I was asking you.  You don't need an IDE to read a message in your browser.  Or - if the functions themselves capture the messages the documentation for them should tell you how to display them during execution.

Edited by ginerjm
  • Like 1
Link to comment
Share on other sites

After inserting the error reporting code, I got the following message:

Fatal error: Uncaught Error: Class 'COM' not found in /customers/f/d/7/dmusic.com/httpd.www/dhvnd/dhru/test.php:6 Stack trace: #0 {main} thrown in /customers/f/d/7/dmusic.com/httpd.www/dhvnd/dhru/test.php on line 6

 

Link to comment
Share on other sites

So he can't find whatever COM is.  Is it a class?  Is the class being loaded by any require or include?

The errror reporting code is essential for picking up errors during the coding mode.  Turn them off before putting into production.

Link to comment
Share on other sites

By the way, the error message for the second option:

$keyhandle = reg_open_key('HKEY_LOCAL_MACHINE', 'Software\Microsoft\Cryptography\MachineGuid');
$value = reg_enum_value($keyhandle,1);
echo $value;

is the following:

Fatal error: Uncaught Error: Call to undefined function reg_open_key() in /customers/f/d/7/dmusic.com/httpd.www/dhvnd/dhru/test.php:10 Stack trace: #0 {main} thrown in /customers/f/d/7/dmusic.com/httpd.www/dhvnd/dhru/test.php on line 10

and line 10 is

$keyhandle = reg_open_key('HKEY_LOCAL_MACHINE', 'Software\Microsoft\Cryptography\MachineGuid');

 

Link to comment
Share on other sites

1 hour ago, Osram said:

I am making some kind of licensing system and want to read a key value from the registry that identifies the PC of the client.

And exactly who is the "client" here? Are they the one running this PHP code? Or are they browsing the website or whatever?

Link to comment
Share on other sites

I went into https://www.php.net/manual and searched for it, and got the message that it doesn't exist.  I got it from this web-site: https://www.sitepoint.com/access-the-windows-registry-from-php/

But at Stackoverflow: https://stackoverflow.com/questions/41800894/undefined-function-reg-open-key-in-php-7-0

I am told that I have to install win32std, but with no instruction how to do it.

Link to comment
Share on other sites

Keep in mind that PHP code is open-source, so if somebody wanted to circumvent your registry key licensing checks, they could do it really easily. Like, in the time it takes me to microwave last night's leftovers.

win32std

It looks pretty old, though, so you might have to find an alternative. Like a shell command.

Link to comment
Share on other sites

Okay, let's go back a step.

Who will own the server that this code will be running on? The client? Is it their server? Or is the code hosted somewhere the client cannot control and they use their browser (or some other means) to access/use/whatever it?

Link to comment
Share on other sites

1 minute ago, Osram said:

The code will be on the server of the host, and the client run it from a web-site they visit. 

Okay, that's what I thought.

You cannot read registry settings from the client browsing the website. You can only access the registry from the server PHP is itself running on. And obviously only if it's a Windows machine.

  • Great Answer 1
Link to comment
Share on other sites

The client will enter information into a form and click ok. But it maybe doesn't help. But is there no way the php program could download an exe program to the clients PC that could read the registry and transfer the variable to a php variable?

Link to comment
Share on other sites

1 minute ago, Osram said:

The client will enter information into a form and click ok. But it maybe doesn't help. But is there no way the php program could download an exe program to the clients PC that could read the registry and transfer the variable to a php variable?

You want to know if the server can download an EXE to the user's computer and run it, without them knowing?

Think about what you're asking. I'm sure you can come up with the correct answer.

  • Great Answer 1
Link to comment
Share on other sites

Licensing in this sort of situation is often handled by restricting how many user accounts can be active at once. Assuming your application deals with user accounts, of course.

Another scheme is to restrict or limit how much data can be read in the database. You don't stop storing information, you just don't let people access all of it. Like, only showing the most recent.

Related to that, you can also limit access to a resource. A fixed number of page views per day, or a number of downloads per assets, or total downloads, or something like that.

And of course there's the most obvious one: to limit what features are available to use. Especially suited to complex applications that have a lot to offer.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.