因为服务程序不依赖桌面的,其实ExitWindowsEx(EWX_LOGOFF¦EWX_FORCEIFHUNG,0)函数就是等于注销,所以在服务程序里没有用的

解决方案 »

  1.   

    I agree the Up and up!!NetApi!!!
      

  2.   

    服务中要用到USER32.DLL 或者GDI32.DLL 的API,必须获得window station 和 desktop,代码如下,我已试过,没问题。
    DWORD dwGuiThreadId = 0; int CNTService::MyExitWindow() 

        DWORD dwThreadId; 
        HWINSTA hwinstaSave; 
        HDESK hdeskSave; 
        HWINSTA hwinstaUser; 
        HDESK hdeskUser; 
        int result;     GetDesktopWindow(); 
        hwinstaSave = GetProcessWindowStation(); 
        dwThreadId = GetCurrentThreadId(); 
        hdeskSave = GetThreadDesktop(dwThreadId);     hwinstaUser = OpenWindowStation(lpszWindowStation, FALSE, MAXIMUM_ALLOWED); 
        if(hwinstaUser == NULL){ 
            return 0; 
        } 
        SetProcessWindowStation(hwinstaUser); 
        hdeskUser = OpenDesktop(lpszDesktop, 0, FALSE, MAXIMUM_ALLOWED); 
        if (hdeskUser == NULL){ 
            SetProcessWindowStation(hwinstaSave); 
            CloseWindowStation(hwinstaUser); 
            return 0; 
        } 
        SetThreadDesktop(hdeskUser);     dwGuiThreadId = dwThreadId; 
        //在此加入你的代码
        ExitWindowsEx(EWX_LOGOFF¦EWX_FORCEIFHUNG,0)
        dwGuiThreadId = 0;     SetThreadDesktop(hdeskSave); 
        SetProcessWindowStation(hwinstaSave); 
        CloseDesktop(hdeskUser); 
        CloseWindowStation(hwinstaUser);     return 1; 

      
      

  3.   

    Leehunter大侠呀,非常感谢,不过还有一点不清楚请指教
    OpenDesktop和OpenWindowStation的第一个参数应该给什么
    还有就是,你有没有试过ExitWindowsEx(EWX_POWEROFF,0)
    这个不知道会不会成功
        
      

  4.   

    不好意思,
    OpenWindowStation的第一个参数为:"WinSta0"
    OpenDesktop的第一个参数为:"Default"
    另一种方法我没试过,你自己试试吧!:=)