【问题标题】:Using a Winforms App to Configure a Windows Service使用 Winforms 应用程序配置 Windows 服务
【发布时间】:2015-04-01 03:28:05
【问题描述】:

我有一个由 Winform 和 Windows 服务组成的项目。安装后,它们都存在于同一个公共文件夹中,c:\program files\

我希望 Winform 能够在两个应用程序共享的通用 xml 文件中设置连接字符串、密码、日志文件路径等设置。我会处理所有的加密和解密,所以这不是我的问题。

问题似乎是在安装应用程序时,Winform 无法更新文件并且我收到拒绝访问错误,尽管我是具有桌面绝对权限的 COMPLETE 域管理员。

问题是,如何允许 Winform 定义 Winform 应用程序和它希望配置的 Windows 服务之间的公共连接字符串?

我不想依赖 machine.config 并且想要我自己的 XML 文件来保存所有的配置选项。一定是我缺少一些简单的东西,一个简单的解决方案?

【问题讨论】:

  • 不是一个答案,而是一个变通方法 - 您是否考虑过使用注册表而不是 xml 文件?

标签: winforms windows-services


【解决方案1】:

自从微软似乎已经转移到 application.config 路线并真正开始锁定注册表以来,注册表在过去只引起了头痛。再加上整个 WOW6432 分支,它变得更加难以使用。

我当前的解决方案似乎运行良好,只要两者具有相同的公司名称和产品名称,无论是从服务还是 Winform 调用,它都具有以下功能来指向相同的位置。然后我将自己的 XML 配置文件放在那个位置,一切都很好。

' **********************************************************************************************************
' Returns Commong Data Folder
' If folder does not exist, it attempts to create it
' **********************************************************************************************************
Public Function GetCommonDataFolder(ByRef ErrorMessage As String) As String
    Dim Result As String = ""

    Result = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) & "\" & My.Application.Info.CompanyName & "\" & My.Application.Info.ProductName

    Try
        Directory.CreateDirectory(Result)
    Catch ex As Exception
        ErrorMessage = "An exception occurred creating directory: " & Result & ": " & ex.Message
    End Try

    Return Result
End Function

【讨论】:

    猜你喜欢
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-08
    • 2017-02-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多