?? iis.cpp
字號:
&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 : DeleteApplication
Description:
Deletes the specified application
Arguments:
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 string
Return 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, 1);
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;
}
/*
Function : MakeUnicode
Description:
Returns a unicode version of the provided string
Arguments:
szString - The string to be translated
Return Value:
Returns a pointer to the unicode string if successful, NULL if not
*/
LPWSTR MakeUnicode(
LPSTR szString,
BOOL bRegularString
)
{
LPWSTR szwRet;
DWORD dwNumChars;
int NumChars;
if (bRegularString)
NumChars = -1;
else
NumChars = (strlen(szString) + 2);
// Allocate buffer for the returned wide string
dwNumChars = MultiByteToWideChar(
CP_ACP, // code page
MB_PRECOMPOSED, // flags
szString, // ANSI source string
-1, // source string length
NULL, // destination buffer
0 // size of destination buffer in chars
);
szwRet = (LPWSTR)LocalAlloc(LPTR, dwNumChars * sizeof(WCHAR));
if (!szwRet)
return NULL;
// Do the conversion
MultiByteToWideChar(
CP_ACP, // code page
MB_PRECOMPOSED, // flags
szString, // ANSI source string
NumChars, // source string length
szwRet, // destination buffer
dwNumChars // size of destination buffer in chars
);
return szwRet;
}
/*
Function : WrAddKey
Description:
Creates the specified metabase path
Arguments:
szMetaPath - The metabase path to be created
Return Value:
Returns TRUE if successfull; otherwise FALSE.
*/
BOOL WrAddKey(
LPSTR szMetaPath
)
{
CHAR szParent[MAX_PATH];
CHAR szDir[MAX_PATH];
LPWSTR szwPath = NULL;
LPWSTR szwNew = NULL;
LPSTR szPtr;
METADATA_HANDLE hMetaData;
BOOL fMetaData = FALSE;
HRESULT hres;
DWORD dwLastError;
// Parse the supplied metabase path into parent and new directory
strcpy(szParent, szMetaPath);
szPtr = strrchr(szParent, '/');
if (!szPtr)
{
SetLastError(ERROR_INVALID_PARAMETER);
goto Failed;
}
*szPtr = 0;
strcpy(szDir, szPtr + 1);
// Open the metabase
szwPath = MakeUnicode(szParent, 1);
szwNew = MakeUnicode(szDir, 1);
if (!szwPath || !szwNew)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
goto Failed;
}
hres = g_spAdminBase->OpenKey(
METADATA_MASTER_ROOT_HANDLE,
szwPath,
METADATA_PERMISSION_READ|METADATA_PERMISSION_WRITE,
60000,
&hMetaData
);
if (FAILED(hres))
{
SetLastError(hres);
goto Failed;
}
else
fMetaData = TRUE;
// Create the new key
hres = g_spAdminBase->AddKey(
hMetaData,
szwNew
);
if (FAILED(hres))
{
SetLastError(hres);
goto Failed;
}
// Clean up
hres = g_spAdminBase->CloseKey(hMetaData);
fMetaData = FALSE;
if(szwNew)
LocalFree(szwNew);
if(szwPath)
LocalFree(szwPath);
return TRUE;
Failed:
dwLastError = GetLastError();
if (fMetaData)
g_spAdminBase->CloseKey(hMetaData);
LocalFree(szwNew);
LocalFree(szwPath);
SetLastError(dwLastError);
return FALSE;
}
/*
Function : WrSetData
Description:
Sets the specified data in the metabase
Arguments:
szMetaPath - The metabase path where the data will be set
dwIdentifier - The metabase data identifier
dwAttributes - The data attributes
dwUserType - The metabase user type
dwDataType - The type of data being set
dwDataSize - The size of the data being set
pData - The actual data
Return Value:
Returns TRUE if successfull; otherwise FALSE.
*/
BOOL WrSetData(
LPSTR szMetaPath,
DWORD dwIdentifier,
DWORD dwAttributes,
DWORD dwUserType,
DWORD dwDataType,
DWORD dwDataSize,
LPVOID pData
)
{
LPWSTR szwPath = NULL;
LPWSTR szwValue = NULL;
METADATA_RECORD mdRecord;
METADATA_HANDLE hMetaData;
BOOL fMetaData = FALSE;
HRESULT hres;
DWORD dwLastError;
// Get a handle to the metabase location specified
szwPath = MakeUnicode(szMetaPath, 1);
if (!szwPath)
goto Failed;
hres = g_spAdminBase->OpenKey(
METADATA_MASTER_ROOT_HANDLE,
szwPath,
METADATA_PERMISSION_READ|METADATA_PERMISSION_WRITE,
60000,
&hMetaData
);
if (FAILED(hres))
{
SetLastError(hres);
goto Failed;
}
else
fMetaData = TRUE;
//
// Populate the metadata record
//
mdRecord.dwMDIdentifier = dwIdentifier;
mdRecord.dwMDAttributes = dwAttributes;
mdRecord.dwMDUserType = dwUserType;
mdRecord.dwMDDataType = dwDataType;
mdRecord.dwMDDataTag = 0;
switch (mdRecord.dwMDDataType)
{
case ALL_METADATA:
SetLastError(ERROR_NOT_SUPPORTED);
goto Failed;
case BINARY_METADATA:
mdRecord.dwMDDataLen = dwDataSize;
mdRecord.pbMDData = (PBYTE)pData;
break;
case DWORD_METADATA:
mdRecord.dwMDDataLen = sizeof(DWORD);
mdRecord.pbMDData = (PBYTE)pData;
break;
case EXPANDSZ_METADATA:
SetLastError(ERROR_NOT_SUPPORTED);
goto Failed;
case STRING_METADATA:
szwValue = MakeUnicode((LPSTR)pData, 1);
if (!szwValue)
goto Failed;
mdRecord.dwMDDataLen = sizeof(WCHAR) * (wcslen(szwValue) + 1);
mdRecord.pbMDData = (PBYTE)szwValue;
break;
case MULTISZ_METADATA:
szwValue = MakeUnicode((LPSTR)pData, 0);
if (!szwValue)
goto Failed;
mdRecord.dwMDDataLen = sizeof(WCHAR) * (wcslen(szwValue) + 2);
mdRecord.pbMDData = (PBYTE)szwValue;
break;
default:
SetLastError(ERROR_INVALID_PARAMETER);
goto Failed;
}
//
// Do the work
//
hres = g_spAdminBase->SetData(
hMetaData,
L"/",
&mdRecord
);
if (FAILED(hres))
{
SetLastError(hres);
goto Failed;
}
//
// Close the metabase
//
g_spAdminBase->CloseKey(hMetaData);
fMetaData = FALSE;
//
// Clean up
//
LocalFree(szwPath);
//LocalFree(szwValue);
return TRUE;
Failed:
dwLastError = GetLastError();
if (fMetaData)
g_spAdminBase->CloseKey(hMetaData);
LocalFree(szwPath);
LocalFree(szwValue);
SetLastError(dwLastError);
return FALSE;
}
#else
int CreateIISVDir(int arg)
{
return 0;
}
#endif
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -