关于.net下服务安装

本来我想从Process.Strat()用Installutil.exe 把服务程序安装上去的,但是调试时可以,发布后执行就怎么也不行了,什么错也不报,语句Process.Strat(...)也执行了,就是装不了 ,可能是哪里权限不对。

后来在网上找到.net里的几个类,可以用来安装:

TransactedInstaller和AssemblyInstaller

TransactedInstaller是用来安装多个AssemblyInstaller的,我只用AssemblyInstaller就够了!

要引用System.Configuration.Install.dll和

using System.Configuration.Install;

很简单

安装:

AssemblyInstaller myAssemblyInstaller;

myAssemblyInstaller=new AssemblyInstaller();

myAssemblyInstaller.UseNewContext=true;

myAssemblyInstaller.Path="XXXService.exe";

Hashtable mySavedState=new Hashtable()

myAssemblyInstaller.Install(mySavedState);

myAssemblyInstaller.Commit(mySavedState);

myAssemblyInstaller.Dispose();

卸载服务:

AssemblyInstaller myAssemblyInstaller;

myAssemblyInstaller=new AssemblyInstaller();

myAssemblyInstaller.UseNewContext=true;

myAssemblyInstaller.Path="XXXService.exe";

myAssemblyInstaller.CommandLine=new string[1]{"/u"};

myAssemblyInstaller.Uninstall(null);

myAssemblyInstaller.Dispose();

这2个类应该也可以制作一些小的安装程序!

posted @ 2022-06-16 12:07  ytsee  阅读(194)  评论(0)    收藏  举报