微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

设置服务的运行凭据

我有一个在安装过程中使用的app.config文件的服务。 在ProjectInstaller类中有代码来读取app.config文件,取出凭据并设置它们。 目标是不显示用户/密码提示

在下面的例子中, serviceUser和servicePassword只是对象范围的私有string。

以下块(驻留在ProjectInstaller ctor中)可正常工作。 也就是说,它设置服务的login详细信息,而不会提示用户

public ProjectInstaller() { InitializeComponent(); LoadServiceSettings(); //Install the service as a specific user: serviceProcessInstaller1.Account = ServiceAccount.User; serviceProcessInstaller1.Username = "MYDOMAIN\myUser"; serviceProcessInstaller1.Password = servicePassword; //pulled out of app.config by LoadServiceSettings call }

但是,以下不起作用:

在VB.net中实现这样的工具提示

C#获取networking上的图像的宽度/高度,而无需下载整个文件

使用命令行csc.exe创build一个C#可移植类库?

在Windows XP中快速检测移除固定IDE驱动器

使用用于.NET控件的WiX安装程序在32个版本上设置registry项。 64位,WoW6432Node

public ProjectInstaller() { InitializeComponent(); LoadServiceSettings(); //Install the service as a specific user: serviceProcessInstaller1.Account = ServiceAccount.User; serviceProcessInstaller1.Username = serviceUser; //both get pulled out of app.config by LoadServiceSettings() call; serviceProcessInstaller1.Password = servicePassword; WriteLog("The service user is *" + serviceUser + "*"); // The above line outputs: // The service user is *MYDOMAINmyUser* WriteLog("Are the strings the same? " + (serviceUser == "MYDOMAIN\myUser").ToString()); // The above line outputs: // Are the strings the same? True WriteLog("Values: *" + serviceUser + "*" + servicePassword + "*"); // The above line outputs: // Values: *MYDOMAINmyUser*myPassword* WriteLog("Values: *" + serviceProcessInstaller1.Username + "*" + serviceProcessInstaller1.Password + "*"); // The above line outputs: // Values: *MYDOMAINmyUser*myPassword* }

为什么string是硬编码还是不重要? 另外值得注意的是,在我的app.config我不逃避斜线…因为它不是一个XML转义字符。

为什么这个失败?

编辑:“失败”我的意思是服务安装程序提示input密码,无论用户放在哪里覆盖serviceUser和servicePassword 。

保存到Excel文件导致在C#窗口中的错误

SetwindowsHookEx与SetWinHookEventEx

版本控制的生产环境

我怎样才能让我的.NET应用程序自己擦除?

无法加载可执行文件

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