Re: Calling IIsWebVirtualDir's AppUnload in C++
travislspencer@gmail.com wrote:
I'm having a hard time figuring out how to do the following in C++
(using ATL):
Dim DirObj
Set DirObj = GetObject("IIS://localhost/w3svc/1/ROOT/myvdir")
DirObj.AppUnload
Got it. Here is my whole little program in case some other poor sap
has to do something similar.
--
Regards,
Travis Spencer
#include "stdafx.h"
#include <stdio.h>
#include <activeds.h>
#include <iiisext.h>
#define APP_NAME _T("NetCentral_Charts")
#define EXIT_IF_FAILED(ERROR_MSG) \
do { \
if (FAILED(hr)) { \
_ftprintf(stderr, _T(ERROR_MSG)); \
goto error; \
} \
} while (false)
int _tmain(int argc, _TCHAR* argv[])
{
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
CComPtr<IADs> pADs;
CComPtr<IISApp> pApp;
EXIT_IF_FAILED("CoInitializeEx failed");
hr = ADsGetObject(_T("IIS://localhost/w3svc/1/ROOT/") APP_NAME,
IID_IADs, (void **)&pADs);
EXIT_IF_FAILED("ADsGetObject failed");
hr = pADs->QueryInterface(&pApp);
EXIT_IF_FAILED("Couldn't obtain an IISApp interface from the IADs
object");
hr = pApp->AppUnLoad();
if (SUCCEEDED(hr))
_tprintf(APP_NAME _T(" application was successfully
unloaded!\n"));
else
_tprintf(APP_NAME _T(" application was not unloaded!\n"));
error:
if (pADs) pADs.Release();
if (pApp) pApp.Release();
CoUninitialize();
return 0;
}