March 29, 2024, 08:18:26 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Understanding the windows registry - Making changes to another user - Final part

Started by Andy, October 16, 2016, 06:03:44 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

In this last post, I have amended the program so that you can show / hide drives not just from your user account, but anyone else's account too (on your machine).

As these example programs have to be run as Admin (and to stop my ears burning), I've added some code in to check that you are running it as Admin.

It is another simple use of the registry and involves trying to add an entry to a certain part of it.  As this location requires Admin rights, if you do not have them, then the entry cannot be written.

When you try to read this entry back, if there's nothing there then you did not have Admin rights when you ran the program, if you did, the entry will exist and you will be able to read it.

You can then deleted this entry.

'==========================================================================
' First we will test to see if this program is being run as Admin...
'
' To do this test, try writing a value to:
' "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Test"
'
' If you have admin rights, it will do so, if not it will fail.
'
'==========================================================================

result = RegSetDWValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Test",1,"Test")
sleep(250)

'=================================================================
' Now try to read this test entry value back from the registry....
'=================================================================

resultin = ""
resultin = RegGetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Test","Test")

if resultin = ""
   ' Program has not been run as Admin.
   _MessageBox(0, "Please run this program as an Administrator.")
   end
else
   ' Program has been run as admin, so let's delete this test entry, so we can test again next time.
   result = RegDeleteKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Test")
endif


This is very useful when you need your program to be run with Admin rights.

For ease of use:
1. Compile (do not run yet) the example.
2. Find usersdrives2.exe and place a Desktop shortcut to it.
3. Run it (from the shortcut) normally, and you will get an error message.
4. Now right click on it (the shortcut) and "Run as Administrator".
5. Use it the same way was the previous examples.

This program sets a string called RegPath, and will contain one of the following entries:

For you the current user it will be :-
"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer" 

For another users :-
"HKEY_USERS\\ UsersName\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"

Where "UsersName" will be the other user's account name.

Note the different registry locations.

Enjoy!

And finally, some thoughts / conclusions etc...

Now you've seen that with care, the registry can be a big help to you, and you can have a little fun too.

These are my golden rules that (under pain of death) you should always follow:

1. When experimenting with the registry, it's better to create a test user account rather than potentially messing up your own registry settings, and use this account to "play around with" - this is very important because as a worse case scenario you could end up having to re-install windows on your machine - so don't pay around with your registry settings.
 
2. Some registry "tweaks" are relatively "harmless" and some are very powerful such as the NoDrives entry which I have shown you.

3. Always research and ask advice (you can always PM me and I will be glad to help if I can).

4. With all that said, don't be afraid to experiment, but don't use your own user account to do it on until you're confident.

5. Always make changes to registry settings responsibly, and do it on your machine.

Thanks for reading this, and I hope it's not been too boring!  ::)

Andy.
:)

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.