注册系统服务时,为什么要输入用户名和密码,能不能不输入?(在线等~~~)

刘物峰 2008-10-30 03:00:16
我在网上找一段代码:
System.Configuration.Install.AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller ( );
myAssemblyInstaller.UseNewContext = true;
myAssemblyInstaller.Path = filepath;
myAssemblyInstaller.Install ( stateSaver );//在这一步提示
myAssemblyInstaller.Commit ( stateSaver );
myAssemblyInstaller.Dispose ( );
//--Start Service
service.Start ( );
运行时为什么要输入用户名和密码?能不能不输入?
输入正确的,又说我没有权限?
...全文
137 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
acqy 2008-10-30
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 daihongliu 的回复:]
唉,我做事太不小心了,我一直是设置了的,Local System [acqy ]一说我去看了一下,是user
改了就好了,谢谢你!
[/Quote]

不客气!
刘物峰 2008-10-30
  • 打赏
  • 举报
回复
唉,我做事太不小心了,我一直是设置了的,Local System [acqy ]一说我去看了一下,是user
改了就好了,谢谢你!
刘物峰 2008-10-30
  • 打赏
  • 举报
回复
兄弟,我不想在命令行中加入,我想的是我点击一个按键就可以安装一个服务!
检查一下你的Installer的属性,记得有个地方改成Local System应该就可以了。我是设置了的!
tianbian_man 2008-10-30
  • 打赏
  • 举报
回复
mark
acqy 2008-10-30
  • 打赏
  • 举报
回复
你是做Windows Service么?检查一下你的Installer的属性,记得有个地方改成Local System应该就可以了。

一般情况下,并不是一定要创建一个Windows Service的工程,才能实现Windows Service。
我们比较常用的做法是,创建一个ConsoleApplication,然后在控制台程序中启动服务并使用Console.ReadLine()使程序不马上退出。
这样做便于调试
而要做成Windows Service,就直接在这个工程里添加一个Installer Class(项目上右键->添加->新项目,选择Installer Class),然后写类似下面的代码:

using System.ComponentModel;
using System.Configuration.Install;
using System.ServiceProcess;
using Mail360.DataManager.ServiceAdapter;

namespace DataManager
{
[RunInstaller(true)]
public class WindowsServiceInstaller : Installer
{
public WindowsServiceInstaller()
{
ServiceProcessInstaller processInstaller = new
ServiceProcessInstaller();
ServiceInstaller serviceInstaller = new ServiceInstaller();
processInstaller.Account = ServiceAccount.NetworkService;
serviceInstaller.DisplayName = "MyService";
serviceInstaller.Description = "Test my service";
serviceInstaller.ServiceName = "MyService";
serviceInstaller.StartType = ServiceStartMode.Automatic;
Installers.Add(processInstaller);
Installers.Add(serviceInstaller);
}
}
}



在上面的Installer Class里面就能够设置Account。
安装和卸载服务就简单了:
[code=BatchFile]
installutil /i "consoleApplication.exe"
installutil /u "consoleApplication.exe"
[/code]
david_anwei 2008-10-30
  • 打赏
  • 举报
回复
可以

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