简体   繁体   English

在Windows 7中成功计划和运行的任务无法在Windows XP中运行

[英]Task that successfully scheduled and ran in Windows 7 could not run in Windows XP

I'm writing an application that will automatically schedule a task. 我正在编写一个将自动安排任务的应用程序。 It's supposed to work on both Windows 7 and Windows XP. 它应该可以在Windows 7和Windows XP上运行。 Unfortunately, I can't seem to run it on Windows XP. 不幸的是,我似乎无法在Windows XP上运行它。

In the setup .C file, I create the batch file and execute it. 在安装.C文件中,我创建批处理文件并执行它。 On the Windows 7 version, the task command looks like this: 在Windows 7版本上,task命令如下所示:

schtasks /create /tn \"<Script Name>\" /xml \"%s\\<Script XML>\"

Where %s is the working directory of the setup file (and the temporary batch script). 其中%s是安装文件(和临时批处理脚本)的工作目录。 This method has been tested on multiple Windows 7 machines and has been confirmed to work flawlessly on all of them. 此方法已在多台Windows 7计算机上进行了测试,并已确认在所有这些计算机上均可正常使用。 The reason that I decided to create the task using an XML file is because the task would not run on laptops, because by default the automatically-generated XML sets the script to NOT RUN on battery. 之所以决定使用XML文件来创建任务,是因为该任务无法在笔记本电脑上运行,因为默认情况下,自动生成的XML会将脚本设置为“电池不运行”。

When I tried to run the same application on Windows XP, however, I got the error that the /xml parameter was not recognized, so I rewrote the task schedule command for XP. 但是,当我尝试在Windows XP上运行相同的应用程序时,出现了无法识别/ xml参数的错误,因此我重写了XP的Task Schedule命令。 I knew that the XP computers this application would be running on were not laptops anyway, so I figured I didn't have to worry about the "don't run on battery" part of the auto-generated XML. 我知道该应用程序将在其上运行的XP计算机不是便携式计算机,因此我认为我不必担心自动生成的XML的“不用电池运行”部分。

Here's the task command for the Windows XP version: 这是Windows XP版本的任务命令:

schtasks /create /tn \"<Script Name>\" /tr \"%s\\<File To Run>.exe\" /sc minute /mo 60

When the application finishes installing, I get the status message "Could not run" on the task that I schedule. 应用程序完成安装后,我在计划的任务上收到状态消息“无法运行”。 I know that the executable that I'm scheduling DOES work, because it works when I run it manually (on both XP and Windows 7), so I'm wracking my brains trying to find a solution to this problem. 我知道我正在计划的可执行文件确实可以工作,因为当我手动运行它(在XP和Windows 7上)时,它都可以工作,所以我不知所措,试图找到解决此问题的方法。

If it matters, the executable is a C# file. 如果重要的话,可执行文件就是一个C#文件。 I logged the operating directory of the batch file and the C# executable, and they're both correct, so I'm not sure why I can't get this task to run automatically on Windows XP. 我记录了批处理文件和C#可执行文件的操作目录,它们都是正确的,所以我不确定为什么不能让此任务在Windows XP上自动运行。

If anyone can help me, I'd really appreciate it. 如果有人可以帮助我,我将非常感激。 I've been working on this problem for a few days now. 我已经为这个问题工作了几天。

Not having an XP machine or windows XP mode, this is all a stab in the dark. 没有XP机器或Windows XP模式,这一切都是黑暗的。

My main prediction is that i don't think you have to escape the quotes in /tn \\"<Script Name>\\" because i got an error while testing it. 我的主要预测是,我认为您不必转义/tn \\"<Script Name>\\"的引号,因为在测试时出现错误。 The same probably goes for /tr \\"%s\\\\<File To Run>.exe\\" . /tr \\"%s\\\\<File To Run>.exe\\" Even if either of those have spaces in them, normal (un-escaped) quotes should do. 即使其中任何一个包含空格,也应使用常规(未转义)引号。 I tested schtasks /Create /TN \\"name\\" /TR cmd /SC once /ST 12:00 in windows 7 and i got the error ERROR: The filename, directory name, or volume label syntax is incorrect. 我在Windows 7中测试了schtasks /Create /TN \\"name\\" /TR cmd /SC once /ST 12:00 ,并且收到错误ERROR: The filename, directory name, or volume label syntax is incorrect. .
Another thing is that you have /SC set to minute , but you also have /MO set to 60 . 另一件事是,您将/SC设置为minute ,但您也将/MO设置为60 I'd predict that that's fine on windows 7, but that might make XP complain. 我预测这在Windows 7上还可以,但是这可能会使XP抱怨。 setting /SC to HOURLY might be worth a shot (if XP has that option). /SC设置为HOURLY可能值得一试(如果XP具有该选项)。

As a final note, in general, windows utilities don't change massively between versions, especially if they don't display their version in the help file. 最后要说明的是,通常Windows实用程序在版本之间不会发生很大变化,尤其是如果它们未在帮助文件中显示其版本时。 It's unlikely that anything basic has changed since XP except for the /XML option (and also /V1 ). 自XP以来,除了/XML选项(以及/V1 )以外,几乎没有任何基本的变化。 If it works in 7, there's about a 95% chance that it'll work in XP, so you might try testing stuff out there too. 如果它可以在7中运行,那么它有95%的机会可以在XP中运行,因此您也可以尝试在其中进行测试。

As a side note, the escape character for CMD is ^ for seemingly all applications. 顺便提一下,对于似乎所有应用程序,CMD的转义字符为^ schtasks /Create /TN ^"name^" /TR cmd /SC once /ST 13:00 and schtasks /Create /TN "name" /TR cmd /SC once /ST 13:00 both worked perfectly, although they did overwrite each other and just have the name name without the quotes (windows probably stripped the quotes before creating them). schtasks /Create /TN ^"name^" /TR cmd /SC once /ST 13:00schtasks /Create /TN "name" /TR cmd /SC once /ST 13:00都可以正常工作,尽管它们确实覆盖了每个其他,只是名称name不带引号(Windows可能会在创建引号之前将其删除)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM