为所有用户,添加系统启动时高权限启动的进程

第一部分,添加高权限启动的进程
    //  Set up principal information: 
    hr = pPrincipal->put_Id(_bstr_t(L"Principal1"));
    //if (FAILED(hr))
        //DebugPrint(L"\nCannot put the principal ID: %x", hr);

    hr = pPrincipal->put_LogonType(TASK_LOGON_INTERACTIVE_TOKEN);
    //if (FAILED(hr))
        //DebugPrint(L"\nCannot put principal logon type: %x", hr);

    //  Run the task with the least privileges (LUA) 
    hr = pPrincipal->put_RunLevel(TASK_RUNLEVEL_HIGHEST);//以最高权限
    pPrincipal->Release();
    if (FAILED(hr))
    {
        //DebugPrint(L"\nCannot put principal run level: %x", hr);
        pRootFolder->Release();
        pTask->Release();
        //CoUninitialize();
        return false;
    }

 

第二部分,为所有用户添加触发器

        //在触发器集合中创建触发器      
        hr = pTriggerCollection->Create(TASK_TRIGGER_LOGON, &pTrigger); //当用户启动时触发  
        if (FAILED(hr))
        {
            return false;
        }

        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;
        }

        hr = pLogonTrigger->put_Id(_bstr_t(L"Trigger1"));
        if (FAILED(hr))
            printf("\nCannot put the trigger ID: %x", hr);

        //  Set the task to start at a certain time. The time 
        //  format should be YYYY-MM-DDTHH:MM:SS(+-)(timezone).
        //  For example, the start boundary below
        //  is January 1st 2005 at 12:05
        hr = pLogonTrigger->put_StartBoundary(_bstr_t(L"2005-06-16T12:05:00"));
        if (FAILED(hr))
            printf("\nCannot put the start boundary: %x", hr);

        hr = pLogonTrigger->put_EndBoundary(_bstr_t(L"2005-06-16T18:00:00"));
        if (FAILED(hr))
            printf("\nCannot put the end boundary: %x", hr);

        //  Define the user.  The task will execute when the user logs on.
        //  The specified user must be a user on this computer.  
        hr = pLogonTrigger->put_UserId(NULL);
        pLogonTrigger->Release();
        if (FAILED(hr))
        {
            pRootFolder->Release();
            pTask->Release();
            CoUninitialize();
            return 1;
        }
        pTriggerCollection->Release();

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值