SERVICE_TABLE_ENTRY ServiceTable[2];
ServiceTable[0].lpServiceName = _T("MyService");
ServiceTable[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION)ServiceMain;在ServiceMain函数中调用WTSQueryUserToken(dwSessionId, &hToken)时,报错ERROR_NO_TOKEN 1008.
sessionid 的值已经成功获取,
根据msdn的说法,The token query is for a session in which no user is logged-on. This occurs, for example, when the session is in the idle state. 
服务程序是开机即启动的,用的admin账户登录,为何会报这样的错呢?

解决方案 »

  1.   

        WTSGETACTIVECONSOLESESSIONID lpfnWTSGetActiveConsoleSessionId = (WTSGETACTIVECONSOLESESSIONID)GetProcAddress(hmod,"WTSGetActiveConsoleSessionId"); 
        DWORD dwSessionId = lpfnWTSGetActiveConsoleSessionId();
    这样得到的 值看过了 是1
      

  2.   

    ServiceMain ?
    你服务启动的时候,应该还没到你登录呢。除非你的服务是手动启动。
      

  3.   

    好久没来,忘记要结贴,sorry!
    原来要输入用户名和密码登录后 调用WTSQueryUserToken才不会出错,还是谢谢大家了!