2

I found a sample code from MSDN which triggers notepad.exe on user logon,

but as i'm trying to compile the program using g++ task.cpp -o task.exe -lole32 -loleaut32 -luuid

in this code block

ILogonTrigger *pLogonTrigger = NULL;       
hr = pTrigger->QueryInterface( 
        IID_ILogonTrigger, (void**) &pLogonTrigger );
pTrigger->Release();
if( FAILED(hr) )
{
    printf("\nQueryInterface call failed for ILogonTrigger: %x", hr );
    pRootFolder->Release();
    pTask->Release();
    CoUninitialize();
    return 1;
}

It says ILogonTrigger and IID_ILogonTrigger is not defined. I checked my header file and tried to swap with the once i got from other compilers, it got even worse. How to code it so that I can get the same user logon trigger ?

The err:

task.cpp:208:5: error: 'ILogonTrigger' was not declared in this scope
  208 |     ILogonTrigger *pLogonTrigger = NULL;
      |     ^~~~~~~~~~~~~
task.cpp:208:20: error: 'pLogonTrigger' was not declared in this scope; did you mean 'pTrigger'?
  208 |     ILogonTrigger *pLogonTrigger = NULL;
      |                    ^~~~~~~~~~~~~
      |                    pTrigger
task.cpp:210:13: error: 'IID_ILogonTrigger' was not declared in this scope; did you mean 'IID_ITaskTrigger'?
  210 |             IID_ILogonTrigger, (void**) &pLogonTrigger );
      |             ^~~~~~~~~~~~~~~~~
      |             IID_ITaskTrigger 

this is my header file if it can help solve the problem.

Ahmed Can Unbay
  • 2,694
  • 2
  • 16
  • 33
  • *"It says"* - What's *"it"*? Your compiler? Your linker? Your IDE? Something else? Please include the unabridged error diagnostics in your question. – IInspectable Feb 09 '21 at 10:15
  • @IInspectable is it okay ? – Ahmed Can Unbay Feb 09 '21 at 11:04
  • See, now it says *"not declared"*, where previously your question read *"not defined"*. That makes a world of a difference. Are you including *taskschd.h*? – IInspectable Feb 09 '21 at 11:09
  • yes i am, i can put my taskschd.h in a link and show you as well, it doesnt have it in there, but it has whole other things which run without a problem. Maybe user logon is modified ? I will update the link then @IInspectable – Ahmed Can Unbay Feb 09 '21 at 11:10
  • Please provide a [mcve] in the question itself. I'm not talking about any random file called *taskschd.h*, I'm talking about the *taskschd.h* file that ships as part of the Windows SDK. – IInspectable Feb 09 '21 at 11:20
  • Your header file does not provide the `ILogonTrigger` interface, make sure that the Windows SDK provided by your system supports this interface: [ILogonTrigger interface](https://learn.microsoft.com/en-us/windows/win32/api/taskschd/nn-taskschd-ilogontrigger) – Zeus Feb 10 '21 at 06:13
  • yes, that is true, i was wondering where to update the SDK or where to download it ? indeed if i run msi of the installer do i have to reinstall my gcc compiler again ? i checked online headers i found but none of them worked, (they were even worse with more errors) do you know how to install it to the system ? @SongZhu-MSFT – Ahmed Can Unbay Feb 10 '21 at 08:00
  • Refer to [Windows 10 SDK](https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk/) and you can also select `Windows 10 SDK (10.0.19041.0)` in the optional components of the Visual Studio 2019 Installer. – Zeus Feb 10 '21 at 08:03
  • sure, amazing. Downloading the installer. As this thread goes on, i will try to end this quick, how do i refer the SDK to the gcc compiler? I dont use msvc, i dont even know thow to like to VS 2019 as well.. And thank you. @SongZhu-MSFT – Ahmed Can Unbay Feb 10 '21 at 08:08
  • Refer to [Can g++ / minGW play nice with the Windows SDK?](https://stackoverflow.com/questions/2022112/can-g-mingw-play-nice-with-the-windows-sdk-is-visual-studio-the-only-option) and [Update WINVER and _WIN32_WINNT](https://learn.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt?view=msvc-160) may help you – Zeus Feb 10 '21 at 08:15

0 Answers0