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
    }
  • 相关阅读:
    PHP基本语法
    SQL-还原数据库,数据库提示正在还原中的处理办法
    MyBatis学习笔记
    Java byte数据转换和处理总结
    JS和JQUERY的区别
    .NET 之 ORM 性能评测
    你必须知道的 SmartSql !
    SmartSql 介绍
    SmartSql 入门
    SmartCode.ETL 这不是先有鸡还是蛋的问题!
  • 原文地址:https://www.cnblogs.com/sz-leez/p/5947145.html
Copyright © 2011-2022 走看看