安装程序中服务的注册问题 我用VS2005(C#)写了一个Windows服务程序和另外一个窗体程序,现在要将两个程序合在一起做成一个安装包,请问如何在制作安装文件的时候能自动注册windows服务程序?在网上查了很多资料,都是在单个windows服务程序的解决方案里面再添加一个安装程序,但是我是有多个分开的项目,要单独建立一个安装项目,不知道怎么操作,望高手指点! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 要用到安装服务的InstallUtil.exe工具。打包的时候加一个BAT文件,里面写上安装服务的命令:InstallUtil -i 服务程序集文件名在安装的时候调用这个批处理文件就行了。 请问如何在安装的时候调用或者运行这个bat文件?另外,有没有通过VS2005直接设置就可以达到安装windows服务的办法? 就是在安装的时候执行一个函数,里面调用命令行,然后用Process.Start(@"C:\bat.BAT");这个会显示命令行窗口。如果楼主不想显示,可以不用BAT文件,直接在代码中调用CMD。参考这个Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = true; //不显示命令行窗口 p.Start(); p.StandardInput.WriteLine("InstallUtil -i 服务程序集文件名"); //确保InstallUtil在当前目录下 都是在单个windows服务程序的解决方案里面再添加一个安装程序楼主说的是安装服务的程序,这个是添加Windows服务必须的。就是说楼主要在服务的解决方案中添加一个安装程序,代码怎么写楼主可以搜索一下,网上资料很多。然后把所有项目打包安装,这方面楼主可以参考C#程序打包与部署c#程序打包,同时把netframework也打包进去关于C#程序打包问题!在这个安装过程中调用cmd安装服务。 我也遇到过楼主这样的问题,自已先做一个安装服务启动程序,程序如下 static int Main(string[] args) { if (args.Length > 0) { System.Diagnostics.Process process = new Process(); if (System.IO.File.Exists(Application.StartupPath + @"\InstallUtil.exe")) { process.StartInfo.FileName = Application.StartupPath + @"\InstallUtil.exe"; if (args.Length > 1 && System.IO.File.Exists(Application.StartupPath + @"\" + args[1])) try { System.IO.FileStream _file = System.IO.File.OpenWrite(Application.StartupPath + @"\" + args[1]); _file.Close(); } catch { return -1; } try { process.StartInfo.Arguments = (args.Length > 1 ? args[0] + " " + '"' + Application.StartupPath + @"\" + args[1] + '"' : '"' + Application.StartupPath + @"\" + args[0] + '"'); process.Start(); } catch { } } else { MessageBox.Show(Application.StartupPath + " " + args[0]); } } System.Threading.Thread.Sleep(2000); return 0; }将InstallUtil.exe以及上面生成的可执行软件也打包到安装包里 然后在安装的自定义操作里,在提交里面增加生成的程序,并将 arguments 设置为你的服务程序(例server.exe) 同时将installerclass设置为false这样在安装时就会自动注册服务了 学习 还可以用这个 AssemblyInstaller Installer = new AssemblyInstaller(); IDictionary saveState = new Hashtable(); Installer.UseNewContext = true; Installer.Path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "服务.exe"); saveState.Clear(); Installer.Install(saveState); Installer.Commit(saveState); Installer.Dispose();安装服务 参考http://topic.csdn.net/u/20071122/14/79750198-12a2-4fbb-88c2-aebcf10d93af.htmlhttp://blog.csdn.net/selfxd/archive/2007/07/17/1694808.aspx 查询临时表出错,求解 .net读取问题 创建线程过多的问题?! Combobox绑定数据只改变下拉列表,而不改变Text值的办法, 多个客户端不定时到一个服务器端发送数据,用什么方式好? 想用winfrom+2008+c#写个程序,最小化驻留在任务栏上,用于每隔1小去运行一次updata.asp。小弟先感谢前辈了! 左右两个按钮 点击按钮月份增减 类似IIS的页脚的功能 X509Certificate2UI这个C#自带的恶控件如何才能居中显示? C#。winform 窗体跳转,数据传输,涉及父窗体,子窗体 C# winform 小型游戏中怎样记录怪物移动的位置
InstallUtil -i 服务程序集文件名
在安装的时候调用这个批处理文件就行了。
Process.Start(@"C:\bat.BAT");
这个会显示命令行窗口。如果楼主不想显示,可以不用BAT文件,直接在代码中调用CMD。参考这个Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true; //不显示命令行窗口
p.Start();
p.StandardInput.WriteLine("InstallUtil -i 服务程序集文件名"); //确保InstallUtil在当前目录下
楼主说的是安装服务的程序,这个是添加Windows服务必须的。就是说楼主要在服务的解决方案中添加一个安装程序,代码怎么写楼主可以搜索一下,网上资料很多。
然后把所有项目打包安装,这方面楼主可以参考
C#程序打包与部署
c#程序打包,同时把netframework也打包进去
关于C#程序打包问题!
在这个安装过程中调用cmd安装服务。
static int Main(string[] args)
{
if (args.Length > 0)
{
System.Diagnostics.Process process = new Process();
if (System.IO.File.Exists(Application.StartupPath + @"\InstallUtil.exe"))
{
process.StartInfo.FileName = Application.StartupPath + @"\InstallUtil.exe";
if (args.Length > 1 && System.IO.File.Exists(Application.StartupPath + @"\" + args[1]))
try
{
System.IO.FileStream _file = System.IO.File.OpenWrite(Application.StartupPath + @"\" + args[1]);
_file.Close();
}
catch
{
return -1;
}
try
{
process.StartInfo.Arguments = (args.Length > 1 ? args[0] + " " + '"' + Application.StartupPath + @"\" + args[1] + '"' : '"' + Application.StartupPath + @"\" + args[0] + '"');
process.Start();
}
catch
{ }
}
else
{
MessageBox.Show(Application.StartupPath + " " + args[0]);
} }
System.Threading.Thread.Sleep(2000);
return 0;
}
将InstallUtil.exe以及上面生成的可执行软件也打包到安装包里 然后在安装的自定义操作里,在提交里面增加生成的程序,并将 arguments 设置为你的服务程序(例server.exe) 同时将installerclass设置为false
这样在安装时就会自动注册服务了
IDictionary saveState = new Hashtable();
Installer.UseNewContext = true;
Installer.Path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "服务.exe");
saveState.Clear();
Installer.Install(saveState);
Installer.Commit(saveState);
Installer.Dispose();安装服务
http://topic.csdn.net/u/20071122/14/79750198-12a2-4fbb-88c2-aebcf10d93af.html
http://blog.csdn.net/selfxd/archive/2007/07/17/1694808.aspx