| 662 | } |
| 663 | |
| 664 | bool SetStartOnSystemStartup(bool fAutoStart) |
| 665 | { |
| 666 | // If the shortcut exists already, remove it for updating |
| 667 | boost::filesystem::remove(StartupShortcutPath()); |
| 668 | |
| 669 | if (fAutoStart) { |
| 670 | CoInitialize(NULL); |
| 671 | |
| 672 | // Get a pointer to the IShellLink interface. |
| 673 | IShellLink* psl = NULL; |
| 674 | HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL, |
| 675 | CLSCTX_INPROC_SERVER, IID_IShellLink, |
| 676 | reinterpret_cast<void**>(&psl)); |
| 677 | |
| 678 | if (SUCCEEDED(hres)) { |
| 679 | // Get the current executable path |
| 680 | TCHAR pszExePath[MAX_PATH]; |
| 681 | GetModuleFileName(NULL, pszExePath, sizeof(pszExePath)); |
| 682 | |
| 683 | TCHAR pszArgs[5] = TEXT("-min"); |
| 684 | |
| 685 | // Set the path to the shortcut target |
| 686 | psl->SetPath(pszExePath); |
| 687 | PathRemoveFileSpec(pszExePath); |
| 688 | psl->SetWorkingDirectory(pszExePath); |
| 689 | psl->SetShowCmd(SW_SHOWMINNOACTIVE); |
| 690 | psl->SetArguments(pszArgs); |
| 691 | |
| 692 | // Query IShellLink for the IPersistFile interface for |
| 693 | // saving the shortcut in persistent storage. |
| 694 | IPersistFile* ppf = NULL; |
| 695 | hres = psl->QueryInterface(IID_IPersistFile, |
| 696 | reinterpret_cast<void**>(&ppf)); |
| 697 | if (SUCCEEDED(hres)) { |
| 698 | WCHAR pwsz[MAX_PATH]; |
| 699 | // Ensure that the string is ANSI. |
| 700 | MultiByteToWideChar(CP_ACP, 0, StartupShortcutPath().string().c_str(), -1, pwsz, MAX_PATH); |
| 701 | // Save the link by calling IPersistFile::Save. |
| 702 | hres = ppf->Save(pwsz, TRUE); |
| 703 | ppf->Release(); |
| 704 | psl->Release(); |
| 705 | CoUninitialize(); |
| 706 | return true; |
| 707 | } |
| 708 | psl->Release(); |
| 709 | } |
| 710 | CoUninitialize(); |
| 711 | return false; |
| 712 | } |
| 713 | return true; |
| 714 | } |
| 715 | |
| 716 | #elif defined(Q_OS_LINUX) |
| 717 |
no test coverage detected