antmar904 Posted May 17, 2017 Share Posted May 17, 2017 Hi, I know this has been asked many time but I can't seem to find the answer for what I want to do. I have one script asking the user if they want to reboot their computer, if they click yes then run script 2. Script 2 will then read the what the $Reboot varabile is set to (either 0 or 1) and perform a job depending on the return value. I can't seem to figure out how to get script two to read the $Reboot value from script 1 Script 1: While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnYes Global $Reboot = 1 Run(@ScriptDir & "\PatchDelayRed.exe") Exit Case $btnNo GUISetState(@SW_HIDE) msg3() Exit EndSwitch WEnd Script 2: AutoItSetOption("TrayIconHide", 1) Global $Reboot If $Reboot = 0 Then Do Sleep(5000) ;Sleep for two hours Run(@ScriptDir & "\PatchRebootRed_Eng.exe") Exit Until $Reboot = 1 ElseIf $Reboot = 1 Then MsgBox(0, "", "Rebooting Now") Exit EndIf Link to comment Share on other sites More sharing options...
232showtime Posted May 17, 2017 Share Posted May 17, 2017 what do you mean script 1 script2 ? are these script has separate SciteWindow? ill get to that... i still need to learn and understand a lot of codes Correct answer, learn to walk before you take on that marathon. Link to comment Share on other sites More sharing options...
antmar904 Posted May 17, 2017 Author Share Posted May 17, 2017 script 1 is a gui with a yes and no button. depending on what the user selects (yes or no) I set the $Reboot variable to either 1 (yes) or 0 (no) then I run script 2 which I need to be able to get the value of the variable $Reboot. Link to comment Share on other sites More sharing options...
Subz Posted May 17, 2017 Share Posted May 17, 2017 Just use $CmdLineRaw or $CmdLine[1] in your second script, so for example: Script 1 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnYes Global $Reboot = 1 Run(@ScriptDir & "\PatchDelayRed.exe True") Exit Case $btnNo GUISetState(@SW_HIDE) msg3() Exit EndSwitch WEnd Script 2 AutoItSetOption("TrayIconHide", 1) Global $Reboot = False If $CmdLine[0] >= 1 Then $Reboot = $CmdLine[1] If $Reboot = False Then Do Sleep(5000) ;Sleep for two hours Run(@ScriptDir & "\PatchRebootRed_Eng.exe") Exit Until $Reboot = True ElseIf $Reboot = True Then MsgBox(0, "", "Rebooting Now") Exit EndIf fraizor 1 Link to comment Share on other sites More sharing options...
alien4u Posted May 17, 2017 Share Posted May 17, 2017 1 hour ago, antmar904 said: script 1 is a gui with a yes and no button. depending on what the user selects (yes or no) I set the $Reboot variable to either 1 (yes) or 0 (no) then I run script 2 which I need to be able to get the value of the variable $Reboot. @antmar904 You can't read values of variables from one script/program in another script/program this is a misconception. Variables are subject to an Scope, as far as I know there is not Scope for a variable outside the program/script. What you need is to pass a parameter to your second script. You could take a quick read of Variables Scopes and Functions Parameters and that would clarify your misconception and eventually help you to figure it out or to find a better way/approach. Link to comment Share on other sites More sharing options...
Guest Posted May 17, 2017 Share Posted May 17, 2017 21 minutes ago, alien4u said: @antmar904 You can't read values of variables from one script/program in another script/program this is a misconception. Variables are subject to an Scope, as far as I know there is not Scope for a variable outside the program/script. Link to comment Share on other sites More sharing options...
mikell Posted May 17, 2017 Share Posted May 17, 2017 4 hours ago, antmar904 said: if they click yes then run script 2 Why not : if they click yes then run func_1, if they click no then run func_2 ? Link to comment Share on other sites More sharing options...
alien4u Posted May 18, 2017 Share Posted May 18, 2017 8 hours ago, gil900 said: My previous statement still valid since you are accessing the memory address of the variables, does that mean you modify the variable scope? does that make true the assumption that you can access/pass variables values from/to another program? My point here is that the OP should consider learning basic concepts which would help him to understand/accomplish in a better way what he is trying to do. (This is applying the premise: Teach a man how to Fish). After he knows how to fish then he can probably learn to catch fishes with his bare hands. Link to comment Share on other sites More sharing options...
benched42 Posted May 19, 2017 Share Posted May 19, 2017 Another solution is if Script 1 has "Reboot" selected then write a small text file with a unique name to the user's Documents folder. When Script 2 starts, check for that file - if it exists, delete it and know that the computer has been rebooted. Who lied and told you life would EVER be fair? Link to comment Share on other sites More sharing options...
antmar904 Posted May 25, 2017 Author Share Posted May 25, 2017 Thank you all for your responses. The route I took was to right to a text file (either 0 or 1) then read that text file with script 2. I'm sure all the other ways would work as well, but this is the way I went. Thanks again! Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted May 25, 2017 Share Posted May 25, 2017 2 hours ago, antmar904 said: Thank you all for your responses. The route I took was to right to a text file (either 0 or 1) then read that text file with script 2. I'm sure all the other ways would work as well, but this is the way I went. Thanks again! .INI Files & Registry Keys are both ways I do this kind of thing. If working with files I keep it in the Temp Directory, but I prefer registry as its away from the user and easy to reference. 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