3

I have made C# project recently and try to run it at windows startup. I configured WXS file in order to write Registry Run key (HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run) Below is full of my WXS file.

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*" Name="NACViewAgentSetupProject" Language="1033" Version="1.0.0.0" Manufacturer="JSGURU" UpgradeCode="MYGUID">
        <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <MediaTemplate />

        <Feature Id="ProductFeature" Title="NACViewAgentSetupProject" Level="1">
            <ComponentGroupRef Id="ProductComponents" />
        </Feature>
    </Product>

    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
                <Directory Id="INSTALLFOLDER" Name="NACViewAgentSetupProject" />
            </Directory>
      <Directory Id="ProgramMenuFolder"></Directory>
        </Directory>
    </Fragment>

  <Fragment>
    <DirectoryRef Id="ProgramMenuFolder">
      <Component Id="ApplicationShortcut" Guid="MYGUID">
        <Shortcut Id="ApplicationStartMenuShortcut" Name="NACViewAgent" Description="NACVIEW Agent" Target="[INSTALLFOLDER]NACViewAgent.exe" WorkingDirectory="INSTALLFOLDER">
          <!--AUMID-->
          <ShortcutProperty Key="System.AppUserModel.ID" Value="NACVIEW.NACViewAgent"/>

          <!--COM CLSID, specifying which CLSID to activate when toast clicked-->
          <ShortcutProperty Key="System.AppUserModel.ToastActivatorCLSID" Value="{MYGUID}"/>
        </Shortcut>

        <RemoveFile Id="RemoveApplicationShortcut" Directory="ProgramMenuFolder" Name="NACViewAgent" On="uninstall"/>
        <RegistryValue Root="HKCU" Key="Software\NACVIEW" Name="installed" Type="integer" Value="1" KeyPath="yes" />

      </Component>
      <Component Id="ApplicationAutostart" Guid="MYGUID">
        <RegistryValue Root="HKCU" Action="write" Key="Software\Microsoft\Windows\CurrentVersion\Run" Name="NACViewAgent" Value="[INSTALLFOLDER]NACViewAgent.exe" Type="string"/>
      </Component>
    </DirectoryRef>
  </Fragment>

    <Fragment>
        <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
            <!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
            <!-- <Component Id="ProductComponent"> -->
                <!-- TODO: Insert files, registry keys, and other resources here. -->
            <!-- </Component> -->

      <Component Id="NACViewAgent.exe" Guid="MYGUID">
        <File Id="NACViewAgent.exe" Name="NACViewAgent.exe" Source="$(var.NACViewAgent.TargetDir)NACViewAgent.exe"/>
      </Component>
      <Component Id="GalaSoft.MvvmLight.dll" Guid="MYGUID">
        <File Id="GalaSoft.MvvmLight.dll" Name="GalaSoft.MvvmLight.dll" Source="$(var.NACViewAgent.TargetDir)GalaSoft.MvvmLight.dll"/>
      </Component>
      <Component Id="Newtonsoft.Json.dll" Guid="MYGUID">
        <File Id="Newtonsoft.Json.dll" Name="Newtonsoft.Json.dll" Source="$(var.NACViewAgent.TargetDir)Newtonsoft.Json.dll"/>
      </Component>
      <Component Id="Microsoft.WindowsAPICodePack.dll" Guid="MYGUID">
        <File Id="Microsoft.WindowsAPICodePack.dll" Name="Microsoft.WindowsAPICodePack.dll" Source="$(var.NACViewAgent.TargetDir)Microsoft.WindowsAPICodePack.dll"/>
      </Component>
      <Component Id="CommonServiceLocator.dll" Guid="MYGUID">
        <File Id="CommonServiceLocator.dll" Name="CommonServiceLocator.dll" Source="$(var.NACViewAgent.TargetDir)CommonServiceLocator.dll"/>
      </Component>
      <Component Id="System.Windows.Interactivity.dll" Guid="MYGUID">
        <File Id="System.Windows.Interactivity.dll" Name="System.Windows.Interactivity.dll" Source="$(var.NACViewAgent.TargetDir)System.Windows.Interactivity.dll"/>
      </Component>
      <Component Id="GalaSoft.MvvmLight.Extras.dll" Guid="MYGUID">
        <File Id="GalaSoft.MvvmLight.Extras.dll" Name="GalaSoft.MvvmLight.Extras.dll" Source="$(var.NACViewAgent.TargetDir)GalaSoft.MvvmLight.Extras.dll"/>
      </Component>
      <Component Id="GalaSoft.MvvmLight.Platform.dll" Guid="MYGUID">
        <File Id="GalaSoft.MvvmLight.Platform.dll" Name="GalaSoft.MvvmLight.Platform.dll" Source="$(var.NACViewAgent.TargetDir)GalaSoft.MvvmLight.Platform.dll"/>
      </Component>
      <Component Id="Microsoft.WindowsAPICodePack.ExtendedLinguisticServices.dll" Guid="MYGUID">
        <File Id="Microsoft.WindowsAPICodePack.ExtendedLinguisticServices.dll" Name="Microsoft.WindowsAPICodePack.ExtendedLinguisticServices.dll" Source="$(var.NACViewAgent.TargetDir)Microsoft.WindowsAPICodePack.ExtendedLinguisticServices.dll"/>
      </Component>
      <Component Id="Microsoft.WindowsAPICodePack.Sensors.dll" Guid="MYGUID">
        <File Id="Microsoft.WindowsAPICodePack.Sensors.dll" Name="Microsoft.WindowsAPICodePack.Sensors.dll" Source="$(var.NACViewAgent.TargetDir)Microsoft.WindowsAPICodePack.Sensors.dll"/>
      </Component>
      <Component Id="Microsoft.WindowsAPICodePack.Shell.dll" Guid="MYGUID">
        <File Id="Microsoft.WindowsAPICodePack.Shell.dll" Name="Microsoft.WindowsAPICodePack.Shell.dll" Source="$(var.NACViewAgent.TargetDir)Microsoft.WindowsAPICodePack.Shell.dll"/>
      </Component>
      <Component Id="Microsoft.WindowsAPICodePack.ShellExtensions.dll" Guid="MYGUID">
        <File Id="Microsoft.WindowsAPICodePack.ShellExtensions.dll" Name="Microsoft.WindowsAPICodePack.ShellExtensions.dll" Source="$(var.NACViewAgent.TargetDir)Microsoft.WindowsAPICodePack.ShellExtensions.dll"/>
      </Component>

      <!--Tell WiX to install the shortcut-->
      <ComponentRef Id="ApplicationShortcut"/>
      <ComponentRef Id="ApplicationAutostart"/>
        </ComponentGroup>
    </Fragment>
