• 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
    }
  • 相关阅读:
    Git 基础笔记整理1
    学习开源中国客户端
    IOS项目中的细节处理,如更改状态栏等等
    网络编程
    当FileWriter没有flush的时候,不写入文件
    批量移动文件
    批量重命名文件
    替换一个文件内的某个字符
    遍历map和删除map中的一个entry
    ArrayList的遍历-转载
  • 原文地址:https://www.cnblogs.com/sz-leez/p/5947145.html
Copyright © 2020-2023  润新知