Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Microsoft VBScript compilation error: Expected ')'

Status
Not open for further replies.

RNF0528

MIS
Apr 4, 2006
115
US
I am attempting to create a schedule task using a vbs. I am getting an error
Microsoft VBScript compilation error: Expected ')'

I tried quotes but it doesn't work. Any help would be very appreciated.


WshShell.Run ("SCHTASKS /create /tn "MAint" /tr "\""c:\test.exe\" /sc daily /sd 12/29/2008 /st 06:00:00 /RU domain\username /RP Password"")

I can run the command from the command line with a problem.
 
What about this ?
WshShell.Run "SCHTASKS /create /tn MAint /tr c:\test.exe\ /sc daily /sd 12/29/2008 /st 06:00:00 /RU domain\username /RP Password"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Because of the way the command variables are set. We need to keep the integrity of the following quotes.

SCHTASKS /create /tn "MAint" /tr "\""c:\test.exe\" /sc daily /sd 12/29/2008 /st 06:00:00 /RU domain\username /RP Password

If i place this in the command line as is above it runs. I have to keep at least these quotes.

 
Something like:
Code:
"SCHTASKS /create /tn  " & Chr(34) & "MAint" & Chr(34) & " / tr; " & Chr(34) & "\" & Chr(34) & Chr(34) & "c:\test.exe\" & Chr(34) & " /sc daily /sd 12/29/2008 /st 06:00:00 /RU domain\username /RP Password"
Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
WshShell.Run "SCHTASKS /create /tn ""MAint"" /tr ""\""""c:\test.exe\"" /sc daily /sd 12/29/2008 /st 06:00:00 /RU domain\username /RP Password"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Because of the way the command variables are set
What is your real actual code ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I am trying to create a scheduled task on a workstation to run in at 0600hrs.

From this site below:


Code:

SCHTASKS /create /tn "MAint" /tr "\""c:\test.exe\" /sc daily /sd 12/29/2008 /st 06:00:00 /RU domain\username /RP Password
 
Thank you for helping me. Im sorry I am not sure what your asking? Is this what you need. Its a very simple script.


Code:

Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Run "SCHTASKS /create /tn "MAint" /tr "\""c:\test.exe\" /sc daily /sd 12/29/2008 /st 06:00:00 /RU domain\username /RP Password"

 
So, again, the following should work:
WshShell.Run "SCHTASKS /create /tn MAint /tr c:\test.exe /sc daily /sd 12/29/2008 /st 06:00:00 /RU domain\username /RP Password"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
ok, I understand it should work but it doesn`t.

"\""c:\test.exe\"
I think the problem is in the portion above.
Anyway, thanks for the help again I may try and attack this problem from another route. Dont want to waste anymore of your time.

 
And this ?
WshShell.Run "SCHTASKS /create /tn MAint /tr \""c:\test.exe\"" /sc daily /sd 12/29/2008 /st 06:00:00 /RU domain\username /RP Password"

Or even this ?
WshShell.Run "SCHTASKS /create /tn MAint /tr ""\""c:\test.exe\"""" /sc daily /sd 12/29/2008 /st 06:00:00 /RU domain\username /RP Password"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Going by PHV's suggestion from 6 Jan 09 11:30, his code works for me. That is, his code should (as far as I can see) be identical to entering the command line you entered on 6 Jan 09 11:16

Do you have the correct domain, username, and password? Does it create the task when you run the script? Looking in "Scheduled Tasks", does it show a Last Run Time and Next Run Time?
 
I know this is late to the game, but it looks like it should work, to test, I put the command string into a variable then put the variable into a msgbox so I could look at it. It looks identical to the OP's code and I don't see why it won't work. (note - due to linewrap issues, I put a space between each line of code).

Code:
Set wshShell = WScript.CreateObject("Wscript.Shell")

runString = "SCHTASKS /create /tn ""MAint"" /tr ""\""""c:\test.exe\"" /sc daily /sd 12/29/2008 /st 06:00:00 /RU domain\username /RP Password" 

runString2 = "SCHTASKS /create /tn " & Chr(34) & "MAint" & Chr(34) & " /tr " & Chr(34) & "\" & Chr(34) & Chr(34) & "c:\test.exe\" & Chr(34) & " /sc daily /sd 12/29/2008 /st 06:00:00 /RU domain\username /RP Password"

MsgBox runString & vbCr & runString2

wshShell.Run runString
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top