</Wix>

build wix project and install it, then I can see NACViewAgent value in Run key like below. enter image description here

I restarted my machine. but unfortunately my exe does not auto start when windows boots.

Thanks in advance!

JS Guru
  • 343
  • 1
  • 3
  • 11
  • Too late to look at this now, but are you sure the EXE runs at all? Just check that first. Could be missing dependencies so it crashes on launch ([debug](https://stackoverflow.com/a/25005864/129130), [ideas list](https://stackoverflow.com/a/53530377/129130)). Sorry, has to be mentioned. Maybe have a look [here](https://stackoverflow.com/a/51777260/129130) (quoted path, possible culprit) and [here](https://stackoverflow.com/a/50836731/129130) as well. I might opt for the shortcut in the Startup folder. There is also ***scheduled tasks*** and ***running as a service***. – Stein Åsmul Jan 10 '20 at 02:54
  • @SteinÅsmul Thanks very much. I can start EXE on Start Menu. The EXE works without any issues. I added all dependencies. – JS Guru Jan 10 '20 at 18:58
  • And I added shortcut in the startup folder on start menu via WIX config before trying with Run registry key. but dont have any luck. That's why I am trying Run registry key. – JS Guru Jan 10 '20 at 19:02
  • Note that my app needs admin privilege. – JS Guru Jan 10 '20 at 19:05
  • If your application needs admin privilege then I would use a scheduled task that runs on startup OR better convert your application to a service. Otherwise you would either see an elevation prompt for the application or nothing at all on startup. Very undesirable. – Stein Åsmul Jan 12 '20 at 16:42

0 Answers0