3 《Undocumented Windows 2000 Secrets》翻译 --- 第三章( 五 )


BOOL WINAPI w2kServiceContinue (SC_HANDLE hManager,
PWORD pwName)
{
return w2kServiceControl (hManager, pwName,
SERVICE_CONTROL_CONTINUE);
}
// -----------------------------------------------------------------
SC_HANDLE WINAPI w2kServiceLoad (PWORD pwName,
PWORD pwInfo,
PWORD pwPath,
BOOL fStart)
{
BOOL fOk;
SC_HANDLE hManager = NULL;
if ((hManager = w2kServiceConnect ()) != NULL)
{
fOk = w2kServiceAdd (hManager, pwName, pwInfo, pwPath);
if (fOk && fStart)
{
if (!(fOk = w2kServiceStart (hManager, pwName)))
{
w2kServiceRemove (hManager, pwName);
}
}
if (!fOk)
{
hManager = w2kServiceDisconnect (hManager);
}
}
return hManager;
}
// -----------------------------------------------------------------
SC_HANDLE WINAPI w2kServiceLoadEx (PWORD pwPath,
BOOL fStart)
{
PVS_VERSIONDATA pvvd;
PWORD pwPath1, pwInfo;
WORD awName [MAX_PATH];
DWORD dName, dExtension;
SC_HANDLE hManager = NULL;
if (pwPath != NULL)
{
dName = w2kPathName (pwPath, &dExtension);
lstrcpyn (awName, pwPathdName,
min (MAX_PATH, dExtension - dName1));
pwPath1 = w2kPathEvaluate (pwPath, NULL);
pvvd = w2kVersionData (pwPath1, -1);
pwInfo = ((pvvd != NULL) && pvvd->awFileDescription [0]
? pvvd->awFileDescription
: awName);
hManager = w2kServiceLoad (awName, pwInfo, pwPath1, fStart);
w2kMemoryDestroy (pvvd);
w2kMemoryDestroy (pwPath1);
}
return hManager;
}
// -----------------------------------------------------------------
BOOL WINAPI w2kServiceUnload (PWORD pwName,
SC_HANDLE hManager)
{
SC_HANDLE hManager1 = hManager;
BOOL fOk = FALSE;
if (pwName != NULL)
{
if (hManager1 == NULL)
{
hManager1 = w2kServiceConnect ();
}
if (hManager1 != NULL)
{
w2kServiceStop (hManager1, pwName);
fOk = w2kServiceRemove (hManager1, pwName);
}
}
w2kServiceDisconnect (hManager1);
return fOk;
}
// -----------------------------------------------------------------
BOOL WINAPI w2kServiceUnloadEx (PWORD pwPath,
SC_HANDLE hManager)
{
DWORD dName, dExtension;
WORD awName [MAX_PATH];
PWORD pwName = NULL;
if (pwPath != NULL)
{
dName = w2kPathName (pwPath, &dExtension);
lstrcpyn (pwName = awName, pwPathdName,
min (MAX_PATH, dExtension - dName1));
}
return w2kServiceUnload (pwName, hManager);
}
// -----------------------------------------------------------------
列表 3-8. 服务和驱动管理库函数

推荐阅读