0

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);
  }
}

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.