I have a desktop bridge app. Using the app manifest, I can force my app to start at login time.
However, I want to programmatically enable/disable this feature, but I have not managed to do it yet.
#include <winrt/Windows.ApplicationModel.h>
using namespace winrt;
using namespace Windows::Foundation;
using namespace Windows::UI;
using namespace Windows::UI::ViewManagement;
using namespace Windows::ApplicationModel;
bool CppWinrt::makeStartup(int clear0Set1Query2)
{
try
{
StartupTask startupTask = winrt::Windows::ApplicationModel::StartupTask::GetAsync(L"MyStartupId").GetResults(); // L"AD2F1837.HPAccessoryCenter").GetResults();
if (clear0Set1Query2 == 1) startupTask.RequestEnableAsync().GetResults();
if (clear0Set1Query2 == 0) startupTask.Disable();
return startupTask.State() == winrt::Windows::ApplicationModel::StartupTaskState::Enabled;
}
catch (...) { return false; }
}
Here is the stuff in the app package...
<Extensions>
<desktop:Extension
Category="windows.startupTask"
Executable="HPAccessoryCenter\HPAccessoryCenter.exe"
EntryPoint="Windows.FullTrustApplication">
<desktop:StartupTask
TaskId="MyStartupId"
Enabled="true"
DisplayName="HPAccessoryCenter" />
</desktop:Extension>
</Extensions>
It compiles, but generates a run time error of: Exception thrown at 0x00007FFEFF7FA839 (KernelBase.dll) in HPAccessoryCenter.exe: WinRT originate error - 0x80070490 : 'Element not found.'.
Thanks, Cyrille
User contributions licensed under CC BY-SA 3.0