我使用Inno Setup为我的应用程序创建一个安装导入XML格式的计划任务在Inno Setup的
我怎么能计划任务使用Inno Setup的一个XML文件添加到用户的PC?
我已经创建了我的开发PC上的计划任务,并将其导出到一个名为ServerSwitchScheduledTask.xml
文件我已经包含在我安装此文件。我目前正在将此文件的副本放置在应用程序的文件夹中,如下所示:
[Setup]
PrivilegesRequired=admin
[Files]
Source: "ServerSwitchScheduledTask.xml"; DestDir: "{app}"; Flags: ignoreversion
这可按预期工作。但是,我也想将计划任务实际导入用户PC。
我想这
Filename: "schtasks.exe"; \
Parameters: "/create /XML {app}\ServerSwitchScheduledTask.xml /tn ServerSwitch";
导致没有错误,我可以看到(在调试输出Inno Setup的),但不计划任务添加到用户的PC
然后我读了文档为schtasks.exe
/RP [口令]
指定Pa的值ss用于用/ RU参数指定的用户。要提示输入密码,该值必须是“*”或没有值。该系统帐户的密码被忽略。该参数必须与/ RU或/ XML开关结合使用。
所以我把它改为:
Filename: "schtasks.exe"; \
Parameters: "/create /RP * /XML {app}\ServerSwitchScheduledTask.xml /tn ServerSwitch";
我想到这提示上安装一个密码,但它并没有,仍然不会产生错误或添加计划任务。
我一直在使用这样的代码段也试过:
[Files]
Source: "ServerSwitchScheduledTask.xml"; DestDir: "{app}"; Flags: ignoreversion; BeforeInstall: BeforeInstallProc
[Code]
procedure BeforeInstallProc;
var
ResultCode: Integer;
begin
{ Launch Notepad and wait for it to terminate }
if Exec('{sys}\schtasks.exe', '/create /XML ServerSwitchScheduledTask.xml /tn ServerSwitch', '', SW_SHOW,
ewWaitUntilTerminated, ResultCode) then
begin
{ handle success if necessary; ResultCode contains the exit code }
MsgBox('Task sceduled', mbConfirmation, MB_OK);
end
else begin
if MsgBox('Unable to schedule Server Switch to start on login. See AUTO RUN section of the REAM_ME#13#10#13#10Continue anyway?', mbConfirmation, MB_YESNO) = IDYES then
begin
{ user clicked Yes }
end;
{ handle failure if necessary; ResultCode contains the error code }
WizardForm.Close;
{ MsgBox('Intsataller says: ', mbCriticalError, MB_OK); }
end;
end;
我得到这个方法
我也试过这样显示的Unable to schedule Server.....
消息:
[Files]
Source: "ServerSwitchScheduledTask.xml"; DestDir: "{app}"; Flags: ignoreversion; AfterInstall: AfterInstallProc
[Code]
procedure AfterInstallProc;
var
ResultCode: Integer;
begin
{ Launch Notepad and wait for it to terminate }
if Exec('{sys}\schtasks.exe', '/create /XML "C:\Program Files (x86)\Server Tools\ServerSwitchScheduledTask.xml" /tn ServerSwitch', '', SW_SHOW,
ewWaitUntilTerminated, ResultCode) then
begin
{ handle success if necessary; ResultCode contains the exit code }
MsgBox('Task sceduled', mbConfirmation, MB_OK);
end
else begin
if MsgBox('Unable to schedule Server Switch to start on login. See AUTO RUN section of the REAM_ME. Continue anyway?', mbConfirmation, MB_YESNO) = IDYES then
begin
{ user clicked Yes }
end;
{ handle failure if necessary; ResultCode contains the error code }
WizardForm.Close;
{ MsgBox('Intsataller says: ', mbCriticalError, MB_OK); }
end;
end;
这也失败了,但是,随着安装的文件,我可以在命令行中成功地调用它像这样:
C:\Windows\system32>schtasks.exe /create /XML "C:\Program Files (x86)\Server Too
ls\ServerSwitchScheduledTask.xml" /TN ServerSwitch
SUCCESS: The scheduled task "ServerSwitch" has successfully been created.
我无法重现您的问题。您的Inno安装脚本适用于从Windows Scheduler导出的简单任务。所以我认为这个问题是特定于您的特定任务的,而实际上Inno Setup没有这样的问题。如果您从提升的命令提示符('cmd.exe')执行它,您的'schtasks'命令是否适用于您? –
@MartinPrikryl我认为你是对的,我觉得这与文件路径中的空格有关。我将xml文件安装到'C:\ Program Files(x86)\ Server Too ls \ ServerSwitchScheduledTask.xml'我可以用'C:\ Windows \ system32>命令行从那里运行它schtasks.exe /创建/ XML“C:\ Program Files文件(x86)\服务器太 ls \ ServerSwitchScheduledTask.xml”/ TN ServerSwitch 成功:计划任务“ServerSwitch”已成功创建.'但我不知道如何做到这一点Exec()命令或在“[Run]”部分 – DelightedD0D
是否正在使用您从命令行测试'schtasks.exe'的相同帐户运行安装程序?没有比“无法安排服务器”更多的细节吗? –