简体   繁体   English

如何从Visual Studio 2010安装程序运行schtasks.exe?

[英]How to run schtasks.exe from Visual Studio 2010 installer?

I have aa Visual Studio 2010 solution with multiple C++ projects, and a windows installer project. 我有一个包含多个C ++项目的Visual Studio 2010解决方案,以及一个Windows安装程序项目。

The installer works for the most part installing the deployment directories, and applications, and various shortcuts. 安装程序大部分用于安装部署目录,应用程序和各种快捷方式。 the last thing I would like the installer to do is install a couple of Tasks in the Windows Task Scheduler. 我希望安装程序做的最后一件事是在Windows任务计划程序中安装几个任务。

I can run the schtask.exe from the command line and it works fine. 我可以从命令行运行schtask.exe,它工作正常。 I thought I could then just copy this same command to a CustomAction within the installer. 我想我可以将这个相同的命令复制到安装程序中的CustomAction。 However this does not work and the installation fails with the message "There is a problem with this windows installer package. A program required for this install could not be run..." 但是这不起作用,安装失败并显示消息“此Windows安装程序包存在问题。无法运行此安装所需的程序...”

I have add the System Folder to the FileSystem setup, and in the CustomActions I have added a CustomAction under the Commit node. 我已将System Folder添加到FileSystem设置,在CustomActions中,我在Commit节点下添加了CustomAction。

The CustomAction sourcePath property is pointed to C:\\Windows\\System32\\schtasks.exe and the Arguments property is "/create /tn ""WiwoCLLauncher"" /tr C:\\ECS\\WiwoCLLauncher.exe /sc ONSTART" CustomAction sourcePath属性指向C:\\ Windows \\ System32 \\ schtasks.exe,Arguments属性为“/ create / tn”“WiwoCLLauncher”“/ tr C:\\ ECS \\ WiwoCLLauncher.exe / sc ONSTART”

Can anyone give some insight on how to run schtasks.exe from the VS2010 installer? 任何人都可以从VS2010安装程序中了解如何运行schtasks.exe?

The CustomAction sourcePath property is pointed to C:\\Windows\\System32\\schtasks.exe CustomAction sourcePath属性指向C:\\ Windows \\ System32 \\ schtasks.exe

That does not do what you hope it does. 并不是你希望它做什么。 The setup project builder will actually include schtasks.exe from your machine into the MSI file. 安装项目构建器实际上您机器上的schtasks.exe 包含到MSI文件中。 And will try to deploy it onto the target machine. 并将尝试将其部署到目标计算机上。 Luckily the Windows File System Protection feature prevents you from murdering the user's operating system. 幸运的是,Windows文件系统保护功能可以防止您谋杀用户的操作系统。 But does leave you with a failed install. 但是安装失败会让你失望吗?

The Setup builder doesn't give you enough flexibility to prevent the builder from doing this. “安装”构建器不会为您提供足够的灵活性来阻止构建器执行此操作。 Technically you can use Orcas to edit the MSI file afterwards (remove the deployment item and change the custom action type from 2 to 34) but that gets to be rather painful. 从技术上讲,您可以使用Orcas之后编辑MSI文件(删除部署项并将自定义操作类型从2更改为34)但这会非常痛苦。 As long as you want to stick with the VS builder then do consider writing a wee little bit of C# code that uses Process.Start() to run the command. 只要您想坚持使用VS构建器,那么考虑编写一些使用Process.Start()来运行命令的C#代码。

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

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