Search code examples
.netvisual-studio-2008windows-installerwindows-authentication

WindowsIdentity.GetCurrent() returns SYSTEM when ran from custom action


I have an install project (running on Windows 7) that launches a custom action at commit which starts the application that was just installed. During the startup of this application I have a method that checks the current user's name to perform some authentication. When launched from this custom action I am getting 'NTAUTHORITY\SYSTEM' instead of 'DOMAIN\USER'

Update: This link from the accepted answer is what solved my issue:

How can I customize an MSI in the Visual Studio setup/deployment project?


Solution

  • You probably should read the value of the USERNAME MSI property:

    string username = Session.Property("USERNAME");
    

    The above will work in immediate execution mode; however, in deferred mode you will explicitly have to pass the user name using the CustomActionData property to your custom action. For details see here:

    Tip: MSI Properties and Deferred Execution

    UPDATE: If you want to launch the installed application after the setup is completed you might prefer the approach described in this article:

    Launching Your Application After Install using Visual Studio 2005

    or use Aaron Stebner's script to modify your MSI:

    How can I customize an MSI in the Visual Studio setup/deployment project?