Mike Broderick
asked on
Setting CurrentUser\Run in msi setup custom action fails with no message
I have a .Net 4 msi setup project that runs a VB program as a custom action. This program attempts to set a string value in the the registry key HKCU\Software\Microsoft\Wi ndows\Curr entVersion \Run. I get no error yet the key value is not set. I have attached a code snippet. The code works when I test it from visual studio, but not when it is in the msi routine. I also elevated the priveleges. Same error. How do I get this to work?
Try
regStartPgmKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
If regStartPgmKey Is Nothing Then
MessageBox.Show("Error accessing Startup program registry key." & vbCrLf & "Process will continue", _
"BDS Intstall/Uninstall error", _
MessageBoxButtons.OK, _
MessageBoxIcon.Error)
End If
regStartPgmKey.SetValue(PgmName, Path.Combine(TargetDir, PgmName))
regStartPgmKey.Close()
MessageBox.Show("After Set " & PgmName)
Catch ex As Exception
MessageBox.Show("Error accessing Startup program registry key:" & ex.Message & vbCrLf & "Process will continue", _
"BDS Intstall/Uninstall error", _
MessageBoxButtons.OK, _
MessageBoxIcon.Error)
End Try
ASKER
Correct. Same problem.
What do you mean by "elevated the priveleges"? If you ran the msi as a different admin user or System account then HKCU would no longer be the user logged on, but the elevated user.
Where is the custom action? If it is the deferred sequence then again that could be running as the System account.
For HKCU keys to go to the logged-on-user's hive, ensure that the action is in the Execute Immediate sequence and the msi is called in the user context. Although can't you use the msi to write the reg keys natively?
If the msi *must* be run with elevated privileges, then there are other techniques that must be employed to get things to run in the user context.
Daz.
Where is the custom action? If it is the deferred sequence then again that could be running as the System account.
For HKCU keys to go to the logged-on-user's hive, ensure that the action is in the Execute Immediate sequence and the msi is called in the user context. Although can't you use the msi to write the reg keys natively?
If the msi *must* be run with elevated privileges, then there are other techniques that must be employed to get things to run in the user context.
Daz.
ASKER
Elevated priveleges:
In visual studio editing the update project, (the one that runs during the custom action) Click Project - "Project" properties. Select the Application tab and click the View Windows Settings button. In requestedExecutionLevel, change asInvoker to requireAdministrator.
The Custom Action is defined in the Setup project on the Edit Custom Actions pane, in the Install and Uninstall sections.
I'm using Visual Studio to build the msi. I apologize but I am unaware of the terms Execute Immediate Sequence and user context. However, I did put a messagebox immediately after the write operation and it did execute.
In visual studio editing the update project, (the one that runs during the custom action) Click Project - "Project" properties. Select the Application tab and click the View Windows Settings button. In requestedExecutionLevel, change asInvoker to requireAdministrator.
The Custom Action is defined in the Setup project on the Edit Custom Actions pane, in the Install and Uninstall sections.
I'm using Visual Studio to build the msi. I apologize but I am unaware of the terms Execute Immediate Sequence and user context. However, I did put a messagebox immediately after the write operation and it did execute.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ahh-ha. The user name is SYSTEM. Is there a way to VS/2010 to run the custom action as the user, or to put the registry in someone else's area?
Please note that there are written procedures that need to be performed as part of the install. As a workaround, I put a line item into the procs which moved a shortcut into the user's Startup folder. This works OK, I would like to automate it (thus the question) but dont want to do anything drastic.
Please note that there are written procedures that need to be performed as part of the install. As a workaround, I put a line item into the procs which moved a shortcut into the user's Startup folder. This works OK, I would like to automate it (thus the question) but dont want to do anything drastic.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you.
You mean same problem? As you said there is no error.