0

I have already set the program run as the windows startup, however the program can only work when it is run as administrator in windows 10, can anybody tell me what I should add in the code to set that? Here is my Wix code:

In product modules there is

<ComponentRef Id="RegistryEntries"/>

and then

<Fragment>
    <DirectoryRef Id="ProgramFilesFolder">
      <Component Id="RegistryEntries" Guid="14fe9526-0da4-4761-ad27-8a77f145c6b5">
        <RegistryKey Root="HKCU"
                     Key="Software\Microsoft\Windows\CurrentVersion\Run"
              Action="createAndRemoveOnUninstall">
          <RegistryValue Type="string" Name="March Networks Video Assistant" Value="[INSTALLFOLDER]March Networks Video Assistant.exe" KeyPath="yes"/>          
        </RegistryKey>
      </Component>
    </DirectoryRef>
  </Fragment>

Thank you so much to everybody.

1 Answer 1

1

The problem is you are putting this registry key in the HKCU which will run things in the current user's context at startup.

If you want it to be run as administrator on startup it needs to go into HKLM.

Try the following:

<Fragment>
  <DirectoryRef Id="ProgramFilesFolder">
    <Component Id="RegistryEntries" Guid="14fe9526-0da4-4761-ad27-8a77f145c6b5">
      <RegistryKey Root="HKLM"
                 Key="Software\Microsoft\Windows\CurrentVersion\Run"
          Action="createAndRemoveOnUninstall">
        <RegistryValue Type="string" Name="March Networks Video Assistant" Value="&quot;[INSTALLFOLDER]March Networks Video Assistant.exe&quot;" KeyPath="yes"/>          
      </RegistryKey>
    </Component>
  </DirectoryRef>
</Fragment>

So notice I changed HKCU to HKLM (this might cause ICE warnings during compilation but you can safely ignore them). If you are using a per user install, I don't know if this will be able to write the registry key though unless the install is run as administrator... Also I put &quot; around your RegistryValue's value since it's always nice to wrap full paths in quotes because of spaces.

Another nice thing you can do is update the RegistryValue's value using the install path of the component which can be referenced using the following syntax:

[#IDOfFile]

So if your component defining the "March Networks Video Assistant.exe" <File> uses Id="MarchNetworksVideoAssistant.exe" you can update your RegistryValue's value to

value="&quot;[#MarchNetworksVideoAssistant.exe]&quot;"

You can get a good explanation of this syntax here

If a substring of the form [#filekey] is found, it is replaced by the full path of the file, with the value filekey used as a key into the File table. The value of [#filekey] remains blank and is not replaced by a path until the installer runs the CostInitialize action, FileCost action, and CostFinalize action. The value of [#filekey] depends upon the installation state of the component to which the file belongs. If the component is run from the source, the value is the path to the source location of the file. If the component is run locally, the value is the path to the target location of the file after installation. If the component has an action state of absent, the installed state of the component is used to determine the [#filekey] value. If the installed state of the component is also absent or null, [#filekey] resolves to an empty string, otherwise it resolves to the value based upon the component's installed state. For more information about checking the installation state of components, see Checking the Installation of Features, Components, Files.

1
  • Thank you very much Brian, that was really helpful! Commented Jun 22, 2017 at 19:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.