开发环境:VS2008
.net framework版本:2.0
操作系统:winxp sp2我编写了一个windows service程序,现要求以User的身份登录.在serviceProcessInstaller中把Account的属性设为User,编成功.然后使用InstallUtil.exe安装时弹出对话框要求输入用户名和密码,以domain\username,password的格式输入用户名及密码,但输入后点击确定即提示:在“安装”阶段发生异常。
System.ComponentModel.Win32Exception: 帐户名与安全标识间无任何映射完成。之后安装失败,回滚.请问:服务如果要以User登录而不是以Local System或者Local Service登录应该怎么做?如何设置登录的用户名及密码?

解决方案 »

  1.   

    能说得再详细点吗? 怎样在管理员的权限下? 我是以administrator登录的,service登录的用户也是administrator
      

  2.   


    不行,试过了.还是提示 :在“安装”阶段发生异常。
    System.ComponentModel.Win32Exception: 帐户名与安全标识间无任何映射完成。
      

  3.   

    服务本身是正常的,只要使用Local System就能正常安装.
      

  4.   

    嗯...
    也从来没有试过用user...
      

  5.   


    我也是第一次.这个服务的功能是使用PDF的虚拟打印机执行Word->PDF的转换.在winform程序里转换没有问题.但是写成服务以后就无法执行转换.在网上查了一点资料是这样说的:when you run that code in a windows form app, its running under your credentials. when you run it as a service it runs as the network service user. services dont typically interact w/ the users (and its a bad to allow it), so any apps it launches will be running under that user's context and not in yours, kind of like logging off, logging in under a different account, running the windows app, switching users, and wondering why you never see word under this other user.所以决定试试使用User登录,也许会管用.
      

  6.   

    我没动手做过, 但是, 可以肯定, 可以使用其他帐号运行SC_HANDLE CreateService(
      SC_HANDLE hSCManager,
      LPCTSTR lpServiceName,
      LPCTSTR lpDisplayName,
      DWORD dwDesiredAccess,
      DWORD dwServiceType,
      DWORD dwStartType,
      DWORD dwErrorControl,
      LPCTSTR lpBinaryPathName,
      LPCTSTR lpLoadOrderGroup,
      LPDWORD lpdwTagId,
      LPCTSTR lpDependencies,
      LPCTSTR lpServiceStartName,
      LPCTSTR lpPassword
    );上面的函数在创建服务时被调用, lpServiceStartName lpPassword 分别用于指定服务运行的帐号和密码
      

  7.   


    我又重新试了一次,写了一个什么都不做的服务(就只加了一个Timer控件).以User登录,还是不行.一样的错误提示.以Local System就正常.你试试看看?5分钟写一个,安装一下.
      

  8.   

    username 要遵守下面的规则If the service type is SERVICE_WIN32_OWN_PROCESS, use an account name in the form DomainName\UserName. The service process will be logged on as this user. If the account belongs to the built-in domain, you can specify .\UserName. 还有最好不要空密码
      

  9.   

    楼上,确实是我错了。用户名我试用了:username,domain\username,machinename\username,几种格式,就是没有试.\username。.\username是正确的。通过以上事例,有两个经验和大家分享:1.以user登录的话,用户名(本地)的格式为:.\username2.以LocalSystem访问虚拟打印机不成功。 但是以User身份访问就没有什么问题。
      

  10.   

    多谢楼主和楼上的讨论,
    虽然也没有去做,但是想想自己也很有可能忘记用.\username
    呵呵 最近都在用orcale,要是还在使用sqlserver,猜想还是很有可能想到.的写法