Click here to Skip to main content
15,881,600 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Date compare Pin
David Crow24-Apr-09 4:10
David Crow24-Apr-09 4:10 
AnswerRe: Date compare Pin
Joe Woodbury24-Apr-09 15:45
professionalJoe Woodbury24-Apr-09 15:45 
QuestionProblem calling a DLL from another DLL Pin
Mohammad A Gdeisat24-Apr-09 1:30
Mohammad A Gdeisat24-Apr-09 1:30 
AnswerRe: Problem calling a DLL from another DLL Pin
Cedric Moonen24-Apr-09 1:48
Cedric Moonen24-Apr-09 1:48 
GeneralRe: Problem calling a DLL from another DLL Pin
Mohammad A Gdeisat24-Apr-09 3:22
Mohammad A Gdeisat24-Apr-09 3:22 
AnswerRe: Problem calling a DLL from another DLL Pin
CPallini24-Apr-09 2:12
mveCPallini24-Apr-09 2:12 
GeneralRe: Problem calling a DLL from another DLL Pin
Mohammad A Gdeisat24-Apr-09 3:19
Mohammad A Gdeisat24-Apr-09 3:19 
Question[WMI]Why I Invoke GetObject() failed with message:"Access Denied" Pin
aqz954823-Apr-09 23:54
aqz954823-Apr-09 23:54 
I Want to Create process on Remote computer.But, I Invoke GetObject() failed with message:"Access Denied" .thanks.

The code:

    HRESULT hres;

    // Step 1: --------------------------------------------------
    // Initialize COM. ------------------------------------------

    hres =  CoInitializeEx(0, COINIT_MULTITHREADED); 
    if (FAILED(hres))
    {
        TRACE("Failed to initialize COM library. Error code = %ld",hres); 
        return;                  // Program has failed.
    }

    // Step 2: --------------------------------------------------
    // Set general COM security levels --------------------------
    // Note: If you are using Windows 2000, you need to specify -
    // the default authentication credentials for a user by using
    // a SOLE_AUTHENTICATION_LIST structure in the pAuthList ----
    // parameter of CoInitializeSecurity ------------------------


	if(S_OK!= CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_CONNECT, RPC_C_IMP_LEVEL_IDENTIFY, NULL, EOAC_NONE, 0) )
	{
		TRACE("Failed to initialize security. Error code = %ld\n",hres); 
		CoUninitialize();
		return;                    // Program has failed.
	}				
			
    
    // Step 3: ---------------------------------------------------
    // Obtain the initial locator to WMI -------------------------

    IWbemLocator *pLoc = NULL;

    hres = CoCreateInstance(
        CLSID_WbemLocator,             
        0, 
        CLSCTX_INPROC_SERVER, 
        IID_IWbemLocator, (LPVOID *) &pLoc);
 
    if (FAILED(hres))
    {
        TRACE("Failed to create IWbemLocator object.Err code = %ld\n",hres);
		CoUninitialize();
        return;                 // Program has failed.
    }

    // Step 4: -----------------------------------------------------
    // Connect to WMI through the IWbemLocator::ConnectServer method

    IWbemServices *pSvc = NULL; 

	hres = pLoc->ConnectServer(
        _bstr_t(L"\\\\192.168.0.2\\ROOT\\CIMV2"),//computer name, DNS name or IP address
        _bstr_t("administrator"),                 // User name
        _bstr_t("2007"),                  // User password
        NULL,//_bstr_t(L"MS_409"),               // Locale             
        NULL,/*WBEM_FLAG_CONNECT_USE_MAX_WAIT, */                            // Security flags
        NULL,/*_bstr_t(L"ntlmdomain:TIPRAY.com"),*/   // Authority
        0,                                // Context object 
        &pSvc                             // IWbemServices proxy
        );

    if (FAILED(hres))
    {
        TRACE("Could not connect. Error code = %ld\n",hres); 
        pLoc->Release();     
        CoUninitialize();
        return;                // Program has failed.
    }

    TRACE("Connected to ROOT\\CIMV2 WMI namespace\n");

    // Step 5: --------------------------------------------------
    // Set security levels on a WMI connection ------------------

    hres = CoSetProxyBlanket(
       pSvc,                        // Indicates the proxy to set
       RPC_C_AUTHN_WINNT,           // RPC_C_AUTHN_xxx
       RPC_C_AUTHZ_NONE,            // RPC_C_AUTHZ_xxx
       NULL,                        // Server principal name 
       RPC_C_AUTHN_LEVEL_CALL,      // RPC_C_AUTHN_LEVEL_xxx 
       RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
       NULL,                        // client identity
       EOAC_NONE                    // proxy capabilities 
    );

    if (FAILED(hres))
    {
        TRACE("Could not set proxy blanket. Error code = %ld\n",hres);
        pSvc->Release();
        pLoc->Release();     
        CoUninitialize();
        return;               // Program has failed.
    }

	// Step 6: --------------------------------------------------
    // Use the IWbemServices pointer to make requests of WMI ----
	
    // set up to call the Win32_Process::Create method
    BSTR MethodName = SysAllocString(L"Create");
    BSTR ClassName = SysAllocString(L"Win32_Process");
	
    IWbemClassObject* pClass = NULL;
