Voila pour Locker un pc
ISTLDLLPREFIX STL_ERRORS LockComputer ()
{
STL_ERRORS l_eRetValue = STL_NO_ERROR;
try
{
OS_TYPES l_eOsType;
DWORD l_dwBuildNumber;
char l_acAdditionalInfos [128];
l_eRetValue = GetOsType (&l_eOsType, &l_dwBuildNumber, l_acAdditionalInfos);
if (l_eRetValue != STL_NO_ERROR)
{
throw l_eRetValue;
}
switch (l_eOsType)
{
case OT_WIN_2000 :
case OT_WIN_XP :
case OT_WIN_SERVER_2003_FAMILY :
if (LockWorkStation () == FALSE)
{
l_eRetValue = STL_OS_NOT_SUPPORTED;
}
break;
default :
l_eRetValue = STL_OS_NOT_SUPPORTED;
break;
}
}
catch (STL_ERRORS)
{
}
return l_eRetValue;
}
Pour l'os
ISTLDLLPREFIX STL_ERRORS GetOsType (OS_TYPES* p_peOsType, DWORD* p_pdwBuildNumber, char p_acAdditionalInfos [128])
{
STL_ERRORS l_eRetValue;
OSVERSIONINFO l_tOsVersionStruct;
BOOL l_bError;
*p_peOsType = OT_UNKNOWN;
l_eRetValue = STL_NO_ERROR;
try
{
l_tOsVersionStruct.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
l_bError = GetVersionEx (&l_tOsVersionStruct);
if (l_bError == FALSE)
{
l_eRetValue = STL_INTERNAL_ERROR;
throw l_eRetValue;
}
*p_pdwBuildNumber = l_tOsVersionStruct.dwBuildNumber;
strncpy (p_acAdditionalInfos, l_tOsVersionStruct.szCSDVersion, 128 * sizeof (char));
switch (l_tOsVersionStruct.dwPlatformId)
{
case VER_PLATFORM_WIN32s: //windows 3.1
*p_peOsType = OT_WIN_3_1;
break;
case VER_PLATFORM_WIN32_WINDOWS: //windows 95, 98, Me
if (l_tOsVersionStruct.dwMinorVersion == 0)
{
*p_peOsType = OT_WIN_95;
}
else if (l_tOsVersionStruct.dwMinorVersion == 10)
{
*p_peOsType = OT_WIN_98;
}
else if (l_tOsVersionStruct.dwMinorVersion == 90)
{
*p_peOsType = OT_WIN_Me;
}
break;
case VER_PLATFORM_WIN32_NT: //windows NT, 2000, XP, Server 2003
if (l_tOsVersionStruct.dwMajorVersion == 3)
{
*p_peOsType = OT_WIN_NT3_51;
}
else if (l_tOsVersionStruct.dwMajorVersion == 4)
{
*p_peOsType = OT_WIN_NT4_0;
}
else if (l_tOsVersionStruct.dwMajorVersion == 5)
{
if (l_tOsVersionStruct.dwMinorVersion == 0)
{
*p_peOsType = OT_WIN_2000;
}
else if (l_tOsVersionStruct.dwMinorVersion == 1)
{
*p_peOsType = OT_WIN_XP;
}
else if (l_tOsVersionStruct.dwMinorVersion == 2)
{
*p_peOsType = OT_WIN_SERVER_2003_FAMILY ;
}
}
break;
}
}
catch (STL_ERRORS)
{
}
return l_eRetValue;
}
Pour se logger/delogger d'un ordi en reseau..
ISTLDLLPREFIX DWORD ConnectToComputer
(
char* p_pcRemoteName,
char* p_pcPassword,
char* p_pcUserName
)
{
NETRESOURCE l_oNetSrce;
DWORD l_EndStatement = NO_ERROR;
DWORD l_dwConnectRes;
l_oNetSrce.lpRemoteName = p_pcRemoteName;
l_oNetSrce.dwScope = RESOURCE_GLOBALNET;
l_oNetSrce.dwType = RESOURCETYPE_ANY;
l_oNetSrce.dwDisplayType = RESOURCEDISPLAYTYPE_SERVER;
l_oNetSrce.dwUsage = RESOURCEUSAGE_CONNECTABLE;
l_oNetSrce.lpLocalName = NULL;
l_oNetSrce.lpProvider = NULL;
l_dwConnectRes = WNetAddConnection2 (&l_oNetSrce, p_pcPassword, p_pcUserName, NULL);
if (l_dwConnectRes != NO_ERROR)
return l_dwConnectRes;
return l_EndStatement;
}
/***************************************/
/***************************************/
/* DisconnectFromComputer */
/***************************************/
/***************************************/
ISTLDLLPREFIX DWORD DisconnectFromComputer
(
char* p_pcRemoteName
)
{
DWORD l_dwRes;
l_dwRes = WNetCancelConnection2(p_pcRemoteName, CONNECT_UPDATE_PROFILE, true);
return l_dwRes;
}