Note that StartTrace can fail using ERROR_ALREADY_EXISTS, after which if you need to change session properties, you will want to use ControlTrace. Also note that you need to run your program "as an administrator" if you have UAC enabled; and that if you are debugging, you will also need to start Visual Studio "as an administrator." Your program should also have its own manifest (if you have one) set as "Administrator" for privileges.
If you're browsing the MSDN for OpenTrace, ProcessTrace, and StartTrace, you'll find links to various examples that will give you what you want.
brian
source share