Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7948745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:48:38+00:00 2026-06-04T01:48:38+00:00

I have a service that when installed puts the Myapp.exe.config file (generated based of

  • 0

I have a service that when installed puts the Myapp.exe.config file (generated based of the app.config file) into the install directory. During the install process I need details from this file to configure the install. Particularly I need to tweak the Account/Username/Password fields of my service’s ServiceProcessInstaller instance so when it runs it runs as a particular user.

However, during the install process the installer hasn’t set my registry settings yet nor copied my Myapp.exe.config to the install directory…so I have no way of pulling these values, which means my service cannot install as the correct user. The only way I can do it now is to hardcode the user/pass values into the ProjectInstaller class, but I can’t bring myself to do it this way. It’s just wrong.

Is there a Windows install best practice regarding how to install a service as a particular user and how to access those credentials during the install process.

Currently I’m trying something like:

namespace MyService
{
   [RunInstaller(true)]
   public partial class ProjectInstaller : System.Configuration.Install.Installer
   {
      public ProjectInstaller()
      {
         InitializeComponent();

         //Set the user credentials.
         //NOTE: Eventually this needs to be updated to pull these values out of a
         //      conf file.  The problem now is that the location of the conf file
         //      is tied to a registry entry for the location of the service which
         //      may or may not exist when this block is executed.
         /* This is the only way I can get it to work, but this is
          * too horrible to ever actually do it this way:
         serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.User;
         serviceProcessInstaller1.Username = "DOMAIN\\user";
         serviceProcessInstaller1.Password = "password";
          */

         // Try to pull the service's registry values to know where it installed:
         RegistryKey keyService = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\services\\MyService");
         string path = ((string)keyService.GetValue("ImagePath"));
         path = path.Substring(1, path.LastIndexOf('\\'));

         string user = someValueFromFileIOontheAbovePath1,
                pass = someValueFromFileIOontheAbovePath2;

         serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.User;
         serviceProcessInstaller1.Username = user;
         serviceProcessInstaller1.Password = pass;
         //Doesn't work because install isn't complete and there aren't reg settings
         // yet, and even if I had the path the .config file is not written yet so
         // there's no file to parse.
      }
   }
}

Some .config file that holds these parameters:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   <appSettings>
      <add key="User" value="DOMAIN\bob"/>
      <add key="Password" value="secret"/>
   </appSettings>
</configuration>

How can I pull these user/pass values during install without resorting to hardcoding them into the binary?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:48:39+00:00Added an answer on June 4, 2026 at 1:48 am

    One way to accomplish what you want with the MSI is to use a Custom Action on the Commit to run your custom object installer. Commit Actions are run after the files have been copied, so the files will exist in the installation directory your user has chosen.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application (Windows service) that is installed into a directory in the
Our Windows file server has an archive service installed that stubs files that have
I have a windows service (C#) installed on a server that launches every 10
I have a WiX based MSI that installs a service and some shortcuts (and
I have a service that sometimes calls a batch file. The batch file takes
I have a service that is downloading a file. When the download is done,
I have a windows service that is already installed on a server, and I
I have an application that is installed per-machine (since it uses a service). One
I have a windows service that is installed using a setup project. Things work
I have a windows service exe that is compiled as x86, amd64, and Itanium.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.