Jump to content
Strydr

Inconsistent RegRead/write responses?

Recommended Posts

Strydr

I try to stay out of the Registry in general, and I've never played in the Windows10 registry at all, so I'm probably not understanding something simple.  

I'm trying to test for a key and write if it's not there.

I'm testing for "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Holographic\SupportedProtocols\Steam"

It will have no value.

I've been trying use Williechan's code snippet (I haven't started worrying about GEOsoft's note, yet):

RegRead($RegKeyImLookingFor,"")
If @Error > 0 Then
   ;Key does not exist
    DoSomething()
Else
   ;Key does exist
    DoSomethingElse()
EndIf

While this works fine for some entries, it doesn't for others.  Examples:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Hints  works fine.

Nothing under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Holographic will work.  The Holographic key has subkeys (not sure that I have the terminology right) so I also tried going thru the tree structure under it.  I've tried different keys: some work, some don't and I can't find any pattern to it. 

I need the answer for the Steam key listed on top, but I would very much like to know what on earth is going on!  Help?  

Thank you!

ps:  let me know if you are into WindowsMR, you'll like what this is for...

Share this post


Link to post
Share on other sites
Strydr

How on earth do I edit my post?  Hmmmm

Anyway, also wanted to mention that I tried a simple RegWrite to write that string and nothing seems to have happened.  I'm not going to repeat it until I get an idea of what's going on.  

Thanks!

Share this post


Link to post
Share on other sites
Subz

Have you tried the following keys?

;~ 32 bit key
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Holographic

;~ 64 bit key
HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Holographic

 

Share this post


Link to post
Share on other sites
Strydr

    >

4 hours ago, Subz said:

;~ 64 bit key HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Holographic

EURIKA!!  <he shouts!>  

Thank you sooo much!

To be clear:  so even tho my "Regedit" says nothing about 64bit, since my OS is 64bit I'm going to have 64bit entries <doh>.  Also, the main way to tell if they are 64bit or 32bit is that they won't show up if I don't address them correctly, ie HKLM64 vs HKLM.  Is there any other way to tell?

Is it safe to say that the reason my RegWRITE did not work is because I was using a 32bit key in a 64bit section of the registry?

Again, thank you very very much!  It's on such simple, obvious things that I loose the most hair!

Share this post


Link to post
Share on other sites
Subz

On a 64 bit machine

32 bit Registry = HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node
64 bit Registry = HKEY_LOCAL_MACHINE\SOFTWARE

Assuming your script is compiled as 32 bit, when you used RegWrite to "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Holographic" you actually wrote to the 32 bit path i.e.:

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Holographic

If you compile your script as 64 bit then it would go to the correct location:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Holographic

However if you want to write to the 64 bit path when your script is compiled as 32 bit, then you can use HKLM64 for 64 bit and HKLM for 32 bit.  Personally I prefer using 32 bit compiled scripts otherwise you have to create two separate executables one for 64 bit and one for 32 bit, by using a 32 bit compiled script you can check to see which architecture for example:

