| 147 | } |
| 148 | |
| 149 | static int check_update(printInfoStruct& printInfo) |
| 150 | { |
| 151 | if (l_Debug) |
| 152 | std::wcout << "Initializing COM library" << '\n'; |
| 153 | CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); |
| 154 | ISearchResult *pResult; |
| 155 | IUpdateSession *pSession; |
| 156 | IUpdateSearcher *pSearcher; |
| 157 | BSTR criteria = NULL; |
| 158 | |
| 159 | HRESULT err; |
| 160 | if (l_Debug) |
| 161 | std::wcout << "Creating UpdateSession and UpdateSearcher" << '\n'; |
| 162 | CoCreateInstance(CLSID_UpdateSession, NULL, CLSCTX_INPROC_SERVER, IID_IUpdateSession, (void **)&pSession); |
| 163 | pSession->CreateUpdateSearcher(&pSearcher); |
| 164 | |
| 165 | /* |
| 166 | * IsInstalled = 0: All updates, including languagepacks and features |
| 167 | * BrowseOnly = 0: No features or languagepacks, security and unnamed |
| 168 | * BrowseOnly = 1: Nothing, broken |
| 169 | * RebootRequired = 1: Reboot required |
| 170 | */ |
| 171 | |
| 172 | criteria = SysAllocString(CRITERIA); |
| 173 | // https://msdn.microsoft.com/en-us/library/windows/desktop/aa386526%28v=vs.85%29.aspx |
| 174 | // https://msdn.microsoft.com/en-us/library/ff357803%28v=vs.85%29.aspx |
| 175 | |
| 176 | if (l_Debug) |
| 177 | std::wcout << L"Querying updates from server" << '\n'; |
| 178 | |
| 179 | err = pSearcher->Search(criteria, &pResult); |
| 180 | if (!SUCCEEDED(err)) |
| 181 | goto die; |
| 182 | SysFreeString(criteria); |
| 183 | |
| 184 | IUpdateCollection *pCollection; |
| 185 | IUpdate *pUpdate; |
| 186 | |
| 187 | LONG updateSize; |
| 188 | pResult->get_Updates(&pCollection); |
| 189 | pCollection->get_Count(&updateSize); |
| 190 | |
| 191 | if (updateSize == 0) |
| 192 | return -1; |
| 193 | |
| 194 | printInfo.numUpdates = updateSize; |
| 195 | // printInfo.important = printInfo.warn; |
| 196 | |
| 197 | IInstallationBehavior *pIbehav; |
| 198 | InstallationRebootBehavior updateReboot; |
| 199 | |
| 200 | for (LONG i = 0; i < updateSize; i++) { |
| 201 | pCollection->get_Item(i, &pUpdate); |
| 202 | if (l_Debug) { |
| 203 | std::wcout << L"Checking reboot behaviour of update number " << i << '\n'; |
| 204 | } |
| 205 | pUpdate->get_InstallationBehavior(&pIbehav); |
| 206 | pIbehav->get_RebootBehavior(&updateReboot); |
no test coverage detected