ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

NSIS,判断安装包是否管理员身份运行的代码

2021-04-25 09:01:52  阅读:261  来源: 互联网

标签:MessageBox R0 R2 MB admin NSIS 管理员 OK 安装包


本篇文章属于《518超市播音软件开发日志》系列文章的一部分。
我在开发《518超市播音软件》(http://www.518boyin.com/)的时候,用的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,R0,R2,MB,admin,NSIS,管理员,OK,安装包
来源: https://blog.51cto.com/u_14634790/2730024

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有