#ifdef Q_OS_WIN32 #include "windef.h" #include "winbase.h" #include "wingdi.h" #include "winuser.h" #include "psapi.h" #include "winsvc.h" #include "shellapi.h" #include "ras.h" #include "tchar.h" #include "raserror.h" #include "rasdlg.h" #include "winreg.h"#else#endifvoid rasPrimer(){ RASENTRYNAME *lpRasEntryName; DWORD cb = 0; DWORD cEntries = 0; DWORD nRet; lpRasEntryName = (LPRASENTRYNAME)GlobalAlloc(GPTR, sizeof(RASENTRYNAME)); lpRasEntryName->dwSize = sizeof(RASENTRYNAME); nRet = RasEnumEntries(NULL, NULL, lpRasEntryName, &cb, &cEntries); if (nRet == ERROR_BUFFER_TOO_SMALL) { lpRasEntryName = (LPRASENTRYNAME)GlobalAlloc(GPTR, cb); lpRasEntryName->dwSize = sizeof(RASENTRYNAME); } // Calling RasEnumEntries to enumerate the phone-book entries nRet = RasEnumEntries(NULL, NULL, lpRasEntryName, &cb, &cEntries); if (nRet != ERROR_SUCCESS) { printf("RasEnumEntries failed: Error %d\n", nRet); } else { printf("Phone-book entries in the default phone book:\n\n"); for(int i=0;i < cEntries;i++) { printf("%s\n",lpRasEntryName->szEntryName); lpRasEntryName++; } }}
qint32 connectionEntries(QStringList& connectionEntries){#ifdef Q_OS_WIN32 DWORD dwCb = 0; DWORD dwRet = ERROR_SUCCESS; DWORD dwEntries = 0; RASENTRYNAME qwe; qwe.dwSize=sizeof(qwe); LPRASENTRYNAME lpRasEntryName = &qwe; // Call RasEnumEntries with lpRasEntryName = NULL. dwCb is returned with the required buffer size and // a return code of ERROR_BUFFER_TOO_SMALL dwRet = RasEnumEntries(NULL, NULL, lpRasEntryName, &dwCb, &dwEntries); if (dwRet == ERROR_BUFFER_TOO_SMALL) { // Allocate the memory needed for the array of RAS entry names. lpRasEntryName = (LPRASENTRYNAME) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwCb); if (lpRasEntryName == NULL) { qDebug()<<"connectionEntries: HeapAlloc failed!"; return 0; } // The first RASENTRYNAME structure in the array must contain the structure size lpRasEntryName[0].dwSize = sizeof(RASENTRYNAME); // Call RasEnumEntries to enumerate all RAS entry names dwRet = RasEnumEntries(NULL, NULL, lpRasEntryName, &dwCb, &dwEntries); // If successful, print the RAS entry names if (ERROR_SUCCESS == dwRet) { qDebug()<<"The following RAS entry names were found:"; for (DWORD i = 0; i < dwEntries; i++) { qDebug()<<QString("connectionEntries: %1\n").arg(TCHARToQString(&(lpRasEntryName[i].szEntryName))); connectionEntries.append(TCHARToQString(&(lpRasEntryName[i].szEntryName))); } } //Deallocate memory for the connection buffer HeapFree(GetProcessHeap(), 0, lpRasEntryName); lpRasEntryName = NULL; return 0; } else qDebug()<<QString("dwRet=%1").arg(dwRet); // There was either a problem with RAS or there are RAS entry names to enumerate if(dwEntries >= 1) { qDebug()<<"connectionEntries: The operation failed to acquire the buffer size."; } else { qDebug()<<"connectionEntries: There were no RAS entry names found:."; } return 0;#else qDebug()<<"Only for Windiws"; Q_UNUSED(connectionEntries) return -1;#endif}
#ifdef UNICODE#define QStringToTCHAR(x) (wchar_t*) x.utf16()#define PQStringToTCHAR(x) (wchar_t*) x->utf16()#define TCHARToQString(x) QString::fromUtf16((x))#define TCHARToQStringN(x,y) QString::fromUtf16((x),(y))#else#define QStringToTCHAR(x) x.local8Bit().constData()#define PQStringToTCHAR(x) x->local8Bit().constData()#define TCHARToQString(x) QString::fromLocal8Bit((x))#define TCHARToQStringN(x,y) QString::fromLocal8Bit((x),(y))#endif
#ifdef UNICODE #define QStringToTCHAR(x) (wchar_t*) x.utf16() #define PQStringToTCHAR(x) (wchar_t*) x->utf16() #define TCHARToQString(x) QString::fromUtf16((ushort*)(x)) #define TCHARToQStringN(x,y) QString::fromUtf16((ushort*)(x),(y))#else #define QStringToTCHAR(x) x.local8Bit().constData() #define PQStringToTCHAR(x) x->local8Bit().constData() #define TCHARToQString(x) QString::fromLocal8Bit((x)) #define TCHARToQStringN(x,y) QString::fromLocal8Bit((x),(y))#endif /*UNICODE*/
#include <netcon.h>void DisableNIC(char* InterfaceName){ INetConnectionManager* pNet; INetConnection* pConn; IEnumNetConnection* pEnum; NETCON_PROPERTIES* pProps; wchar_t Temp[255]; ULONG uCount = 0; swprintf(Temp, L"%S", InterfaceName); CoInitialize(NULL); CoCreateInstance(CLSID_ConnectionManager, NULL, CLSCTX_SERVER, IID_INetConnectionManager, (void**)&pNet); pNet->EnumConnections(NCME_DEFAULT, &pEnum); while (pEnum->Next(1, &pConn, &uCount) == S_OK) { pConn->GetProperties( &pProps ); if (!wcscmp(pProps->pszwName, Temp)) { printf("Found %S\n", pProps->pszwName); printf("Going to disable connection now!\n"); pConn->Disconnect(); printf("Disabled!"); CoTaskMemFree(pProps->pszwName); CoTaskMemFree(pProps->pszwDeviceName); CoTaskMemFree(pProps); pConn->Release(); } } pEnum->Release(); pNet->Release(); CoUninitialize();}