Esempio n. 1
0
int logoffUser(TCHAR *userToLogoff)
{
    wprintf(L"Logging off %s\n", userToLogoff);

    int sessionId = findSession(userToLogoff);

    if (sessionId != -1)
    {
        wprintf(L"  session %d\n", sessionId);
        if (!WTSLogoffSession(WTS_CURRENT_SERVER_HANDLE, sessionId, TRUE))
        {
            printError(L"WTSLogoffSession failed: %s");
            return 3;
        }
        else 
            wprintf(L"  ...done.\n");
    }
    else 
    {
		std::wstring msg;
		msg.append(L"Session for ")
			.append(userToLogoff)
			.append(L" not found");
		wprintf(msg.c_str());
		showBalloonTip(msg.c_str());

        return 2;
    }

    return 0;
}
Esempio n. 2
0
		/*
		@brief Logs off the current user from the active session. It is irelevant, if it is a console or rdp session.
		It needs the session number, which can be queried with the QueryActiveSession method.
		@param SessioNumber The session number to the current active session.
		@return
		*/
		bool WinApiHelper::LogOff(quint64 SessioNumber)
		{
			if (!WTSLogoffSession(WTS_CURRENT_SERVER_HANDLE, SessioNumber, true))
			{
				DWORD err = GetLastError();
				m_logger->error("WTSLogoffSession failed. GetLastError: ") << err;
				return false;
			}
			else
			{
				//This will be logged by the service. No logging needed here.
				return true;
			}
		}
Esempio n. 3
0
// @pymethod |win32ts|WTSLogoffSession|Logs off a user logged in through Terminal Services
static PyObject *PyWTSLogoffSession(PyObject *self, PyObject *args, PyObject *kwargs)
{
	static char *keywords[]={"Server","SessionId","Wait", NULL};
	HANDLE h;
	PyObject *obh;
	DWORD SessionId;
	BOOL Wait;

	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Okl:WTSLogoffSession", keywords,
		&obh,		// @pyparm <o PyHANDLE>|Server||Handle to a terminal server
		&SessionId,	// @pyparm int|SessionId||Terminal services session id as returned by <om win32ts.WTSEnumerateSessions>
		&Wait))		// @pyparm boolean|Wait||Indicates whether operation should be performed asynchronously
		return NULL;

	if (!PyWinObject_AsHANDLE(obh, &h))
		return NULL;
	if (!WTSLogoffSession(h, SessionId, Wait))
		return PyWin_SetAPIError("WTSLogoffSession");
	Py_INCREF(Py_None);
	return Py_None;
}