开发者

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

开发者 https://www.devze.com 2022-12-28 19:20 出处:网络
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

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"))
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号