Osram Posted April 4, 2020 Share Posted April 4, 2020 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 Quote Link to comment Share on other sites More sharing options...
ginerjm Posted April 4, 2020 Share Posted April 4, 2020 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. 1 Quote Link to comment Share on other sites More sharing options...
Osram Posted April 4, 2020 Author Share Posted April 4, 2020 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. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted April 4, 2020 Share Posted April 4, 2020 (edited) 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 April 4, 2020 by ginerjm 1 Quote Link to comment Share on other sites More sharing options...
Osram Posted April 4, 2020 Author Share Posted April 4, 2020 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 Quote Link to comment Share on other sites More sharing options...
ginerjm Posted April 4, 2020 Share Posted April 4, 2020 And line 6? Quote Link to comment Share on other sites More sharing options...
Osram Posted April 4, 2020 Author Share Posted April 4, 2020 Line 6 is $Wshshell= new COM('WScript.Shell'); I also now see that when I don't use the error reporting code, I get the message HTTP ERROR 500. Sorry, I overlooked it. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted April 4, 2020 Share Posted April 4, 2020 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. Quote Link to comment Share on other sites More sharing options...
Osram Posted April 4, 2020 Author Share Posted April 4, 2020 No, I don't have anything else than just the script I've shown you. No class using require or include or any com file. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted April 4, 2020 Share Posted April 4, 2020 Well - that's the problem as the messages tell you. Can't help you out - not familiar with any of this particular task. Quote Link to comment Share on other sites More sharing options...
Osram Posted April 4, 2020 Author Share Posted April 4, 2020 Ok, but thanks anyway. I understood a little more. Sincerely Quote Link to comment Share on other sites More sharing options...
Osram Posted April 4, 2020 Author Share Posted April 4, 2020 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'); Quote Link to comment Share on other sites More sharing options...
ginerjm Posted April 4, 2020 Share Posted April 4, 2020 And if you search the php manual for that function name what do you find? Doesn't show up in mine. Is this some package that has to be specifically included into your php install? 1 Quote Link to comment Share on other sites More sharing options...
requinix Posted April 4, 2020 Share Posted April 4, 2020 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? Quote Link to comment Share on other sites More sharing options...
Osram Posted April 4, 2020 Author Share Posted April 4, 2020 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. Quote Link to comment Share on other sites More sharing options...
Osram Posted April 4, 2020 Author Share Posted April 4, 2020 The client is running this php program. Quote Link to comment Share on other sites More sharing options...
requinix Posted April 4, 2020 Share Posted April 4, 2020 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. Quote Link to comment Share on other sites More sharing options...
Osram Posted April 4, 2020 Author Share Posted April 4, 2020 I don't quite understand what you mean by that, as the PHP code can be hidden on the server. Can you explain some more? Quote Link to comment Share on other sites More sharing options...
requinix Posted April 4, 2020 Share Posted April 4, 2020 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? Quote Link to comment Share on other sites More sharing options...
Osram Posted April 4, 2020 Author Share Posted April 4, 2020 The code will be on the server of the host, and the client run it from a web-site they visit. Quote Link to comment Share on other sites More sharing options...
requinix Posted April 4, 2020 Share Posted April 4, 2020 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. 1 Quote Link to comment Share on other sites More sharing options...
Osram Posted April 4, 2020 Author Share Posted April 4, 2020 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? Quote Link to comment Share on other sites More sharing options...
requinix Posted April 4, 2020 Share Posted April 4, 2020 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. 1 Quote Link to comment Share on other sites More sharing options...
Osram Posted April 4, 2020 Author Share Posted April 4, 2020 Ok, I understand. So there's no way to do this. Good to know. Thanks for your comments. Sincerely Quote Link to comment Share on other sites More sharing options...
requinix Posted April 4, 2020 Share Posted April 4, 2020 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.