MCPcopy Create free account
hub / github.com/ElementsProject/elements / SetStartOnSystemStartup

Function SetStartOnSystemStartup

src/qt/guiutil.cpp:530–582  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

528}
529
530bool SetStartOnSystemStartup(bool fAutoStart)
531{
532 // If the shortcut exists already, remove it for updating
533 fs::remove(StartupShortcutPath());
534
535 if (fAutoStart)
536 {
537 CoInitialize(nullptr);
538
539 // Get a pointer to the IShellLink interface.
540 IShellLinkW* psl = nullptr;
541 HRESULT hres = CoCreateInstance(CLSID_ShellLink, nullptr,
542 CLSCTX_INPROC_SERVER, IID_IShellLinkW,
543 reinterpret_cast<void**>(&psl));
544
545 if (SUCCEEDED(hres))
546 {
547 // Get the current executable path
548 WCHAR pszExePath[MAX_PATH];
549 GetModuleFileNameW(nullptr, pszExePath, ARRAYSIZE(pszExePath));
550
551 // Start client minimized
552 QString strArgs = "-min";
553 // Set -testnet /-regtest options
554 strArgs += QString::fromStdString(strprintf(" -chain=%s", gArgs.GetChainName()));
555
556 // Set the path to the shortcut target
557 psl->SetPath(pszExePath);
558 PathRemoveFileSpecW(pszExePath);
559 psl->SetWorkingDirectory(pszExePath);
560 psl->SetShowCmd(SW_SHOWMINNOACTIVE);
561 psl->SetArguments(strArgs.toStdWString().c_str());
562
563 // Query IShellLink for the IPersistFile interface for
564 // saving the shortcut in persistent storage.
565 IPersistFile* ppf = nullptr;
566 hres = psl->QueryInterface(IID_IPersistFile, reinterpret_cast<void**>(&ppf));
567 if (SUCCEEDED(hres))
568 {
569 // Save the link by calling IPersistFile::Save.
570 hres = ppf->Save(StartupShortcutPath().wstring().c_str(), TRUE);
571 ppf->Release();
572 psl->Release();
573 CoUninitialize();
574 return true;
575 }
576 psl->Release();
577 }
578 CoUninitialize();
579 return false;
580 }
581 return true;
582}
583#elif defined(Q_OS_LINUX)
584
585// Follow the Desktop Application Autostart Spec:

Callers 2

ResetMethod · 0.85
setDataMethod · 0.85

Calls 8

StartupShortcutPathFunction · 0.85
GetAutostartFilePathFunction · 0.85
create_directoriesFunction · 0.85
GetAutostartDirFunction · 0.85
GetChainNameMethod · 0.80
SaveMethod · 0.80
ReleaseMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected