Jump to content

My regread code is returning blank and I'm' not sure why...


Go to solution Solved by rudi,

Recommended Posts

Hi all!
The messagebox is supposed to show the value written to the registry key called "PCVRFixer" located in HKLM startup. (CurrentVersion\Run). It's only showing blank. I need my script to be able to detect if it's been added to startup because my script is going to check and then offer to add itself to startup if the user wishes. This is the last step before I add this thing to example scripts. So of course, it has to go wrong. Especially since nothing else has gone wrong so far. :D

I added RequireAdmin because I figure we need admin to read and write HKLM Run tasks... right?
 

#RequireAdmin
#include <MsgBoxConstants.au3>

Local $sFilePath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "PCVRFixer")
MsgBox($MB_SYSTEMMODAL, "", "PCVRFixer is located at" & $sFilePath)

 

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to post
Share on other sites


 

4 minutes ago, OJBakker said:

Check the values of @error and @extended after the RegRead.

How do I check the @Error? I've never quite figured out what I'm supposed to do.
Do I just?
 

$test = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "PCVRFixer")
MsgBox( 0, "", @error )

 

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to post
Share on other sites
5 minutes ago, rudi said:

Please read up the documentation for RegRead()

especially the part covering 32/64 bit: "When running on 64-bit Windows ..."

 

 

Hey, that worked! Thanks a ton!

For future refrence, how should I use @Error? Can I just call it from a message box right after I run a line of code?

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to post
Share on other sites
$test = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "PCVRFixer")
MsgBox(0, '', "$Test = " & $test & @CRLF & _
        "@error = " & @error & @CRLF & _
        "@extended = " & @extended)

try instead:

 

$test = RegRead("HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "PCVRFixer")
MsgBox(0, '', "$Test = " & $test & @CRLF & _
        "@error = " & @error & @CRLF & _
        "@extended = " & @extended)

And yes, @error and @extended have to be evaluated before the next code line is following, that will alter these two makros.

 

To save them for later examination store them in some variable:

 

$err=@error
$ext=@extended
; other code

switch $err
    case ...
endswitch

 

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to post
Share on other sites

@rudi@OJBakker

Okay, so, now it's reading the registry, but for some reason, it refuses to write to the registry. Any chance you might be able to figure out why that's happening?

 

;If A
If Not StringInStr(@ScriptFullPath, ".exe") = 0 Then ;If we are compiled then,
    ;If B
    If Not RegRead("HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "PCVRFixer") = @ScriptFullPath Then ;Check if we are running on startup. If not then,

;Lets ask if the user wants to run us on startup, and offer to not bug them in case their answer is final.
;If C
If Not RegRead("HKLM64\Software\OpenGenerationSoftware\PCVRFixer", "Asktorunonstartup") = "NoMore" Then ;Make sure the user hasn't already told us not to ask again. If they have not then,
;If D
If Not IsDeclared("Startup") Then Local $Startup ;Declare Local $Startup
;Ask the question.
$Startup = MsgBox(262179,"Would you like to add VR Fixer to startup?","Hi! PCVR Fixer has noticed that it's not running on startup. If you add it to startup, you won't have to run tihs program, making it set and forget software. Would you like for PCVR Fixer to add itself to startup? If you slect No, the program will ask next time you run it. " & @CRLF & "If you click 'Cancel', it won't offer to add itself to startup again. ")
Select
    Case $Startup = 6 ;Yes
     RegWrite( "HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "PCVRFixer", @ScriptFullPath )
    Case $Startup = 7 ;No
     ;Nothing. We do nothing if te user clicks no.
    Case $Startup = 2 ;Cancel
     RegWrite( "HKLM64\Software\OpenGenerationSoftware\PCVRFixer", "Asktorunonstartup", "REG_SZ", "NoMore" )
EndSelect
    EndIf ;If A
EndIf ;If B
EndIf ;If C

 

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to post
Share on other sites

I took this code by itself and ran it from my documents folder, where the main script will be. It's not working, it refuses to write to registry.
Let me make sure that it's not needing admin.

EDIT: Nope, this didn't work either.
I've tried both of these.

#RequireAdmin
RegWrite( "HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "PCVRFixer", @ScriptFullPath )

RegWrite( "HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "PCVRFixer", @ScriptFullPath ){/code]
Edited by Draygoes
Added failure.
Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to post
Share on other sites
16 minutes ago, rudi said:
$test = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "PCVRFixer")
MsgBox(0, '', "$Test = " & $test & @CRLF & _
        "@error = " & @error & @CRLF & _
        "@extended = " & @extended)

try instead:

 

$test = RegRead("HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "PCVRFixer")
MsgBox(0, '', "$Test = " & $test & @CRLF & _
        "@error = " & @error & @CRLF & _
        "@extended = " & @extended)

And yes, @error and @extended have to be evaluated before the next code line is following, that will alter these two makros.

 

To save them for later examination store them in some variable:

 

$err=@error
$ext=@extended
; other code

switch $err
    case ...
endswitch

 

I did this as well but for regwrite instead of read.

 

$test = RegWrite("HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "PCVRFixer")
MsgBox(0, '', "$Test = " & $test & @CRLF & _
        "@error = " & @error & @CRLF & _
        "@extended = " & @extended)


 

---------------------------

---------------------------
$Test = 0

@error = 0

@extended = 0
---------------------------
OK   
---------------------------

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to post
Share on other sites

Check your RegWrite parameters.  The third parameter is supposed to be the type and not the value you want to write. I'm not sure why you don't get a value of -2 in @extended because you are calling RegWrite with an invalid type parameter.

 

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...