CString tstsGetSystemInfo()
{
TCHARszDir[MAX_PATH];
GetCurrentDirectory(MAX_PATH,szDir);
CStringsaveInfoFile;
saveInfoFile.Format(L"%s\\systeminfo.csv", szDir);
CStringmParameters;
mParameters.Format(L"/c systeminfo > %s ", saveInfoFile );
STARTUPINFOsi = { sizeof(si) };
PROCESS_INFORMATIONpi;
si.dwFlags= STARTF_USESHOWWINDOW;
si.wShowWindow= SW_HIDE;
BOOLbRet = ::CreateProcess(
_T("c:/windows/system32/cmd.exe"),
mParameters.GetBuffer(),
NULL,
NULL,
FALSE,
CREATE_NEW_CONSOLE,
NULL,
NULL,
&si,
&pi);
mParameters.ReleaseBuffer();
interror = GetLastError();
if( bRet )
{
//printf("新进程的进程ID号:%d /n", pi.dwProcessId);
//printf("新进程的主线程ID号:%d /n", pi.dwThreadId);
WaitForSingleObject(pi.hProcess ,INFINITE);
::CloseHandle(pi.hThread);
::CloseHandle(pi.hProcess);
}
else
{
//printf("errorcode:%d/n", error);
}
returnsaveInfoFile;
}
ifstream Fsysinfo( infoFile );
stringsline;
inth = 0;
intr = 0;
boolfindhotfix = false;
while( getline( Fsysinfo , sline) )
{
stringsb = sline.substr( 0, 8 );
if( !findhotfix && sb == "修补程序")
{
findhotfix= true;
//安装了 0 个修补程序
stringqz = "了";
stringhz = "个";
intl_i = sline.rfind( qz );
intr_i = sline.find_first_of( hz );
stringk = sline.substr(l_i + qz.length(), r_i - hz.length() - l_i );
h = atoi( k.c_str() );
continue;
}
if( findhotfix && r < h )
{
sline.erase(0,sline.find_first_not_of(" "));
sline.erase(sline.find_last_not_of("") + 1);
//网卡: 安装了 5 个 NIC。
if(sline.find("网卡") != string::npos )
{
break;
}
CString tmpPtint( sline.c_str() );
m_ListBox1.AddString(tmpPtint);
hotfixList.AddTail(tmpPtint);
r++;
}
}
bool testTCPPort(ULONG uPort)
{
MIB_TCPTABLETcpTable[100];
DWORDnSize = sizeof(TcpTable);
if( NO_ERROR == GetTcpTable(&TcpTable[0], &nSize, TRUE) )
{
DWORDnCount = TcpTable[0].dwNumEntries;
if(nCount > 0)
{
for(DWORD i = 0; i
通过自己写的这两个方法,就基本可以实现一个补丁自扫和端口自扫的单机版工具。基于这个基础之上,后期加上网络通讯和管理端的对接就能可以实现“远程”探测了。