Jump to content

quotes issue


gcue
 Share

Recommended Posts

i have had an issue with this before where doubling up on the quotes has resolved the issue.

nothing i try now seems to work!

;$task = '"' & @ProgramFilesDir & '\ClipShare\ClipGet.exe" -copy ClipBoard_Image.jpg'
$task = '""' & @ProgramFilesDir & '\ClipShare\ClipGet.exe"" -copy ClipBoard_Image.jpg'

$create = RunWait("SCHTASKS /CREATE /S \\" & $asset & " /RU SYSTEM /TN """ & $task_name & """ /TR " & $task & " /SC ONCE /ST 00:00:00", "", @SW_HIDE)

if i create the task manually, it only needs quotes around the exe path.

Edited by gcue
Link to comment
Share on other sites

If you're just trying to construct the string, wouldn't this work?

$task = """" & @ProgramFilesDir & "\ClipShare\ClipGet.exe"" -copy ClipBoard_Image.jpg"

This gives you the following string in $task:

"C:\Program Files (x86)\ClipShare\ClipGet.exe" -copy ClipBoard_Image.jpg

Link to comment
Share on other sites

I can't debug your code but as a rule of thumb:

- you need quotes around something if that "something" has a white space in it.

Because apps which accept command-line arguments use the white space as a separator between arguments. A white spece somewhere screws up the number of paramaters and that is the purpose of the quotes to make the app conside what it is between as a single entity.

In your case, @ProgramFilesDir = "C:\Program Files" - see the white space? so you will need quotes around your executable name (with its own parameters in your case):

$task = '"' & @ProgramFilesDir & '\ClipShare\ClipGet.exe -copy ClipBoard_Image.jpg"'

To see clearly what I changed and how it looks - just use a msgbox to display the value of $task

The code is not tested so I can't guarantee that it will work 100% - it will involve further juggling with quotes.

(you may try also: $task = '""' & @ProgramFilesDir & '\ClipShare\ClipGet.exe" -copy ClipBoard_Image.jpg"' if my previous line doesn't work)

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

And like this ?

$create = RunWait ( 'SCHTASKS /CREATE /S \\' & $asset & ' /RU SYSTEM /TN "' & $task_name & '" /TR ' & $task & ' /SC ONCE /ST 00:00:00', '', @SW_HIDE )

$task = '"' & @ProgramFilesDir & '\ClipShare\ClipGet.exe" -copy ClipBoard_Image.jpg'
Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

And like this ?

$create = RunWait ( 'SCHTASKS /CREATE /S \\' & $asset & ' /RU SYSTEM /TN "' & $task_name & '" /TR ' & $task & ' /SC ONCE /ST 00:00:00', '', @SW_HIDE )

$task = '"' & @ProgramFilesDir & '\ClipShare\ClipGet.exe" -copy ClipBoard_Image.jpg'

That is his very first line and it didn't work.

That way, schtasks will assume that "-copy ClipBoard_Image.jpg" is another parameter and it is not.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

i tried all the suggestions.. no dice =/

i do output the variable.. looks fine with quotes around the exe path (which is what it wants) but for some reason the task doesnt create.

this one creates the task but doesnt run bc the quotes arent around the exe path..

$task = '"' & @ProgramFilesDir & '\ClipShare\ClipGet.exe -copy ClipBoard_Image.jpg"'

if i manually edit the task after the script creates it and add the quotes around the exe path and manually run the task it works...

i guess theres a specific way to do the quotes when doing it via command line with schtasks?

Link to comment
Share on other sites

Try this:

$task = '"' & @ProgramFilesDir & "\ClipShare\ClipGet.exe" & '"' & " -copy ClipBoard_Image.jpg"
ConsoleWrite($task)

As you'll see from the consolewrite, the quotes will show up like this "C:\Program Files\ClipShare\Clipget.exe" -copy ClipBoard_Image.jpg. You'll need to make sure that there's a space between the final quote around the program name and the parameter -copy so that they'll be seen as seperate.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

accidental double post

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Then the problem isn't with the quotes used, it's how you're creating the task. Post your script that you're using to try to create the task and then we can see where the problem is. If you are using the code I posted above, then the quotes should be in the right places.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Try this:

$task = '"' & @ProgramFilesDir & "\ClipShare\ClipGet.exe" & '"' & " -copy ClipBoard_Image.jpg"
ConsoleWrite($task)

As you'll see from the consolewrite, the quotes will show up like this "C:\Program Files\ClipShare\Clipget.exe" -copy ClipBoard_Image.jpg. You'll need to make sure that there's a space between the final quote around the program name and the parameter -copy so that they'll be seen as seperate.

$task = '"' & @ProgramFilesDir & '\ClipShare\ClipGet.exe" -copy ClipBoard_Image.jpg'
ConsoleWrite ( "$task : " & $task & @Crlf )
$task = '"' & @ProgramFilesDir & "\ClipShare\ClipGet.exe" & '"' & " -copy ClipBoard_Image.jpg"
ConsoleWrite ( "$task : " & $task & @Crlf )

$task : "C:\Program Files\ClipShare\ClipGet.exe" -copy ClipBoard_Image.jpg

$task : "C:\Program Files\ClipShare\ClipGet.exe" -copy ClipBoard_Image.jpg

it's the same result...

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

also didnt work... =/

this is the script

$task = '"' & @ProgramFilesDir & "\ClipShare\ClipGet.exe" & '"' & " -copy ClipBoard_Image.jpg"

    MsgBox(0,"",$task)

    $create = RunWait("SCHTASKS /CREATE /S \\" & $asset & " /RU SYSTEM /TN " & $task_name & " /TR " & $task & " /SC ONCE /ST 00:00:00", "", @SW_HIDE)
Edited by gcue
Link to comment
Share on other sites

i found this article on the quotes thing.. the example doesnt have a switch command so im not sure how to apply quotes to my situation but there's definitely something weird about using quotes with this command.

i am trying to use the command in cmd and am still getting errors =)

http://www.eggheadcafe.com/software/aspnet/30582270/schtasks-doesnt-run-programs-with-spaces.aspx

Link to comment
Share on other sites

I took your script and figured out how to make it work, try this and see if it's working for you.

$task = '"' & @ProgramFilesDir & "\ClipShare\ClipGet.exe  -copy ClipBoard_Image.jpg"""
MsgBox(0, "", $task)
$Asset = @ComputerName
$Task_Name = "TestScript"
$create = RunWait("SCHTASKS /CREATE /S \\" & $Asset & " /RU SYSTEM /TN " & $Task_Name & " /TR " & $task & " /SC ONCE /ST 00:00:00", "", @SW_HIDE)

It wouldn't work unless the quotes were around the whole task line, it would run, but the task wouldn't get created. Once I put the quotes around the whole task line, it worked fine.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

One more time :graduated:

$task = "'" & @ProgramFilesDir & "\ClipShare\ClipGet.exe" & "'" & " -copy ClipBoard_Image.jpg" 
MsgBox(0, "", $task)
$Asset = @ComputerName
$Task_Name = "TestScript"
$create = RunWait("SCHTASKS /CREATE /S \\" & $Asset & " /RU SYSTEM /TN " & $Task_Name & " /TR " & chr(34) & $task & chr(34) & " /SC ONCE /ST 00:00:00", "", @SW_HIDE)

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

One more try:

$task = """'" & @ProgramFilesDir & "\ClipShare\ClipGet.exe'" & " -copy ClipBoard_Image.jpg"""

This will output: "'C:\Program Files\ClipShare\ClipGet.exe' -copy ClipBoard_Image.jpg"

The problem with this command line is you need some quotes doubled (that I tried to do).

I tried to mix the quotes (simple and double) in order that schtasks to not get confused.

Tested and worked.

Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

There's an easier way than trying to recreate the task on every machine. You could create the task on one machine and then just copy it to every other machine. That way you'd know that it was created correctly and you wouldn't have to worry about the quotes issue any longer.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

One more try:

$task = """'" & @ProgramFilesDir & "\ClipShare\ClipGet.exe'" & " -copy ClipBoard_Image.jpg"""

This will output: "'C:\Program Files\ClipShare\ClipGet.exe' -copy ClipBoard_Image.jpg"

The problem with this command line is you need some quotes doubled (that I tried to do).

I tried to mix the quotes (simple and double) in order that schtasks to not get confused.

Tested and worked.

the task creates but it wont run until the quotes are double not single... if i try to run with single quotes it says "could not run" if i manually change it to double quotes it will run *sigh*

thanks for your help and efforts!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...