[color=#FF0000]    hres = pSvc->GetObject(ClassName, 0, NULL, &pClass, NULL);[/color]//<<========================在这边失败
	
	if (FAILED(hres))
    {
        TRACE("Could not GetObject. Error code = %ld\n",hres);
        SysFreeString(ClassName);
        SysFreeString(MethodName);
        pSvc->Release();
        pLoc->Release();     
        CoUninitialize();
        return;               // Program has failed.
    }

    IWbemClassObject* pInParamsDefinition = NULL;
    hres = pClass->GetMethod(MethodName, 0, &pInParamsDefinition, NULL);
	
    IWbemClassObject* pClassInstance = NULL;
    hres = pInParamsDefinition->SpawnInstance(0, &pClassInstance);
	
    // Create the values for the in parameters
    VARIANT varCommand;
    varCommand.vt = VT_BSTR;
    varCommand.bstrVal = L"\\\\192.168.2.2\\Setup\\IntraView.exe";
	
    // Store the value for the in parameters
    hres = pClassInstance->Put(L"CommandLine", 0,
        &varCommand, 0);
	
	if (FAILED(hres))
    {
        TRACE("Could not put. Error code = %ld\n",hres);
        SysFreeString(ClassName);
        SysFreeString(MethodName);
        pClass->Release();
        pSvc->Release();
        pLoc->Release();     
        CoUninitialize();
        return;               // Program has failed.
    }


    // Execute Method
    IWbemClassObject* pOutParams = NULL;
    hres = pSvc->ExecMethod(ClassName, MethodName, 0,NULL, pClassInstance, &pOutParams, NULL);
	
    if (FAILED(hres))
    {
        TRACE("Could not execute method. Error code = %ld\n",hres);
        SysFreeString(ClassName);
        SysFreeString(MethodName);
        pClass->Release();
        pInParamsDefinition->Release();
        pOutParams->Release();
        pSvc->Release();
        pLoc->Release();     
        CoUninitialize();
        return;               // Program has failed.
    }

    // Cleanup
    // ========

    SysFreeString(ClassName);
    SysFreeString(MethodName);
    pClass->Release();
    pInParamsDefinition->Release();
    pOutParams->Release();
    pLoc->Release();
    pSvc->Release();
    CoUninitialize();

AnswerRe: [WMI]Why I Invoke GetObject() failed with message:"Access Denied" Pin
Baltoro25-Apr-09 8:43
Baltoro25-Apr-09 8:43 
GeneralRe: [WMI]Why I Invoke GetObject() failed with message:"Access Denied" Pin
aqz954826-Apr-09 17:02
aqz954826-Apr-09 17:02 
QuestionHow get path of shortcut of internet explorer Pin
ashish8patil23-Apr-09 23:28
ashish8patil23-Apr-09 23:28 
AnswerRe: How get path of shortcut of internet explorer Pin
Sarath C24-Apr-09 2:37
Sarath C24-Apr-09 2:37 
GeneralRe: How get path of shortcut of internet explorer Pin
ashish8patil24-Apr-09 2:43
ashish8patil24-Apr-09 2:43 
Questionproblem with relese mode Pin
kir_MFC23-Apr-09 23:25
kir_MFC23-Apr-09 23:25 
AnswerRe: problem with relese mode Pin
Cedric Moonen23-Apr-09 23:30
Cedric Moonen23-Apr-09 23:30 
AnswerRe: problem with relese mode Pin
Hamid_RT24-Apr-09 0:08
Hamid_RT24-Apr-09 0:08 
QuestionRe: problem with relese mode Pin
David Crow24-Apr-09 4:13
David Crow24-Apr-09 4:13 
QuestionCan you please explain me why this code is not working ? Pin
kapardhi23-Apr-09 23:19
kapardhi23-Apr-09 23:19 
AnswerRe: Can you please explain me why this code is not working ? Pin
Code-o-mat23-Apr-09 23:46
Code-o-mat23-Apr-09 23:46 
GeneralRe: Can you please explain me why this code is not working ? Pin
kapardhi24-Apr-09 0:01
kapardhi24-Apr-09 0:01 
GeneralRe: Can you please explain me why this code is not working ? Pin
Code-o-mat24-Apr-09 1:00
Code-o-mat24-Apr-09 1:00 
AnswerRe: Can you please explain me why this code is not working ? Pin
Stuart Dootson23-Apr-09 23:46
professionalStuart Dootson23-Apr-09 23:46 
GeneralRe: Can you please explain me why this code is not working ? Pin
kapardhi23-Apr-09 23:57
kapardhi23-Apr-09 23:57 
GeneralRe: Can you please explain me why this code is not working ?r Pin
CPallini24-Apr-09 0:12
mveCPallini24-Apr-09 0:12 
GeneralRe: Can you please explain me why this code is not working ? Pin
Chris Losinger24-Apr-09 2:58
professionalChris Losinger24-Apr-09 2:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.