Directory Services

IADsSession Property Methods

The property methods of the IADsSession interface get or set the properties described in the following table. For a general discussion of property methods, see Interface Property Methods.

Properties

Property Description
Computer

[Visual Basic]
Access: Read-only
DataType: BSTR

[C++]
HRESULT get_Computer
([out] BSTR* pbstrComputer);

Name of the client workstation.
ComputerPath

[Visual Basic]
Access: Read-only
DataType: BSTR

[C++]
HRESULT get_ComputerPath
([out] BSTR* pbstrComputerPath);

ADsPath of the computer object for the client workstation.
ConnectTime

[Visual Basic]
Access: Read-only
DataType: Long

[C++]
HRESULT get_ConnectTime
([out] LONG* plConnectTime);

Number of minutes that have elapsed since the session started.
IdleTime

[Visual Basic]
Access: Read-only
DataType: Long

[C++]
HRESULT get_IdleTime
([out] LONG* plIdleTime);

The idle time of the session, in minutes.
User

[Visual Basic]
Access: Read-only
DataType: BSTR

[C++]
HRESULT get_User
([out] BSTR* pbstrUser);

The name of the user of the session.
UserPath

[Visual Basic]
Access: Read-only
DataType: BSTR

[C++]
HRESULT get_UserPath
([out] BSTR* pbstrUserPath);

The ADsPath of the user object for the user of this session.

Example Code [Visual Basic]

The following code example shows how to examine sessions for a file service.

Dim fso As IADsFileServiceOperations
On Error GoTo Cleanup

' Bind to a file service operations object on "myComputer" in the local domain.
Set fso = GetObject("WinNT://myComputer/LanmanServer")

' Enumerate sessions.
If (IsEmpty(fso) = False) Then
	For Each session In fso.sessions
		MsgBox "Session Computer: " & session.Computer
		MsgBox "Session User: " & session.User
	Next Session
End If

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

Example Code [C++]

The following code example enumerates a collection of sessions.

IADsFileServiceOperations *pFso = NULL;
IADsSession *pSes = NULL;
IADsCollection *pColl = NULL;
HRESULT hr = S_OK;
IUnknown *pUnk = NULL;
BSTR bstr = NULL;
VARIANT var;
ULONG lFetch = 0;
IDispatch *pDisp = NULL;
IEnumVARIANT *pEnum = NULL;

VariantInit(&var);

LPWSTR adsPath = L"WinNT://aMachine/LanmanServer";

hr = ADsGetObject(adsPath,IID_IADsFileServiceOperations,
				(void**)&pFso);

if(FAILED(hr)) {goto Cleanup;}

hr = pFso->Sessions(&pColl);

// Enumerate sessions. 
hr = pColl->get__NewEnum(&pUnk);
if(FAILED(hr)) {goto Cleanup;}

hr = pUnk->QueryInterface(IID_IEnumVARIANT,(void**)&pEnum);
if(FAILED(hr)) {goto Cleanup;}

// Enumerate.
hr = pEnum->Next(1, &var, &lFetch);
while(hr == S_OK)
{
	if (lFetch == 1)
	{
		pDisp = V_DISPATCH(&var);
		pDisp->QueryInterface(IID_IADsSession, (void**)&pSes);
		pSes->get_Computer(&bstr);
		printf("Session host: %S\n",bstr);
		SysFreeString(bstr);

		pSes->get_User(&bstr);
		printf("Session user: %S\n",bstr);
		SysFreeString(bstr);

		pRes->Release();
}

	VariantClear(&var);
	pDisp=NULL;
	hr = pEnum->Next(1, &var, &lFetch);
};

Cleanup:
	if(pFso) pFso->Release();
	if(pColl) pColl->Release();
	if(pUnk) pUnk->Release();
	if(pEnum) pEnum->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

IADsFileServiceOperations::Sessions, IADsSession