joshtbailey Posted October 7, 2011 Posted October 7, 2011 (edited) I'm writing a service using Services.au3 to automatically execute a command after the service starts. At the start of my script I have the following variable declared: Global $args = @LogonServer & "\testdir\testfile" WriteLog($args) The $args variable is then used in the _Svc_Main() portion of the script later on: WriteLog($args) RunWait($program & ' /p "' & $args & '" /q ' & $additionalargs) Upon inspecting the output of my Logfile the first WriteLog($args) shows the correct value:\\server\testdir\testfileHowever, the second output of the $args variable is incorrect and shows the following:\testdir\testfile The variable is only used twice in the script, code is shown above. Manually setting the variable without using @Logonserver works. I have tried double setting the variable $args2 = $args without success. Any insight, suggestions, or solutions would be greatly appreciated. Thank you. Edited October 7, 2011 by joshtbailey
water Posted October 8, 2011 Posted October 8, 2011 (edited) Somewhere in your script you change the variable. This could be by manually assigning a new value e.g. $args = "New Value". Or by passing it as a paramter to a function where the parameter is referenced ByRef and then changed in the function. The variable might be changed in one of your include files (though it's bad programming style) $args = 1 ConsoleWrite($args & @LF) _AFunction($args) ConsoleWrite($args & @LF) Exit Func _AFunction(ByRef $param1) $param1 = 2 EndFunc ;==>_AFunction Rename your variable to something unique e.g. $xyz and see if it still happens. Edited October 8, 2011 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
joshtbailey Posted October 9, 2011 Author Posted October 9, 2011 (edited) Thank you for your response. The code above is a representation of the actual code. My variable name is $keyfile1. I will need to trace all the functions but I highly doubt that the variable is used somewhere else. In addition, the variable $keyfile1 is not passed into a function but is referenced inside of the _Svc_Main() function, hence the use of Global. I have tried not using the variable but instead putting everything inside of the RunWait command but the results are the same. It seems that whenever I use the @LogonServer variable inside of the _Svc_Main() function, it will not resolve. Edited October 9, 2011 by joshtbailey
water Posted October 9, 2011 Posted October 9, 2011 I haven't used it myself but you could give the " a try. Step through the script and you'll see when and where the variable changes. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
joshtbailey Posted October 11, 2011 Author Posted October 11, 2011 Thank you for your help. I was unable to get the Graphical AutoIt Debugger to run without crashing, however, after several more attempts and trying different methods of variable setting, such as writing the variable to a file and reading the file, ( did not work ) I feel that the Service.au3 UDF does not allow or inhibits the use of these variables. I have taken a different approach and instead of using the @LogonServer variable I am programmatically specifying the domain controllers based on the workstations network address, in addition I am also setting a static backup file location if the domain controller is unavailable. Thank you "water" for all of your assistance and in pointing me in the right direction.
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