| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1333 人关注过本帖
标题:NSIS,判断安装包是否管理员身份运行的代码
只看楼主 加入收藏
wsgsoft
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2019-12-9
收藏
 问题点数:0 回复次数:0 
NSIS,判断安装包是否管理员身份运行的代码
本篇文章属于《518超市播音软件开发日志》系列文章的一部分。
我在开发《518超市播音软件》(http://www.)的时候,用的NSIS打包制作安装包,安装的时候,需要确保是管理员权限的,不是的话,就提示需要管理员权限运行,然后退出。

Function un.onInit
  Call un.IsUserAdmin
  Pop $R0
  ${If} $R0 == "false"
    MessageBox MB_ICONEXCLAMATION|MB_OK|MB_TOPMOST|MB_SETFOREGROUND "需以管理员身份运行          $\n"
    Quit
  ${EndIf}



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Usage:
;   Call IsUserAdmin
;   Pop $R0   ; at this point $R0 is "true" or "false"
;
Function IsUserAdmin
Push $R0
Push $R1
Push $R2

ClearErrors
UserInfo::GetName
IfErrors Win9x
Pop $R1
UserInfo::GetAccountType
Pop $R2

StrCmp $R2 "Admin" 0 Continue
; Observation: I get here when running Win98SE. (Lilla)
; The functions UserInfo.dll looks for are there on Win98 too,
; but just don't work. So UserInfo.dll, knowing that admin isn't required
; on Win98, returns admin anyway. (per kichik)
; MessageBox MB_OK 'User "$R1" is in the Administrators group'
StrCpy $R0 "true"
Goto Done

Continue:
; You should still check for an empty string because the functions
; UserInfo.dll looks for may not be present on Windows 95. (per kichik)
StrCmp $R2 "" Win9x
StrCpy $R0 "false"
;MessageBox MB_OK 'User "$R1" is in the "$R2" group'
Goto Done

Win9x:
; comment/message below is by UserInfo.nsi author:
; This one means you don't need to care about admin or
; not admin because Windows 9x doesn't either
;MessageBox MB_OK "Error! This DLL can't run under Windows 9x!"
StrCpy $R0 "true"

Done:
;MessageBox MB_OK 'User= "$R1"  AccountType= "$R2"  IsUserAdmin= "$R0"'

Pop $R2
Pop $R1
Exch $R0
FunctionEnd
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
搜索更多相关主题的帖子: 安装 管理员 MessageBox admin 运行 
2021-04-24 19:01
快速回复:NSIS,判断安装包是否管理员身份运行的代码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017380 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved