1.获取计算机的名称和工作组 
2.通过计算机名获得IP地址; 
3.获取本机的MAC地址; 
4.获取系统的端口和状态。 
我们老师要求要满足这四项  谁能帮我一下  救命的程序啊!谢谢了 
最好是把程序发到我邮箱里 谢谢 
[email protected] 谢谢啦  拜谢!

解决方案 »

  1.   

    GetComputerName()..
    SystemInfo.exe有很多需要的信息...
      

  2.   

    WMIhttp://www.codeproject.com/KB/system/Using_WMI_in_Visual_C__.aspx?display=PrintAll&fid=31435&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=2025825&fr=26
      

  3.   

    http://msdn.microsoft.com/en-us/library/aa390418(VS.85).aspx
    #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.
    }
      

  4.   

    owo,现在要作业的怎么这么多,这些写起来有那么难么?做这种题不仅可以锻炼写代码的能力还可以锻炼查资料的能力和思考能力,当然,查资料不是指在这里白要
      

  5.   

    TO:小山
       擦我自己做出一半了都  可是我是VISTA系统  而且我电脑里没有那个NETBEUI那个协议  只有IP/TCP的 所以获取MAC地址我不知道怎么弄了就,还有就是我做完的程序没有错误可是还不能运行!拜托不要把人看扁了好么!没错 这个是作业,可是我学的是VC++MFC的基本类!!!我没有学过网络编程!我自己自学的!!才把获取计算机名称和工作组做了出来   还有就是打开端口和状态那个 我做完之后 编译没有错误,可是就是不能运行!获取IP地址也是!至于那个MAC地址我是真的不会了!我问问大家  让大家帮帮忙怎么了!你不帮就算了  何必说那么多!!!!
      

  6.   


         你说的GetComputerName()函数我用到了   可是后面的那个函数是做什么用的啊?还有就是获取网卡地址时  需要考虑网卡的协议问题么?比如我的只有TCP/IP协议
      

  7.   

    SystemInfo.exe是一个操作系统自带的exe,执行返回结果·