Draygoes Posted November 12, 2022 Share Posted November 12, 2022 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. 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 comment Share on other sites More sharing options...
OJBakker Posted November 12, 2022 Share Posted November 12, 2022 Check the values of @error and @extended after the RegRead. Link to comment Share on other sites More sharing options...
Solution rudi Posted November 12, 2022 Solution Share Posted November 12, 2022 Please read up the documentation for RegRead() especially the part covering 32/64 bit: "When running on 64-bit Windows ..." Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
Draygoes Posted November 12, 2022 Author Share Posted November 12, 2022 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 comment Share on other sites More sharing options...
Draygoes Posted November 12, 2022 Author Share Posted November 12, 2022 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 comment Share on other sites More sharing options...
rudi Posted November 12, 2022 Share Posted November 12, 2022 (edited) $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 November 12, 2022 by rudi Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
Draygoes Posted November 12, 2022 Author Share Posted November 12, 2022 @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 comment Share on other sites More sharing options...
Draygoes Posted November 12, 2022 Author Share Posted November 12, 2022 (edited) 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 November 12, 2022 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 comment Share on other sites More sharing options...
Draygoes Posted November 12, 2022 Author Share Posted November 12, 2022 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 comment Share on other sites More sharing options...
OJBakker Posted November 12, 2022 Share Posted November 12, 2022 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 comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now