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 sta开发者_开发知识库rtup 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?
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?
The below code is what I used in my Installer class as Custom Actions. This will return the current logged in user and not 'NTAUTHORITY\SYSTEM'
IdentityReference identity = new System.Security.Principal.NTAccount(Environment.GetEnvironmentVariable("USERDOMAIN") + "\\" + Environment.GetEnvironmentVariable("USERNAME"))
精彩评论