admin管理员组

文章数量:1405370

I created an app for Windows in C#, which automatically starts when Windows starts.
I Write a simple key in the registry:

    private bool autorunProperty;
    private readonly static string registryString = "Software\\Microsoft\\Windows\\CurrentVersion\\Run";
    private void CheckRegistryKey()
    {
        using (RegistryKey key = Registry.CurrentUser.OpenSubKey(registryString, true))
        {
            if (key != null)
            {
                object value = key.GetValue(appName);

                if (value != null)
                {
                    autorunProperty = true;
                }
                else
                {
                    autorunProperty = false;
                }
            }
            key.Close();
        }
    }

It works perfectly: reading and writing in the registry.
To distribute it I used "MSIX packaging for Visual Studio" and after test installation, doesn't write in the registry.
What I can do?

I created an app for Windows in C#, which automatically starts when Windows starts.
I Write a simple key in the registry:

    private bool autorunProperty;
    private readonly static string registryString = "Software\\Microsoft\\Windows\\CurrentVersion\\Run";
    private void CheckRegistryKey()
    {
        using (RegistryKey key = Registry.CurrentUser.OpenSubKey(registryString, true))
        {
            if (key != null)
            {
                object value = key.GetValue(appName);

                if (value != null)
                {
                    autorunProperty = true;
                }
                else
                {
                    autorunProperty = false;
                }
            }
            key.Close();
        }
    }

It works perfectly: reading and writing in the registry.
To distribute it I used "MSIX packaging for Visual Studio" and after test installation, doesn't write in the registry.
What I can do?

Share Improve this question edited Mar 11 at 16:35 Brummell asked Mar 8 at 15:37 BrummellBrummell 2422 silver badges17 bronze badges 1
  • 1 "Apps that are packaged using MSIX can be configured to run in a lightweight app container. The app's process, and its child processes, run inside the container, and are isolated using file system and registry virtualization. For more info, see MSIX AppContainer apps. All AppContainer apps can read the global registry. An AppContainer app writes to its own virtual registry and application data folder, and that data is deleted when the app is uninstalled or reset. Other apps don't have access to the virtual registry or virtual file system of an AppContainer app." - MSDN – Gerry Schmitz Commented Mar 8 at 18:59
Add a comment  | 

1 Answer 1

Reset to default 0

I discovered the problem.
For security reasons, MSIX is designed to not allow writes to the run key and also prevents the use of the startup folder.
Microsoft introduced "StartupTask" Class to be used in the "Package.appxmanifest" file.
With a few lines of XML it is solved, as in the example:

<Applications>  
<Application Id="App"  
  Executable="MyApp.exe"  
  EntryPoint="Windows.FullTrustApplication">  
    <Extensions>  
        <uap5:Extension Category="windows.startupTask">  
            <uap5:StartupTask  
              TaskId="LaunchOnStartupTaskId"  
              DisplayName="MyApp"/>  
        </uap5:Extension>  
    </Extensions>  

https://www.advancedinstaller/startup-programs-msix.html
https://nicksnettravels.builttoroam/launch-on-startup/

The management of the App is delegated to the specific section of the control panel: Apps > Startup

本文标签: cUsing MSIX packaging for Visual StudioApp doesn39t write in registryStack Overflow