#define _WIN32_WINNT 0x0400#define INITGUID #define STATUS_STRING_SIZE 2048#include <stdio.h> #include <windows.h>#include "CrtVDir.h"#include <iostream.h> #include <winnt.h>#include "iadmw.h" // COM Interface header #include "iiscnfg.h" // MD_ & IIS_MD_ #defines // This sample uses the IWamAdmin interface. The header file for IWamAdmin // was not included in IIS 4.0's SDK. You can get the file from: // ftp://ftp.microsoft.com/bussys/IIS/iis-public/iis40/SDK/iwamreg.h #include "iwamreg.h"#include "atlBase.h" // ATL support for smart pointersCComPtr <IMSAdminBase> g_spAdminBase; CComPtr <IWamAdmin> g_spWamAdmin; int g_nOperation; // CD == 1, RD == 2, CA == 3, RA == 4 DWORD g_dwPermissions = 1, g_dwSite = 1; // default to "read" permission and site 1 BOOL g_bInProc = true;int main(int argc, char* argv[]) { CHAR szStatus[STATUS_STRING_SIZE]; HRESULT hres = S_OK; if(argc == 1 || !ParseParms(argc, argv)) { ShowBanner(); return 0; } // initialize COM hres = CoInitialize(NULL); if (FAILED(hres)) { wsprintf(szStatus, "CoInitializeEx failed: %d (0x%08x)", hres, hres); cerr << szStatus << endl; return 0; } // get a pointer to the IIS Admin Base Object hres = CoCreateInstance(CLSID_MSAdminBase, NULL, CLSCTX_ALL, IID_IMSAdminBase, (void **) &g_spAdminBase); if (FAILED(hres)) { wsprintf(szStatus, "CoCreateInstance failed for CLSID_MSAdminBase: %d (0x%08x)", hres, hres); cerr << szStatus << endl; CoUninitialize(); return 0; } // get a pointer to the IWamAdmin Object hres = CoCreateInstance(CLSID_WamAdmin, NULL, CLSCTX_ALL, IID_IWamAdmin, (void **) &g_spWamAdmin); if (FAILED(hres)) { wsprintf(szStatus, "CoCreateInstance failed for CLSID_WamAdmin: %d (0x%08x)", hres, hres); cerr << szStatus << endl; g_spAdminBase.Release(); CoUninitialize(); return 0; } switch(g_nOperation) { case 1: // create the virtual root if(!CreateVirtualRoot(argv[3], argv[2], g_dwPermissions, g_dwSite, szStatus)) cerr << szStatus << endl; break; case 2: // delete the virtual root if(!DeleteVirtualRoot(argv[2], g_dwSite, szStatus)) cerr << szStatus << endl; break; case 3: // create the application if(!CreateApplication(argv[2], g_bInProc, szStatus)) cerr << szStatus << endl; break; case 4: // delete the application if(!DeleteApplication(argv[2], false, true, szStatus)) cerr << szStatus << endl; break; } cout << szStatus << endl; // this needs to be released before we uninitialize COM g_spAdminBase.Release(); g_spWamAdmin.Release(); CoUninitialize(); return 0; }/* Function : ParseParmsDescription: ParseParms program parameters */ BOOL ParseParms(int argc, char* argv[]) {//·µ»ØÔËÐвÎÊý //´´½¨ÐéÄâÕ¾µã if(0 == strcmp(argv[1], "CD")) { g_nOperation = 1; switch(argc) { case 4: return true; case 5: g_dwPermissions = atoi(argv[4]); return true; case 6: g_dwPermissions = atoi(argv[4]); g_dwSite = atoi(argv[5]); return true; default: return false; } } //ɾ³ýÐéÄâÕ¾µã else if(0 == strcmp(argv[1], "RD")) { g_nOperation = 2; switch(argc) { case 3: return true; case 4: g_dwSite = atoi(argv[3]); return true; default: return false; } } else if(0 == strcmp(argv[1], "CA")) { g_nOperation = 3; if(4 == argc) { if(0 == strcmp(argv[3], "INPROC")) { g_bInProc = true; return true; } else if(0 == strcmp(argv[3], "OOP")) { g_bInProc = false; return true; } else return false; } else return false; } else if(0 == strcmp(argv[1], "RA")) { g_nOperation = 4; if(3 == argc) return true; else return false; } return false; }
/* Function : ShowBannerDescription: Show program parameters */ void ShowBanner() { cerr << "Usage:" << endl << endl; cerr << "CrtVDir.exe CD <path> <name> [<permissions>] [<site>]" << endl; cerr << "CrtVDir.exe RD <name> [<site>]" << endl; cerr << "CrtVDir.exe CA <metabasepath> <INPROC|OOP>" << endl; cerr << "CrtVDir.exe RA <metabasepath>" << endl << endl; cerr << "path - physical path which Virtual Directory will refer to" << endl; cerr << "name - name for virtual directory" << endl; cerr << "metabasepath - full metabase path to the relevant key: w3svc/1/root/myvr" << endl; cerr << "permissions - add desired constants below together" << endl << endl; cerr << "\t1 = Read Access" << endl; cerr << "\t2 = Write Access" << endl; cerr << "\t4 = Execute Access (including Script)" << endl; cerr << "\t512 = Script Access" << endl <<endl; cerr << "site - defaults to 1 if not supplied" << endl << endl; cerr << "INPROC|OOP - application will run in-process of out-of-process" << endl; }/* Function : CreateVirtualRootDescription: Creates the specified virtual rootArguments: szName - Name of the virtual root to add szPhysicalPath - Physical path of the virtual root dwPermissions - Access permissions for the virtual root dwSite - The site to which the virtual root is to be added szStatus - The function can report error descriptions in this stringReturn Value: Returns TRUE if successfull; otherwise FALSE. */ BOOL CreateVirtualRoot( LPSTR szName, LPSTR szPhysicalPath, DWORD dwPermissions, DWORD dwSite, CHAR szStatus[STATUS_STRING_SIZE] ) { CHAR szMetaPath[MAX_PATH]; BOOL bResult; // Create the metabase path wsprintf(szMetaPath, "/LM/W3SVC/%d/ROOT/%s", dwSite, szName); // Create a new key for the virtual directory bResult = WrAddKey(szMetaPath); if (!bResult) { wsprintf( szStatus, "CreateVirtualRoot: Error %d (0x%08x) creating key for virtual root", GetLastError(), GetLastError() ); goto Failed; } // Set the key type for the virtual directory bResult = WrSetData( szMetaPath, // metabase path MD_KEY_TYPE, // identifier METADATA_INHERIT, // attributes IIS_MD_UT_FILE, // user type STRING_METADATA, // data type 0, // data size (not used for STRING_METADATA) "IIsWebVirtualDir" // data ); if (!bResult) { wsprintf(szStatus, "CreateVirtualRoot: Error %d (0x%08x)setting key type for virtual root", GetLastError(), GetLastError()); goto Failed; }
// Set the VRPath for the virtual directory bResult = WrSetData( szMetaPath, // metabase path MD_VR_PATH, // identifier METADATA_INHERIT, // attributes IIS_MD_UT_FILE, // user type STRING_METADATA, // data type 0, // data size (not used for STRING_METADATA) szPhysicalPath // data ); if (!bResult) { wsprintf(szStatus, "CreateVirtualRoot: Error %d (0x%08x) setting vrpath for virtual root", GetLastError(), GetLastError()); goto Failed; } // Set the permissions for the virtual directory bResult = WrSetData( szMetaPath, // metabase path MD_ACCESS_PERM, // identifier METADATA_INHERIT, // attributes IIS_MD_UT_FILE, // user type DWORD_METADATA, // data type 0, // data size (not used for DWORD_METADATA) &dwPermissions // data ); if (!bResult) { wsprintf(szStatus, "CreateVirtualRoot: Error %d (0x%08x) setting permissions for virtual root", GetLastError(), GetLastError()); goto Failed; } // Commit the changes and return g_spAdminBase->SaveData(); wsprintf(szStatus, "CreateVirtualRoot completed successfully.");
return TRUE;Failed: return FALSE; }
/* Function : DeleteVirtualRootDescription: Deletes the specified virtual rootArguments: szName - Name of the virtual root to be deleted dwSite - The site from which the virtual root will be deleted szStatus - The function can report error descriptions in this stringReturn Value: Returns TRUE if successfull; otherwise FALSE.*/BOOL DeleteVirtualRoot( LPSTR szName, DWORD dwSite, CHAR szStatus[STATUS_STRING_SIZE] ) { CHAR szMetaPath[MAX_PATH]; CHAR szParent[MAX_PATH]; CHAR szVDir[MAX_PATH]; LPSTR szPtr; LPWSTR szwParent = NULL; LPWSTR szwVDir = NULL; METADATA_HANDLE hMetaData; BOOL fMetaData = FALSE; BOOL bRes; HRESULT hres; DWORD dwLastError; wsprintf(szMetaPath, "/LM/W3SVC/%d/ROOT/%s", dwSite, szName); strcpy(szParent, szMetaPath); szPtr = strrchr(szParent, '/'); strcpy(szVDir, szPtr + 1); *szPtr = 0; szwParent = MakeUnicode(szParent); szwVDir = MakeUnicode(szVDir); if (!szwParent || !szwVDir) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); wsprintf( szStatus, "DeleteVirtualDirectory failed: %d", GetLastError() ); goto Failed; } // Delete any applications on this directory bRes = DeleteApplication( szMetaPath, // metabase path FALSE, // not recoverable TRUE, // recursive szStatus // status string ); if (!bRes) goto Failed; // Get a handle to the metabase hres = g_spAdminBase->OpenKey( METADATA_MASTER_ROOT_HANDLE, szwParent, METADATA_PERMISSION_READ|METADATA_PERMISSION_WRITE, 60000, &hMetaData ); if (FAILED(hres)) { SetLastError(hres); wsprintf( szStatus, "DeleteVirtualRoot: Error %d (0x%08x) getting handle to metabase", hres, hres ); goto Failed; } else fMetaData = TRUE; // Do the work hres = g_spAdminBase->DeleteKey( hMetaData, szwVDir ); if (FAILED(hres)) { SetLastError(hres); wsprintf( szStatus, "DeleteVirtualRoot: IMSAdminBase->DeleteKey returned %d (0x%08x)", hres, hres ); goto Failed; } // Commit the changes g_spAdminBase->SaveData(); // Clean up and return g_spAdminBase->CloseKey(hMetaData); LocalFree(szwParent); LocalFree(szwVDir); wsprintf(szStatus, "DeleteVirtualRoot completed successfully."); return TRUE;Failed: dwLastError = GetLastError(); if (fMetaData) g_spAdminBase->CloseKey(hMetaData); LocalFree(szwParent); LocalFree(szwVDir); SetLastError(dwLastError); return FALSE; }/* Function : CreateApplicationDescription: Creates the specified WAM applicationArguments: szMetaPath - The metabase path of the application to be created fInproc - If this flag is true, app will be created inproc, else OOP szStatus - The function can report error descriptions in this stringReturn Value: Returns TRUE if successfull; otherwise FALSE.*/ BOOL CreateApplication( LPSTR szMetaPath, BOOL fInproc, CHAR szStatus[STATUS_STRING_SIZE] ) { CHAR szFullMetaPath[MAX_PATH]; LPWSTR szwMetaPath = NULL; HRESULT hres; DWORD dwLastError; // Sanitize the metabase path and get a unicode version
if (*szMetaPath == '/') strcpy(szFullMetaPath, szMetaPath); else wsprintf(szFullMetaPath, "/LM/%s", szMetaPath); szwMetaPath = MakeUnicode(szFullMetaPath); if (!szwMetaPath) { wsprintf( szStatus, "CreateApplication failed: %d", GetLastError() ); goto Failed; } // Do the work hres = g_spWamAdmin->AppCreate( szwMetaPath, fInproc ); if (FAILED(hres)) { SetLastError(hres); wsprintf( szStatus, "CreateApplication: IWamAdmin->AppCreate failed: %d (0x%08x)", GetLastError(), GetLastError() ); goto Failed; } // Clean up and return
SetLastError(dwLastError); return FALSE; }/* Function : DeleteApplicationDescription: Deletes the specified applicationArguments: szMetaPath - The metabase path of the application to be deleted fRecoverable - If this flag is true, the app will be recoverable fRecursive - If this flag is true, all sub-applications will also be deleted szStatus - The function can report error descriptions in this stringReturn Value: Returns TRUE if successfull; otherwise FALSE.*/ BOOL DeleteApplication( LPSTR szMetaPath, BOOL fRecoverable, BOOL fRecursive, CHAR szStatus[STATUS_STRING_SIZE] ) { CHAR szFullMetaPath[MAX_PATH]; LPWSTR szwMetaPath = NULL; HRESULT hres; DWORD dwLastError; // Sanitize the metabase path and get a unicode version
#define STATUS_STRING_SIZE 2048#include <stdio.h>
#include <windows.h>#include "CrtVDir.h"#include <iostream.h>
#include <winnt.h>#include "iadmw.h" // COM Interface header
#include "iiscnfg.h" // MD_ & IIS_MD_ #defines // This sample uses the IWamAdmin interface. The header file for IWamAdmin
// was not included in IIS 4.0's SDK. You can get the file from:
// ftp://ftp.microsoft.com/bussys/IIS/iis-public/iis40/SDK/iwamreg.h
#include "iwamreg.h"#include "atlBase.h" // ATL support for smart pointersCComPtr <IMSAdminBase> g_spAdminBase;
CComPtr <IWamAdmin> g_spWamAdmin; int g_nOperation; // CD == 1, RD == 2, CA == 3, RA == 4
DWORD g_dwPermissions = 1, g_dwSite = 1; // default to "read" permission and site 1
BOOL g_bInProc = true;int main(int argc, char* argv[])
{
CHAR szStatus[STATUS_STRING_SIZE];
HRESULT hres = S_OK; if(argc == 1 || !ParseParms(argc, argv))
{
ShowBanner();
return 0;
} // initialize COM
hres = CoInitialize(NULL); if (FAILED(hres))
{
wsprintf(szStatus, "CoInitializeEx failed: %d (0x%08x)", hres, hres);
cerr << szStatus << endl;
return 0;
} // get a pointer to the IIS Admin Base Object
hres = CoCreateInstance(CLSID_MSAdminBase, NULL, CLSCTX_ALL,
IID_IMSAdminBase, (void **) &g_spAdminBase); if (FAILED(hres))
{
wsprintf(szStatus, "CoCreateInstance failed for CLSID_MSAdminBase: %d (0x%08x)", hres, hres);
cerr << szStatus << endl;
CoUninitialize();
return 0;
} // get a pointer to the IWamAdmin Object hres = CoCreateInstance(CLSID_WamAdmin, NULL, CLSCTX_ALL,
IID_IWamAdmin, (void **) &g_spWamAdmin); if (FAILED(hres))
{
wsprintf(szStatus, "CoCreateInstance failed for CLSID_WamAdmin: %d (0x%08x)", hres, hres);
cerr << szStatus << endl;
g_spAdminBase.Release();
CoUninitialize();
return 0;
} switch(g_nOperation)
{
case 1:
// create the virtual root
if(!CreateVirtualRoot(argv[3], argv[2], g_dwPermissions, g_dwSite, szStatus))
cerr << szStatus << endl; break;
case 2:
// delete the virtual root
if(!DeleteVirtualRoot(argv[2], g_dwSite, szStatus))
cerr << szStatus << endl; break;
case 3:
// create the application
if(!CreateApplication(argv[2], g_bInProc, szStatus))
cerr << szStatus << endl; break;
case 4:
// delete the application
if(!DeleteApplication(argv[2], false, true, szStatus))
cerr << szStatus << endl; break;
} cout << szStatus << endl; // this needs to be released before we uninitialize COM
g_spAdminBase.Release();
g_spWamAdmin.Release(); CoUninitialize();
return 0;
}/*
Function : ParseParmsDescription: ParseParms program parameters
*/
BOOL ParseParms(int argc, char* argv[])
{//·µ»ØÔËÐвÎÊý
//´´½¨ÐéÄâÕ¾µã
if(0 == strcmp(argv[1], "CD"))
{
g_nOperation = 1; switch(argc)
{
case 4:
return true;
case 5:
g_dwPermissions = atoi(argv[4]);
return true;
case 6:
g_dwPermissions = atoi(argv[4]);
g_dwSite = atoi(argv[5]);
return true;
default:
return false;
}
}
//ɾ³ýÐéÄâÕ¾µã
else if(0 == strcmp(argv[1], "RD"))
{
g_nOperation = 2; switch(argc)
{
case 3:
return true;
case 4:
g_dwSite = atoi(argv[3]);
return true;
default:
return false;
} }
else if(0 == strcmp(argv[1], "CA"))
{
g_nOperation = 3; if(4 == argc)
{
if(0 == strcmp(argv[3], "INPROC"))
{
g_bInProc = true;
return true;
}
else if(0 == strcmp(argv[3], "OOP"))
{
g_bInProc = false;
return true;
}
else
return false;
}
else
return false;
}
else if(0 == strcmp(argv[1], "RA"))
{
g_nOperation = 4; if(3 == argc)
return true;
else
return false;
} return false;
}
/*
Function : ShowBannerDescription: Show program parameters
*/
void ShowBanner()
{
cerr << "Usage:" << endl << endl; cerr << "CrtVDir.exe CD <path> <name> [<permissions>] [<site>]" << endl;
cerr << "CrtVDir.exe RD <name> [<site>]" << endl;
cerr << "CrtVDir.exe CA <metabasepath> <INPROC|OOP>" << endl;
cerr << "CrtVDir.exe RA <metabasepath>" << endl << endl; cerr << "path - physical path which Virtual Directory will refer to" << endl;
cerr << "name - name for virtual directory" << endl;
cerr << "metabasepath - full metabase path to the relevant key: w3svc/1/root/myvr" << endl;
cerr << "permissions - add desired constants below together" << endl << endl;
cerr << "\t1 = Read Access" << endl;
cerr << "\t2 = Write Access" << endl;
cerr << "\t4 = Execute Access (including Script)" << endl;
cerr << "\t512 = Script Access" << endl <<endl;
cerr << "site - defaults to 1 if not supplied" << endl << endl;
cerr << "INPROC|OOP - application will run in-process of out-of-process" << endl;
}/*
Function : CreateVirtualRootDescription: Creates the specified virtual rootArguments: szName - Name of the virtual root to add
szPhysicalPath - Physical path of the virtual root
dwPermissions - Access permissions for the virtual root
dwSite - The site to which the virtual root is to be added
szStatus - The function can report error descriptions in this stringReturn Value: Returns TRUE if successfull; otherwise FALSE.
*/
BOOL CreateVirtualRoot(
LPSTR szName,
LPSTR szPhysicalPath,
DWORD dwPermissions,
DWORD dwSite,
CHAR szStatus[STATUS_STRING_SIZE]
)
{
CHAR szMetaPath[MAX_PATH];
BOOL bResult; // Create the metabase path wsprintf(szMetaPath, "/LM/W3SVC/%d/ROOT/%s", dwSite, szName); // Create a new key for the virtual directory bResult = WrAddKey(szMetaPath); if (!bResult)
{
wsprintf(
szStatus,
"CreateVirtualRoot: Error %d (0x%08x) creating key for virtual root",
GetLastError(),
GetLastError()
); goto Failed;
} // Set the key type for the virtual directory bResult = WrSetData(
szMetaPath, // metabase path
MD_KEY_TYPE, // identifier
METADATA_INHERIT, // attributes
IIS_MD_UT_FILE, // user type
STRING_METADATA, // data type
0, // data size (not used for STRING_METADATA)
"IIsWebVirtualDir" // data
); if (!bResult)
{
wsprintf(szStatus, "CreateVirtualRoot: Error %d (0x%08x)setting key type for virtual root",
GetLastError(), GetLastError()); goto Failed;
}
// Set the VRPath for the virtual directory bResult = WrSetData(
szMetaPath, // metabase path
MD_VR_PATH, // identifier
METADATA_INHERIT, // attributes
IIS_MD_UT_FILE, // user type
STRING_METADATA, // data type
0, // data size (not used for STRING_METADATA)
szPhysicalPath // data
); if (!bResult)
{
wsprintf(szStatus, "CreateVirtualRoot: Error %d (0x%08x) setting vrpath for virtual root",
GetLastError(), GetLastError()); goto Failed;
} // Set the permissions for the virtual directory bResult = WrSetData(
szMetaPath, // metabase path
MD_ACCESS_PERM, // identifier
METADATA_INHERIT, // attributes
IIS_MD_UT_FILE, // user type
DWORD_METADATA, // data type
0, // data size (not used for DWORD_METADATA)
&dwPermissions // data
); if (!bResult)
{
wsprintf(szStatus, "CreateVirtualRoot: Error %d (0x%08x) setting permissions for virtual root",
GetLastError(), GetLastError()); goto Failed;
} // Commit the changes and return g_spAdminBase->SaveData(); wsprintf(szStatus, "CreateVirtualRoot completed successfully.");
return TRUE;Failed: return FALSE;
}
/*
Function : DeleteVirtualRootDescription: Deletes the specified virtual rootArguments: szName - Name of the virtual root to be deleted
dwSite - The site from which the virtual root will be deleted
szStatus - The function can report error descriptions in this stringReturn Value: Returns TRUE if successfull; otherwise FALSE.*/BOOL DeleteVirtualRoot(
LPSTR szName,
DWORD dwSite,
CHAR szStatus[STATUS_STRING_SIZE]
)
{
CHAR szMetaPath[MAX_PATH];
CHAR szParent[MAX_PATH];
CHAR szVDir[MAX_PATH];
LPSTR szPtr;
LPWSTR szwParent = NULL;
LPWSTR szwVDir = NULL;
METADATA_HANDLE hMetaData;
BOOL fMetaData = FALSE;
BOOL bRes;
HRESULT hres;
DWORD dwLastError; wsprintf(szMetaPath, "/LM/W3SVC/%d/ROOT/%s", dwSite, szName); strcpy(szParent, szMetaPath); szPtr = strrchr(szParent, '/'); strcpy(szVDir, szPtr + 1); *szPtr = 0; szwParent = MakeUnicode(szParent);
szwVDir = MakeUnicode(szVDir); if (!szwParent || !szwVDir)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY); wsprintf(
szStatus,
"DeleteVirtualDirectory failed: %d",
GetLastError()
); goto Failed;
} // Delete any applications on this directory bRes = DeleteApplication(
szMetaPath, // metabase path
FALSE, // not recoverable
TRUE, // recursive
szStatus // status string
); if (!bRes)
goto Failed; // Get a handle to the metabase hres = g_spAdminBase->OpenKey(
METADATA_MASTER_ROOT_HANDLE,
szwParent,
METADATA_PERMISSION_READ|METADATA_PERMISSION_WRITE,
60000,
&hMetaData
); if (FAILED(hres))
{
SetLastError(hres); wsprintf(
szStatus,
"DeleteVirtualRoot: Error %d (0x%08x) getting handle to metabase",
hres,
hres
); goto Failed;
}
else
fMetaData = TRUE; // Do the work hres = g_spAdminBase->DeleteKey(
hMetaData,
szwVDir
); if (FAILED(hres))
{
SetLastError(hres); wsprintf(
szStatus,
"DeleteVirtualRoot: IMSAdminBase->DeleteKey returned %d (0x%08x)",
hres,
hres
); goto Failed;
} // Commit the changes g_spAdminBase->SaveData(); // Clean up and return g_spAdminBase->CloseKey(hMetaData); LocalFree(szwParent);
LocalFree(szwVDir); wsprintf(szStatus, "DeleteVirtualRoot completed successfully."); return TRUE;Failed: dwLastError = GetLastError(); if (fMetaData)
g_spAdminBase->CloseKey(hMetaData); LocalFree(szwParent);
LocalFree(szwVDir); SetLastError(dwLastError); return FALSE;
}/*
Function : CreateApplicationDescription: Creates the specified WAM applicationArguments: szMetaPath - The metabase path of the application to be created
fInproc - If this flag is true, app will be created inproc, else OOP
szStatus - The function can report error descriptions in this stringReturn Value: Returns TRUE if successfull; otherwise FALSE.*/
BOOL CreateApplication(
LPSTR szMetaPath,
BOOL fInproc,
CHAR szStatus[STATUS_STRING_SIZE]
)
{
CHAR szFullMetaPath[MAX_PATH];
LPWSTR szwMetaPath = NULL;
HRESULT hres;
DWORD dwLastError; // Sanitize the metabase path and get a unicode version
if (*szMetaPath == '/')
strcpy(szFullMetaPath, szMetaPath);
else
wsprintf(szFullMetaPath, "/LM/%s", szMetaPath); szwMetaPath = MakeUnicode(szFullMetaPath); if (!szwMetaPath)
{
wsprintf(
szStatus,
"CreateApplication failed: %d",
GetLastError()
); goto Failed;
} // Do the work hres = g_spWamAdmin->AppCreate(
szwMetaPath,
fInproc
); if (FAILED(hres))
{
SetLastError(hres); wsprintf(
szStatus,
"CreateApplication: IWamAdmin->AppCreate failed: %d (0x%08x)",
GetLastError(),
GetLastError()
); goto Failed;
} // Clean up and return
LocalFree(szwMetaPath); wsprintf(szStatus, "CreateApplication completed successfully."); return TRUE;Failed: dwLastError = GetLastError(); LocalFree(szwMetaPath);
SetLastError(dwLastError); return FALSE;
}/*
Function : DeleteApplicationDescription: Deletes the specified applicationArguments: szMetaPath - The metabase path of the application to be deleted
fRecoverable - If this flag is true, the app will be recoverable
fRecursive - If this flag is true, all sub-applications will also be deleted
szStatus - The function can report error descriptions in this stringReturn Value: Returns TRUE if successfull; otherwise FALSE.*/
BOOL DeleteApplication(
LPSTR szMetaPath,
BOOL fRecoverable,
BOOL fRecursive,
CHAR szStatus[STATUS_STRING_SIZE]
)
{
CHAR szFullMetaPath[MAX_PATH];
LPWSTR szwMetaPath = NULL;
HRESULT hres;
DWORD dwLastError; // Sanitize the metabase path and get a unicode version
if (*szMetaPath == '/')
strcpy(szFullMetaPath, szMetaPath);
else
wsprintf(szFullMetaPath, "/LM/%s", szMetaPath); szwMetaPath = MakeUnicode(szFullMetaPath); if (!szwMetaPath)
{
wsprintf(
szStatus,
"DeleteApplication failed: %d",
GetLastError()
); goto Failed;
} // Do the work if (fRecoverable)
{
hres = g_spWamAdmin->AppDeleteRecoverable(szwMetaPath, fRecursive); if (FAILED(hres))
{
SetLastError(hres); wsprintf(
szStatus,
"DeleteApplication: IWamAdmin->AppDeleteRecoverable failed: %d (0x%08x)",
hres,
hres
); goto Failed;
}
}
else
{
hres = g_spWamAdmin->AppDelete(szwMetaPath, fRecursive); if (FAILED(hres))
{
SetLastError(hres); wsprintf(
szStatus,
"DeleteApplication: IWamAdmin->AppDelete failed: %d (0x%08x)",
hres,
hres
); goto Failed;
}
} // Clean up LocalFree(szwMetaPath); wsprintf(szStatus, "DeleteApplication completed successfully."); return TRUE;Failed: dwLastError = GetLastError();
LocalFree(szwMetaPath); SetLastError(dwLastError);
return FALSE;
}
你好!
我在编译你提供的代码时出现下述错误:
fatal error C1083: Cannot open include file: 'CrtVDir.h': No such file or directory请问CrtVDir.h在哪???
谢谢!!!
你好!
我在编译你提供的代码时出现下述错误:
fatal error C1083: Cannot open include file: 'CrtVDir.h': No such file or directory请问CrtVDir.h在哪???
谢谢!!!