用xml编辑器打开Package.appxmanifest,在【Package】中加入

xmlns=”http://schemas.microsoft.com/appx/manifest/foundation/windows10″
xmlns:uap=”http://schemas.microsoft.com/appx/manifest/uap/windows10″
xmlns:desktop=”http://schemas.microsoft.com/appx/manifest/desktop/windows10″
xmlns:mp=”http://schemas.microsoft.com/appx/2014/phone/manifest”
xmlns:rescap=”http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities”
IgnorableNamespaces=”uap rescap mp desktop”

找到【Applications】/【Extensions】节点,加入


    

找到【Capabilities】节点加入

 

下面是调用代码:win32中

获取当前是否开机启动,绑定到chkBoxStartup

 var startupTask = await Windows.ApplicationModel.StartupTask.GetAsync("Win32appTask");
    switch (startupTask.State)
    {
        case Windows.ApplicationModel.StartupTaskState.Disabled:
            chkBoxStartup.Checked = false;
            break;
        case Windows.ApplicationModel.StartupTaskState.DisabledByUser:
            chkBoxStartup.Checked = false;
            break;
        case Windows.ApplicationModel.StartupTaskState.Enabled:
            chkBoxStartup.Checked = true;
            break;
    }

设置开机启动和取消,绑定到chkBoxStartup

var startupTask = await Windows.ApplicationModel.StartupTask.GetAsync("Win32appTask");
    if (startupTask.State == Windows.ApplicationModel.StartupTaskState.Enabled)
    {
        startupTask.Disable();
        chkBoxStartup.Checked = false;
        MessageBox.Show("The task has been disabled");
    }
    else
    {
        var state = await startupTask.RequestEnableAsync();
        switch (state)
        {
            case Windows.ApplicationModel.StartupTaskState.DisabledByUser:
                MessageBox.Show("The task has been disabled by the user");
                chkBoxStartup.Checked = false;
                break;
            case Windows.ApplicationModel.StartupTaskState.Enabled:
                MessageBox.Show("The task has been enabled");
                chkBoxStartup.Checked = true;
                break;
        }
    }