0

The following is the command to be run.

C:\Windows\System32\schtasks.exe /run /tn "WAU Manager"

The following "TargetPath" does not work because there are quotes inside the quotes.

Set A = CreateObject("WScript.Shell")
Desktop = A.SpecialFolders("Desktop")
Set B = A.CreateShortcut(Desktop & "\Testing.lnk")
B.TargetPath = "C:\Windows\System32\schtasks.exe /run /tn "WAU Manager""
B.Save

I have tried "chr(34)" in the following one, which does not work either.

B.TargetPath = "C:\Windows\System32\schtasks.exe /run /tn " &chr(34)& "WAU Manager" &chr(34) 

The following ones do not work either. Doubling the literal quotes does not fix the problem.

B.TargetPath = "C:\Windows\System32\schtasks.exe /run /tn ""WAU Manager"""
B.TargetPath = """C:\Windows\System32\schtasks.exe"" ""/run /tn"" ""WAU Manager"""
B.TargetPath = """C:\Windows\System32\schtasks.exe /run /tn"" ""WAU Manager"""
B.TargetPath = "C:\Windows\System32\schtasks.exe /run /tn" "WAU Manager"
B.TargetPath = "C:\Windows\System32\schtasks.exe /run /tn" ""WAU Manager""

Const Quote = """"
B.TargetPath = "C:\Windows\System32\schtasks.exe /run /tn " & Quote & "WAU Manager" & Quote

How can I make it work?

Matthew Wai
  • 962
  • 7
  • 14
  • Double the literal quotes `B.TargetPath = "C:\Windows\System32\schtasks.exe /run /tn ""WAU Manager"""`. – user692942 Jan 22 '20 at 13:48
  • I just tried doubling the literal quotes, which does not fix the problem. – Matthew Wai Jan 22 '20 at 13:57
  • Please read my question again. I have tried a few more methods, none of which works. – Matthew Wai Jan 22 '20 at 14:32
  • `Set TS = CreateObject("Schedule.Service")` `TS.Connect("DESKTOP-UCDGI39") ` `Set rootFolder = TS.GetFolder("\")` `Set tasks = rootFolder.GetTasks(0) ` `If tasks.Count = 0 Then` `Wscript.Echo "No tasks are registered."` `Else` `WScript.Echo "Number of tasks registered: " & tasks.Count` `For Each Task In Tasks` `A=Task.Name` `A = A & " " & Task.NextRunTime` `wscript.echo A` `Next` `End If` –  Jan 22 '20 at 16:05
  • https://stackoverflow.com/a/13129295/692942 – user692942 Jan 22 '20 at 17:03
  • @Lankymart, the .xml is **D:\WAU Manager.xml**. I just tried this **`TargetPath = """C:\Windows\System32\schtasks.exe"" \\server\share\D:\WAU Manager.xml"`** and this **`TargetPath = """C:\Windows\System32\schtasks.exe"" \\D:\WAU Manager.xml"`**. Neither of them worked. My .xml file is on drive D rather than a server or shared folder. – Matthew Wai Jan 23 '20 at 08:47

0 Answers0