Directory Services

IADsServiceOperations::Stop

The IADsServiceOperations::Stop method stops a currently active network service.

HRESULT Stop();

Parameters

This method has no parameters.

Return Values

This method supports standard return values, including S_OK. For more information about other return values, see ADSI Error Codes.

Example Code [Visual Basic]

The following code example shows how to stop the Microsoft Fax Service on a computer running Windows 2000.

Dim cp As IADsComputer
Dim so As IADsServiceOperations
On Error GoTo Cleanup

Set cp = GetObject("WinNT://myMachine,computer")
Set so = cp.GetObject("Service", "Fax")
If (so.Status = ADS_SERVICE_RUNNING) Then ' The operation is running.
	so.Stop
End If

Cleanup:
	If (Err.Number<>0) Then
		MsgBox("An error has occurred. " & Err.Number)
	End If
	Set cp = Nothing
	Set so = Nothing

Example Code [C++]

The following code example shows how to stop the Microsoft Fax Service on a computer running Windows 2000.

IADsContainer *pCont = NULL;
IADsServiceOperations *pSrvOp = NULL;
LPWSTR adsPath = L"WinNT://myMachine,computer";
IDispatch *pDisp = NULL;
long status = 0;
HRESULT hr = S_OK;

hr = ADsGetObject(adsPath,IID_IADsContainer,(void**)&pCont);
if(FAILED(hr)) {goto Cleanup;}

hr = pCont->GetObject(CComBSTR("Service"), CComBSTR("Fax"), &pDisp);
if(FAILED(hr)) {goto Cleanup;}

hr = pDisp->QueryInterface(IID_IADsServiceOperations,(void**)&pSrvOp);
if(FAILED(hr)) {goto Cleanup;}

hr = pSrvOp->get_Status(&status);
if(FAILED(hr)) {goto Cleanup;}

if(status == ADS_SERVICE_RUNNING) pSrvop->Stop();

Cleanup:
	if(pDisp) pDisp->Release();
	if(pCont) pCont->Release();
	if(pSrvOp) pSrvOp->Release();

Requirements

Client: Included in Windows XP and Windows 2000 Professional.
Server: Included in Windows Server 2003 and Windows 2000 Server.
Redistributable: Requires Active Directory Client Extension on Windows NT 4.0 SP6a and Windows 95/98/Me.
Header: Declared in Iads.h.

See Also

IADsService, IADsServiceOperations