If @OSArch = "x64" Then
    RegWrite("HKLM64\...)
Else
    RegWrite("HKLM\...)
EndIf

Hope that makes sense.

  • Like 1

Share this post


Link to post
Share on other sites
Strydr

Yes, that makes sense!  Wow, I'm glad I stopped to find out what was going on!  People with both 32bit and 64bit OS's might be using this: I would never have figured out where those bugs were coming from!!!!!

Thank you very very mcuh!!!

Share this post


Link to post
Share on other sites
Strydr

Not sure if I should make a separate thread or not...

Everything seems to be working except that I can't get it to write the key.  

A couple things of note in the following code:

OS build 16299 is the Fall update.  According to Microsoft, I can write, read and delete this key to my hearts content on the Fall version, however the key is only useful on the Spring update 17xxx.  

This is my function: 

Func _WMR_Reg_Op()

Local $TextKey1, $TextKey2, $ButtonOver, $ButtonDel, $WriteDelGUI, $TimerMsg, $RegWrite, $RegWrite2, $Holo_Proto_REG, $tempholder

If StringInStr("Win_10", @OSVersion) Then

        If @OSBuild >= 16299 Then
            $RegWrite = MsgBox(4, "OSVersion", "Congratulations!"  & @CRLF & @CRLF & _
                        'You have the Spring build of Windows or newer!' & @CRLF & @CRLF & _
                        'Would you like to write the needed Registry Key?')
                If $RegWrite = 6 Then
                    If @OSArch = "x64" Then
                        $Holo_Proto_REG = "HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Holographic\SupportedProtocols\Steam"
                        $tempholder = "64"
                    Else
                        $Holo_Proto_REG = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Holographic\SupportedProtocols\Steam"
                        $tempholder = "32"
                    EndIf

                    RegRead($Holo_Proto_REG, "")
                        If @Error > 0 Then
                            RegWrite($Holo_Proto_REG)
                            MsgBox(0, "KeyCheck", "The Key did not exist: now it does")
                            MsgBox(0,"flag", $tempholder)
                        Else
                            $RegWrite2 = MsgBox(3, "KeyCheck", "Your Registry already has this Key" & @CRLF & @CRLF & _
                                            'Would you like to:' & @CRLF & _
                                            'Overwrite it?    press -yes-' & @CRLF & _
                                            'Delete it?         press -no-' & @CRLF & _
                                            'Abort it?          press -cancel-')
                            If $RegWrite2 = 6 Then
                                RegWrite($Holo_Proto_REG)
                                MsgBox(0, "KeyCheck", "The Key existed but it has now been overwritten")
                            ElseIf $RegWrite2 = 7 Then
                                RegDelete($Holo_Proto_REG)
                                MsgBox(0, "KeyCheck", "The Key existed but it has now been removed")
                            Else
                                MsgBox(0, "KeyCheck", "The Key existed: Registry action aborted by User")
                            EndIf
                        EndIf
                EndIf
        Else
            MsgBox(0,"Sorry","Correct Operating System, but wrong Build.  You need the Windows10 Spring Build or newer." & @CRLF & _
                    'You are running Ver: ' & @OSBuild & '   You need Ver 17xxx')
        EndIf
Else
        MsgBox(0, "Wrong OS", "Sorry, but you must be running Windows10")
EndIf

EndFunc

Any ideas what I'm missing?

Thanks for the help!

Share this post


Link to post
Share on other sites
Subz

Can you try placing #RequireAdmin at the top of your script?

Share this post


Link to post
Share on other sites
Strydr

That worked!!  Thank you!

So can I put that into the function so that the security window is only called if someone wants to write the key? (as opposed to being at the top of the main script)

Using RegDelete only deleted the "Steam" part of it; it left the "supportedprotocols" behind.  I could just do it twice; it should delete the next in the tree which would be "supportedprotocols".  Is there a better way?

 

I'll try playing around to see if I can determine the answers later when I have time, but one thing that I do NOT want to "play" with:  what happens if I overwrite the key?  Anything detrimental?   To be clear:  the key exists and I use RegWrite to write it again.  Anything bad happen?  Duplicate entries or anything?

Again!  Thank you very very much for the help!

 

Share this post


Link to post
Share on other sites
Strydr
4 minutes ago, Strydr said:

I could just do it twice; it should delete the next in the tree which would be "supportedprotocols

I would make a second RegDelete entry for the "supportedprotocols" key.  This seems the way to go?

Share this post


Link to post
Share on other sites
Subz

Or you could just delete SupportedProtocols key, since steam is a sub-key, one thing I'm not sure about, when you say overwrite, if the key already exists it won't do anything, the data within the key will remain the same, you would have to include the valuename you want to overwrite for it to take effect.

With regards to #RequireAdmin, no can't be configured in a function, however you could check if the user is an Administrator by using IsAdmin() = False then MsgBox Please restart the executable by right clicking "Run As Administrator"

Share this post


Link to post
Share on other sites
AdamUL

There are multiple workarounds for the #RequireAdmin issue.  Here is one way.  Put the RegWrite calls in a separate script block, at the top of the script, that checks that the user has admin rights.  When you need to run them, you can re-execute the script, requesting Admin Token elevation using a function.  After the admin part of the script executes, it exits and returns to the main script.  See the example script below.  

MsgBox(0, "Test 1", "User is " & (IsAdmin() ? "" : "not ") & "Admin.")

If IsAdmin() Then 
    ;Put Regwrite function calls here.  
    MsgBox(0, "Is Admin?", "Yes, Admin.") ;Example.
    
    Exit
EndIf 

_RerunAsAdmin()

MsgBox(0, "Test 2", "User is " & (IsAdmin() ? "" : "not ") & "Admin.")


Func _RerunAsAdmin()
    Local $sParameters = ""
    If Not @Compiled Then
        $sParameters = '"' & @ScriptFullPath & '"'
    EndIf

    ShellExecuteWait(@AutoItExe, $sParameters, "", "runas")
    If @error Then Return MsgBox(16 + 262144, "ERROR!", "Unable to elevate to Admin due to UAC.")
    
EndFunc

 

Adam

 

Share this post


Link to post
Share on other sites
Strydr

And that should solve my problems!  Have I said "Thank you!" lately?  Thank you very very very much!

I have the impression that Microsoft will be using that key in the future so at some point that key may have a value.  For now, tho, it sounds as if "overwriting" is just a distraction that I should remove.  (after all, that's what rem's are for! :D)

Looks like the Admin issue will require some thought on how to proceed:  thanks guys!  Awesome advice!!!

Share this post


Link to post
Share on other sites
Earthshine

it's for Mixed Reality hardware. you should not be deleting anything from the registry if you did not put it there. when I got my first pc, i was registry edit happy. after messing up so many installations of windows, I learned to hands off. all repair utilities are utter garbage as well and often cause problems rather than solving anything.

Now I install windows once, and keep it for the life of the box usually, unless I get a new boot ssd

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
Strydr

Lol, don't worry.  I'm only deleting the Key that I wrote to begin with and I'm being careful.  I verified with Microsoft that I was safe to write and delete that key. 

I did the same thing a long time ago.  Now, unless I've got a good reason, I keep my fingers out the Registry.

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×