Thread: How to monitor process creation?

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I dunno. It compiles for me (using 2008).
    The only thing I can think of is that VC's headers are outdated.
    Try right-clicking on COINIT_MULTITHREADED and select "go to declaration". See if it finds it.

    You can also try a rebuild.
    Make sure you did as the tutorial mentioned. Copying the first past into the first .cpp source file, the second into a header and the third into 2nd sound file and compile works for me.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Registered User
    Join Date
    Mar 2008
    Posts
    26
    If it compiles to you maybe you send this code to me?
    By email or upload it to some web-storage.

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Copy n' paste, mate, copy n' paste.
    All I was copy & paste.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #19
    Registered User
    Join Date
    Mar 2008
    Posts
    26
    Quote Originally Posted by Elysia View Post
    Copy n' paste, mate, copy n' paste.
    All I was copy & paste.
    Me too.

  5. #20
    Registered User
    Join Date
    Mar 2008
    Posts
    26
    What kind of project did you create?

  6. #21
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I simply used an existing console project.
    But anyway, try finding the define, as I told you earlier. See if you can find them. Dig inside the headers.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #22
    Registered User
    Join Date
    Mar 2008
    Posts
    26
    Ok, the COINIT_MULTITHREADED error was fixed by adding #define _WIN32_DCOM to stdafx.h, why it's needed there?

  8. #23
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It needs to be defined before you include all the headers.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #24
    Registered User
    Join Date
    Mar 2008
    Posts
    26
    #define _WIN32_DCOM- what it for? Why do i need to include it?

  10. #25
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I don't know what it's used for, only that it seems you must define it to use COM (that or use a higher _WIN32_WINNT).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #26
    Registered User
    Join Date
    Mar 2008
    Posts
    26
    Ok, now the event us triggered when new process is created.
    How Do I get the file name and path of this process?

  12. #27
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    How Do I get the file name and path of this process?
    Once you have the process ID, you can use the code example at this link to get the complete command line of the process.

  13. #28
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    There's lots of information in the Win32_Process object in the callback to Indicate(). Replace your EventSink::Indicate() with this. It shows how to get a "pointer" to the Win32_Process object and then get its "ExecutablePath" property.
    Code:
    #include <comutil.h>
    _COM_SMARTPTR_TYPEDEF(IWbemClassObject, __uuidof(IWbemClassObject));
    
    HRESULT EventSink::Indicate(long lObjectCount, IWbemClassObject **apObjArray)
    {
    	HRESULT hres = S_OK;
    
        for (int i = 0; i < lObjectCount; i++)
        {
            cout << "Event occurred" << endl;
            IWbemClassObject *pObj = apObjArray[i];
    
            HRESULT hres;
            VARIANT vInst_;
            hres = pObj->Get(L"TargetInstance", 0, &vInst_, 0, 0);
            if (FAILED(hres))
            {
                cout << "Failed to get TargetInstance: " << hres << endl;
                continue;
            }//if
    
            try
            {
                _variant_t vInst;
                vInst.Attach(vInst_); // use C++ class to manage VARIANT
    
                IWbemClassObjectPtr pWin32ProcessObj(vInst);
    
                VARIANT vVar;
                hres = pWin32ProcessObj->Get(L"ExecutablePath", 0, &vVar, 0, 0);
                if (FAILED(hres))
                {
                    cout << "Failed to get ExecutablePath: " << hres << endl;
                }//if
                else
                {
                    _variant_t vExecPath;
                    vExecPath.Attach(vVar);
    
                    wcout << L"ExecPath: " << (const wchar_t*)((_bstr_t)vExecPath) << endl;
                }//else
            }//try
            catch(_com_error &err)
            {
                cout << "caught _com_error: " << err.Error() << endl;
            }//catch
        }//for
    
        return WBEM_S_NO_ERROR;
    }//Indicate
    gg

  14. #29
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    Quote Originally Posted by Elysia View Post
    Yes, I see it's a fat example now, but Microsoft didn't include the right headers in the code. Bah. Stupid Microsoft.
    What other errors? HRESULT you can get from Windows.h and COM stuff from objbase.h.
    no the problem is he has teh project set as 'use precompiled headers' turn that option off and it shoudl compile fine

  15. #30
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It seems the inital understanding was wrong, but it's not the fault of precompiled headers.
    The OP fixed that before.
    It was an astray define, it seems.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 12-16-2008, 02:43 PM
  2. File creation date (in windows 98 and XP)
    By esbo in forum C Programming
    Replies: 12
    Last Post: 05-03-2006, 05:27 PM
  3. program not working...please look at this
    By JOlszewski in forum C Programming
    Replies: 3
    Last Post: 01-30-2006, 10:33 PM
  4. Dynamic Creation of an object
    By axr0284 in forum Windows Programming
    Replies: 3
    Last Post: 02-05-2005, 10:27 AM
  5. Newton + Einstein were wrong!
    By Jez in forum A Brief History of Cprogramming.com
    Replies: 64
    Last Post: 12-14-2004, 02:24 PM