1.获取计算机的名称和工作组
2.通过计算机名获得IP地址;
3.获取本机的MAC地址;
4.获取系统的端口和状态。
我们老师要求要满足这四项 谁能帮我一下 救命的程序啊!谢谢了
最好是把程序发到我邮箱里 谢谢
[email protected] 谢谢啦 拜谢!
2.通过计算机名获得IP地址;
3.获取本机的MAC地址;
4.获取系统的端口和状态。
我们老师要求要满足这四项 谁能帮我一下 救命的程序啊!谢谢了
最好是把程序发到我邮箱里 谢谢
[email protected] 谢谢啦 拜谢!
解决方案 »
- BACnet客户端开发
- 对话框最大化按钮如何变成问号,然后点击它时弹出帮助文档?
- 求高手帮个忙!帮我设计一个加法测试系统;
- 简单问题:退出程序的处理是放在OnClose中吗?
- CDC::SelectObject()选入设备的位图放在什么坐标位置?为何其不受OffsetViewportOrg()的影响而一起偏移?
- 请教对话框如何取得框架中已经使用的控件对象?
- CListCtrl如何响应鼠标双击
- 在VC里怎么样将得到的数据导入到Excel表格中保存?
- 哪位兄弟理解KLT理解得透彻?书上大多是描述一下算法过程,和算法特征而已。
- 哪有mp3播放及cd转wav,转mp3的vc源代码
- 已经装了vc6.0,vc9.0,再装个vc7.0,不会有兼容性问题吧?
- List Control 的标题在Vista环境下的显示
SystemInfo.exe有很多需要的信息...
#define _WIN32_DCOM
#include <iostream>
using namespace std;
#include <comdef.h>
#include <Wbemidl.h># pragma comment(lib, "wbemuuid.lib")int main(int argc, char **argv)
{
HRESULT hres; // Initialize COM.
hres = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED(hres))
{
cout << "Failed to initialize COM library. "
<< "Error code = 0x"
<< hex << hres << endl;
return 1; // Program has failed.
} // Initialize
hres = CoInitializeSecurity(
NULL,
-1, // COM negotiates service
NULL, // Authentication services
NULL, // Reserved
RPC_C_AUTHN_LEVEL_DEFAULT, // authentication
RPC_C_IMP_LEVEL_IMPERSONATE, // Impersonation
NULL, // Authentication info
EOAC_NONE, // Additional capabilities
NULL // Reserved
);
if (FAILED(hres))
{
cout << "Failed to initialize security. "
<< "Error code = 0x"
<< hex << hres << endl;
CoUninitialize();
return 1; // Program has failed.
} // Obtain the initial locator to Windows Management
// on a particular host computer.
IWbemLocator *pLoc = 0; hres = CoCreateInstance(
CLSID_WbemLocator,
0,
CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID *) &pLoc);
if (FAILED(hres))
{
cout << "Failed to create IWbemLocator object. "
<< "Error code = 0x"
<< hex << hres << endl;
CoUninitialize();
return 1; // Program has failed.
} IWbemServices *pSvc = 0; // Connect to the root\cimv2 namespace with the
// current user and obtain pointer pSvc
// to make IWbemServices calls. hres = pLoc->ConnectServer(
_bstr_t(L"ROOT\\CIMV2"), // WMI namespace
NULL, // User name
NULL, // User password
0, // Locale
NULL, // Security flags
0, // Authority
0, // Context object
&pSvc // IWbemServices proxy
);
if (FAILED(hres))
{
cout << "Could not connect. Error code = 0x"
<< hex << hres << endl;
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.
} cout << "Connected to ROOT\\CIMV2 WMI namespace" << endl; // Set the IWbemServices proxy so that impersonation
// of the user (client) occurs.
hres = CoSetProxyBlanket(
pSvc, // the proxy to set
RPC_C_AUTHN_WINNT, // authentication service
RPC_C_AUTHZ_NONE, // authorization service
NULL, // Server principal name
RPC_C_AUTHN_LEVEL_CALL, // authentication level
RPC_C_IMP_LEVEL_IMPERSONATE, // impersonation level
NULL, // client identity
EOAC_NONE // proxy capabilities
); if (FAILED(hres))
{
cout << "Could not set proxy blanket. Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.
}
// Use the IWbemServices pointer to make requests of WMI.
// Make requests here: // For example, query for all the running processes
IEnumWbemClassObject* pEnumerator = NULL;
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT * FROM Win32_Process"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
if (FAILED(hres))
{
cout << "Query for processes failed. "
<< "Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return 1; // Program has failed.
}
else
{
IWbemClassObject *pclsObj;
ULONG uReturn = 0;
while (pEnumerator)
{
hres = pEnumerator->Next(WBEM_INFINITE, 1,
&pclsObj, &uReturn); if(0 == uReturn)
{
break;
} VARIANT vtProp; // Get the value of the Name property
hres = pclsObj->Get(L"Name", 0, &vtProp, 0, 0);
wcout << "Process Name : " << vtProp.bstrVal << endl;
VariantClear(&vtProp);
}
}
// Cleanup
// ======== pSvc->Release();
pLoc->Release();
CoUninitialize(); return 0; // Program successfully completed.
}
擦我自己做出一半了都 可是我是VISTA系统 而且我电脑里没有那个NETBEUI那个协议 只有IP/TCP的 所以获取MAC地址我不知道怎么弄了就,还有就是我做完的程序没有错误可是还不能运行!拜托不要把人看扁了好么!没错 这个是作业,可是我学的是VC++MFC的基本类!!!我没有学过网络编程!我自己自学的!!才把获取计算机名称和工作组做了出来 还有就是打开端口和状态那个 我做完之后 编译没有错误,可是就是不能运行!获取IP地址也是!至于那个MAC地址我是真的不会了!我问问大家 让大家帮帮忙怎么了!你不帮就算了 何必说那么多!!!!
你说的GetComputerName()函数我用到了 可是后面的那个函数是做什么用的啊?还有就是获取网卡地址时 需要考虑网卡的协议问题么?比如我的只有TCP/IP协议