csmithknott Posted July 7, 2010 Share Posted July 7, 2010 All, Thank you for looking at this, I am sure that it is something dumb I am overlooking. I need to create a scheduled task on some machines. I have a script that does so successfully. ShellExecuteWait ('schtasks.exe', '/create /SC WEEKLY /D SUN /TN DB_Maintenance /TR "c:\program files\landesk\managementsuite\ldlogon\_DBMaint\_DBMaint.bat" /ST 00:15:00 /RU SYSTEM') What I need help with is substituting a variable into the command line. I am getting a value out of the registry using this: Global $LDMain = RegRead("HKLM\Software\LANDesk\ManagementSuite\Setup","LdmainPath") The value of LdmainPath is something like this: f:\myfiles\managementsuite\ There will always be \ldlogon\_DBMaint\_DBMaint.bat appended to whatever value the $LDMain pulls up. I can set the variable but am having problems when I try and use that variable in the command line for schtasks.exe. Here is what I have: ShellExecuteWait ('schtasks.exe', '/create /SC weekly /TN LANDesk_DB_Maintenance /D SUN /TR ' & $LDMain & ' \\ldlogon\\_DBMaint\\_DBMaint.bat /ST 00:15:00 /RU SYSTEM', @SW_HIDE) I have also tried this: ShellExecuteWait ('schtasks.exe', '/create /SC weekly /TN LANDesk_DB_Maintenance /D SUN /TR ' & $LDMain & ' "\\ldlogon\\_DBMaint\\_DBMaint.bat" /ST 00:15:00 /RU SYSTEM', @SW_HIDE) with no success. I am sure that I am messing up my quotes somewhere. I would appreciate any help! Thanks! Link to comment Share on other sites More sharing options...
Negative1 Posted July 7, 2010 Share Posted July 7, 2010 $string = '/create /SC weekly /TN LANDesk_DB_Maintenance /D SUN /TR ' & $LDMain & ' \\ldlogon\\_DBMaint\\_DBMaint.bat /ST 00:15:00 /RU SYSTEM' ShellExecuteWait ('schtasks.exe', $string , @SW_HIDE) ^^ I have used that as a work around before when I ran into this problem... If that doesn't work I would suspect $LDMain is not quite what you think it is. use a msgbox(0,"",$LDMain) and make sure it looks right... Then Msgbox(0,"",'/create /SC weekly /TN LANDesk_DB_Maintenance /D SUN /TR ' & $LDMain & ' \\ldlogon\\_DBMaint\\_DBMaint.bat /ST 00:15:00 /RU SYSTEM') make sure they both look right before adding them to shell execute What are we going to do tonight Brain?Same thing we do every night Pinky try to automate the world. Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 8, 2010 Share Posted July 8, 2010 ShellExecuteWait ('schtasks.exe', '/create /SC WEEKLY /D SUN /TN DB_Maintenance /TR "c:\program files\landesk\managementsuite\ldlogon\_DBMaint\_DBMaint.bat" /ST 00:15:00 /RU SYSTEM') What I need help with is substituting a variable into the command line. ; ... Here is what I have: ShellExecuteWait ('schtasks.exe', '/create /SC weekly /TN LANDesk_DB_Maintenance /D SUN /TR ' & $LDMain & ' \\ldlogon\\_DBMaint\\_DBMaint.bat /ST 00:15:00 /RU SYSTEM', @SW_HIDE) I have also tried this: ShellExecuteWait ('schtasks.exe', '/create /SC weekly /TN LANDesk_DB_Maintenance /D SUN /TR ' & $LDMain & ' "\\ldlogon\\_DBMaint\\_DBMaint.bat" /ST 00:15:00 /RU SYSTEM', @SW_HIDE) Your inclusion of the literal double quotes is wrong: ShellExecuteWait ('schtasks.exe', '/create /SC WEEKLY /D SUN /TN DB_Maintenance /TR "' & $LDMain & '\ldlogon\_DBMaint\_DBMaint.bat" /ST 00:15:00 /RU SYSTEM') AutoIt doesn't use string escape sequences, so the double backslashes "\\" are not required. It probably doesn't hurt, but if the registry value contains a trailing backslash, you probably wind up with doubles where $LDMain & '\ldlogon...' happens. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
csmithknott Posted July 14, 2010 Author Share Posted July 14, 2010 All, thank you for the help. I was able to get it working using this: $string = '/create /SC weekly /TN "LANDesk_DB_Maintenance" /D SUN /TR ' & Chr(34) & $LDMain & 'ldlogon\_DBMaint\_DBMaint.bat" /ST 00:15:00 /RU SYSTEM' The part that was a little strange was getting the " on the left side of the $LDMain variable. Using the Chr(34) seems a little hokey but it works like a champ. Thanks again, it was a great learning experience. 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