zoukankan      html  css  js  c++  java
  • window/mac系统关机

    window/mac系统关机

    #ifdef Q_OS_WIN    
    #include “windows.h”
    #endif
    
    void OnShutDown()
    {
    #ifdef Q_OS_WIN
        HANDLE hToken;
        TOKEN_PRIVILEGES tkp;
    
        //get process flags
        if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
        {
            //"Failed to shutdown:-----get process flags!-----";
            return;
        }        
    
        //get shutdown privilege LUID
        LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
        tkp.PrivilegeCount = 1;
        tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    
        //gets the shutdown privilege for this process
        AdjustTokenPrivileges(hToken, false, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
        if (GetLastError() != ERROR_SUCCESS)
        {
             //"Failed to shutdown:-----gets the shutdown privilege for this process!-----";
            return;
        }
    
        //force shutdown
        if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
        {
            //"Failed to shutdown:-----force shutdown!-----";
            return;
        }
        return;
    
    #else
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
        
        NSDictionary *errorDict = nil;
        NSAppleEventDescriptor *returnDescriptor = nil;
        
        NSAppleScript *scriptObject = [[NSAppleScript alloc] initWithSource:
                        @"tell application "Finder" to shut down"];
          returnDescriptor = [scriptObject executeAndReturnError:&errorDict];    
        if (nil == returnDescriptor)
        {
            //"Failed to shutdown:-----no script result, handle error here-----"; 
        }
        
        [scriptObject release];
        scriptObject = nil;
        
        [pool drain];
        return;
    #endif
    }
  • 相关阅读:
    c# 深拷贝与浅拷贝
    SQLServer性能优化 .net开发菜鸟总结
    Ajax自定义无刷新控件实现
    APScheduler库的详细用法
    catkin在centos中的安装
    第五次任务实现与项目总结第六组
    Javascript教程:获取当前地址栏url
    窗口处理问题
    HTML中area标签
    Asp.net中Frameset的使用小结
  • 原文地址:https://www.cnblogs.com/sz-leez/p/5947145.html
Copyright © 2011-2022 走看看