0

I created a task in MS Task Scheduler app using simple xml command approach:

SCHTASKS /CREATE /SC DAILY /TN "*Hebrew Localized Name Here*" /XML "C:\TEST.xml"

This xml has the arguments string (to run a file) with a localized (hebrew/arabic) path name like this:

...    
 <Exec>
      <Command>"C:\fold\pythonw.exe"</Command>
      <Arguments>"C:\Hebrew_Localized_folder_here\script.py"</Arguments> 
 </Exec>    
...

BUT, finally the file path(Arguments here) added to scheduler ui shows irrelevant characters (like, ان تمام آزادیوں اور حقوق ک), and the task fails to execute.

Task Scheduler task's property (image)

Anyone had similar issue!? Please help. Thanks a lot.

Joe
  • 97
  • 10
  • It looks like UTF-8 has been decoded as the system ANSI codepage. Does the XML file specify the encoding? e.g. "" – Eryk Sun Nov 23 '19 at 00:55
  • @Eryk Sun: Thanks for your reply. Yes, the xml has the encoding in its declaration ' ' – Joe Nov 23 '19 at 21:12
  • Are you certain the file is saved as UTF-16? – Eryk Sun Nov 23 '19 at 21:48
  • Yes. The xml saved has the encoding for UTF-16. Weird thing is, if I use import option within that TaskScheduler app for this xml, the path looks/works fine. But, as i stated in my problem, if i use that command , which is what i need, it gives path error. – Joe Nov 23 '19 at 22:03
  • If it's a UTF-16 file, then it's probably a problem in schtasks.exe. The example in your question looks like UTF-8 that's been improperly decoded. If I encode it back as 1252 and decode as UTF-8, the result is a phrase in Urdu that translates to English as "all these freedoms and rights". – Eryk Sun Nov 23 '19 at 22:35
  • Thanks for your reply. My task xml schema has that UTF-16 encoding '' – Joe Nov 23 '19 at 22:44
  • If it's saved as UTF-8, then it should be declared in the XML as `encoding="utf-8"`. – Eryk Sun Nov 23 '19 at 22:58
  • @Eryk Sun: Thanks a ton for your quick pointers. The question in this related link helped resolving. https://stackoverflow.com/questions/5248400/why-does-the-xdocument-give-me-a-utf16-declaration – Joe Nov 25 '19 at 17:48
  • Okay, you should write an answer with the details that worked for you with schtasks.exe. – Eryk Sun Nov 25 '19 at 18:16

1 Answers1

0

Reference link: why does the Xdocument give me a utf16 declaration?

So using

doc.Save(xmlfilePath);

instead of File.WriteAllText(xmlfilePath, doc.ToString()); to save my edited xml helped resolving the localization issue.

Joe
  • 97
  • 10