设置一个程序必须在启动时从安装程序运行 [英] Set that a program has to run at startup from an installer

查看:118
本文介绍了设置一个程序必须在启动时从安装程序运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#.net应用4,我开始创建安装程序。

I've a C# .net 4 application, I'm starting to create the installer.

安装的程序工作正常,但我的客户希望该应用程序与窗口启动(这是一个永远顶工具,帮助他们管理自己的调用)。

The installed program works fine, but my customer want that the application start with window(it's an "Always of top" toolbar which help them to manage their call).

我想创造一个类安装程序,并在其中插入在注册表中的一个关键

I thought to create a "Class Installer", and in it insert a key in the registry.

我有两个问题:

第一:我怎样才能找到可执行路径?它可以安装之间切换。我发现某处Application.ExecutablePath,但似乎它位于成Application.Window.Forms所以我认为它不兼容WPF

First: How can I find the executable path? It can change between installation. I found somewhere a Application.ExecutablePath, but it seems it located into Application.Window.Forms so I think its not compatible with WPF

二:我需要插入此键在本地计算机的注册表。 ?是否有一个Windows安装程序的方式来指定用户必须具有管理员权限

Second: I need to insert this key in the registry of the local machine. Is there a way in a windows installer to specify that the user must have admin rights?

这是我开始的代码:

RegistryKey rkApp = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
rkApp.SetValue("CstStart", ???);



非常感谢你的帮助!

Thank you very much for your help!

编辑:我发现,我可以通过我的自定义操作的一些数据,有:

I found that I can pass to my Custom action some data, with :

/ DIR =[TARGETDIR] \

/DIR="[TARGETDIR]\"

通常它说我可以找回在CustomActionData。通过

Normally it's said I can retrieve it through the

this.Context.Parameters["DIR"];



不过....似乎在我的安装程序类,this.Context为空:(

But.... it seems that in my installer class, this.Context is null :(

EDIT2:上下文为空,因为我是在构造函数中做这个,我现在在做这个事件this.AfterInstall,现在我得到一个背景下,这似乎要包含一个VARassemblypath,其中包含正是我所需要的路径。

The Context was null because I was doing this in the constructor, I'm now doing this in the event this.AfterInstall and now I get a context, which seems to contains a var "assemblypath" which contains exactly the path I need.

推荐答案

我的假设是你从工作< STRONG>安装项目这里.....

My assumption is you're working from a Setup project here.....

要做到这一点的一种方式 - 我不是说这是最好的,但它可能是最简单的 - 是要做到以下几点:

one way to do this - I'm not saying it is the best but it is probably the easiest - is to do the following:

在文件系统选项卡,右键点击目标计算机上文件系统,添加特殊文件夹, 用户的启动文件夹,这样的文件夹出现在列表上。接下来,获得一个快捷方式到项目的输出(通过右键单击),然后拖动该快捷方式到启动文件夹。

所有的最后,既然你想要这个对所有用户,进入部署项目属性,并设置InstallAllUsers为真。

现在,有这种方法的一个警告,在应用程序不启动Windows启动时,但是,当有人登录。从你说你的项目(一个UI应用程序),这可能是确定的东西。

Now, there is a caveat with this approach, in that the app does not start when Windows starts, but when someone logs on. From what you say of your project (a UI app) this may be ok.

如果你真的想去黑客注册表你可以看看创建一个自定义操作DLL 。这一点,你可以写几乎你喜欢什么,并且在安装过程结束时,安装程​​序将调用您的DLL,所以你可以做你的东西。你可以传递东西,如可执行文件的路径作为参数到DLL(你会从安装对话框回暖,而不是从任何对象)。我不会进入这个详细的必须有这个在网络上的负载。

If you really want to go hacking the registry you could look at creating a custom action dll. This is something where you can write pretty much what you like, and at the end of the install process the setup program will call into your dll so you can do your stuff. You can pass things like the path of the executable as a parameter into the dll (which you would pick up from the installer dialog, not from any object). I won't go into this is detail as there must be loads on the web about this.

您应该知道,有可以传递的信息有限的到DLL - 如果没有记错可能低至256个字符。你可能会没事只是一个路径,但是当你开始做更多....

You should be aware that there is a finite amount of information you can pass into the dll - might be as low as 256 chars if memory serves. You'll probably be ok with just a path but when you start doing more....

至于检测用户是否是本地管理员,就是有点更靠谱,如果仅仅是因为自定义操作DLL被在安装结束,而不是在开始运行 - 所以你可以编写代码来找出当前用户在什么组,但机会是你已经吹起来在此之前,代码可以运行。我不相信 - 在Microsoft安装项目至少 - 有可能知道这个

As regards detecting whether a user is a local Admin, that is a bit more tricky, if only because the custom action dll gets run at the end of the installation rather than at the start - so you could write code to find out what groups the current user is in, but the chances are you'd have blown up before that code could run. I don't believe - in a Microsoft Setup project at least - that it is possible to know this.

这篇关于设置一个程序必须在启动时从安装程序运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