startupbootautostartflutter-windows

how to add flutter windows app to start-up on windows 11?


I want my flutter windows app to auto start on system boot.

I have used win32 package to achieve this and it's working on windows 10. but on windows 11, no registry entry is created.

I have also added shortcut of exe in start up apps folder, still not working.

I have disabled defender, disabled secure boot, no luck.

any suggestions will be grateful.

win32 usage:

void addApplicationToStartup() {
  var path = Platform.resolvedExecutable;
  final key = 'Software\\Microsoft\\Windows\\CurrentVersion\\Run';

  final hkey = calloc<HKEY>();
  final lpKey = TEXT(key);

  final lpValueName = "MyApp".toNativeUtf16();

  final lpData = path.toNativeUtf16();

  try {
    // Open the registry key
    final result = RegOpenKeyEx(
        HKEY_CURRENT_USER, lpKey, 0, KEY_WRITE, hkey);
    if (result != ERROR_SUCCESS) {
      throw WindowsException(result);
    }

    // Set the registry value
    final result2 = RegSetValueEx(
        hkey.value,
        lpValueName,
        0,
        REG_SZ,
        lpData.cast<Uint8>(),
        (path.length + 1) * sizeOf<Uint16>());
    if (result2 != ERROR_SUCCESS) {
      throw WindowsException(result2);
    }

    print('Application added to startup successfully.');
  } finally {
    // Clean up
    free(hkey);
    free(lpData);
    free(lpKey);
    free(lpValueName);
  }
}

Solution

  • I solved the issue. The issue was that I was trying to add my app to start up that required elevated privileges. After removing the elevated privileges requirement, the app was added to start up.