Jump to content
Sign in to follow this  
csmithknott

Passing $Variable in command line

Recommended Posts

csmithknott

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!

Share this post


Link to post
Share on other sites
Negative1

$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.

Share this post


Link to post
Share on other sites
PsaltyDS

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.

:blink:


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

Share this post


Link to post
Share on other sites
csmithknott

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. :blink:

Share this post


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
Sign in to follow this  

×