Visual Studio setup project: run CustomActions/process as current user not system account

家住魔仙堡 提交于 2019-12-04 14:13:23

问题


I'm using a setup project in visual studio 2010 for a c# outlook add-in (Office 2010/2013) and an other standalone tool. During the installation I kill all instances of outlook, afterwards I want to restart an instance of outlook.

In my addin project I added an installerclass and added an InstallEventHandler(AfterInstallEventHandler) where I execute

Process.Start("Outlook");

While the same command simply opens Outlook in an other compiled class, in the context of the installer outlook opens in the profile creation assistant.

I also tried to run said working compiled exe as an user defined action after the commit, but same problem occurs.

Any solution or explanation would be appreciated.


回答1:


SOLUTION:

The installation runs in the SYSTEM account. Therefor the created process is also run in said account, not as the currently logged in user.

I created an additional project (InstallHelper), which includes the

Process.Start("Outlook");

I added the InstallHelper as CustomAction on Commit in my setup project and changed InstallerClass to False in the properties of the CustomAction. Then I copied WiRunSql.vbs to the project folder and added an PostBuildEvent to the setup project:

@echo off
cscript //nologo "$(ProjectDir)WiRunSql.vbs" "$(BuiltOutputPath)" "UPDATE CustomAction SET Type=1554 WHERE Type=3602"

3602:

  • 0x800 (msidbCustomActionTypeNoImpersonate)
  • 0x400 (msidbCustomActionTypeInScript)
  • 0x200 (msidbCustomActionTypeCommit)
  • 0x12 (Custom Action Type 18: exe)

1554:

  • 0x400 (msidbCustomActionTypeInScript)
  • 0x200 (msidbCustomActionTypeCommit)
  • 0x12 (Custom Action Type 18: exe)

See: msdn: Custom Action In-Script Execution Options

The Type-change removed the bit for msidbCustomActionTypeNoImpersonate (0x00000800), so the InstallHelper and the created process are run as the logged in user, not as SYSTEM.

Alternatively those changes are possible via opening the msi in orca (has to be repeated after each build, so I prefer the scripted change).




回答2:


In additional to previous answer(I spent a lot of time to understand this):

Text of WiRunSql.vbs for me: (for you it will contains also argument2-update script argument)

(for me PostBuildevent is

@echo off
cscript //nologo "$(ProjectDir)WiRunSql.vbs" "$(BuiltOuputPath)"

)

Dim filename, installer, database
filename = WScript.Arguments(0)
Set installer = CreateObject("WindowsInstaller.Installer")
Set database = installer.OpenDatabase(filename, 1)
sql = "UPDATE `CustomAction` SET `Type`= 1554 WHERE `Type`= 3602"
Set view = database.OpenView(sql)
view.Execute
view.Close
database.Commit

You can test your script in command promt before:

cscript "C:\Projects\YourProject\WiRunSql.vbs" "C:\Projects\YourProject\Debug\Setup.msi"

This need for look errors in script

To look new Type value you can use orca https://support.microsoft.com/en-us/kb/255905

Also look: http://www.codeproject.com/Articles/383481/Editing-an-MSI-Database http://integr8consulting.blogspot.ru/2012/04/microsoft-installer-custom-actions-user.html https://github.com/facebookarchive/ie-toolbar/blob/master/Common/Install/msi/FBIE-MSI/scripts/msipostbuild.vbs



来源:https://stackoverflow.com/questions/14773220/visual-studio-setup-project-run-customactions-process-as-current-user-not-syste

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!