NSIS打包+管理员权限+多用户安装

本文介绍了一种在NSIS中实现用户权限检查的方法,并提供了一个示例函数IsUserAdmin,该函数通过调用UserInfo.dll插件来判断当前用户是否为管理员。此外,还讨论了在不同Windows版本下权限检查的表现差异及如何设置快捷方式的相关问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


  
; Author: Lilla (lilla@earthlink.net) 2003 - 06 - 13
; function IsUserAdmin uses plugin \NSIS\PlusgIns\UserInfo.dll
; This function
is based upon code in \NSIS\Contrib\UserInfo\UserInfo.nsi
; This function was tested under NSIS
2 beta 4 (latest CVS as of this writing).
;
; 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

;获取管理员权限
RequestExecutionLevel none|user|highest|admin
;多用户安装
;使用SetShellVarContext all 将快捷方式创建到alluser的开始菜单中
SetShellVarContext all

NSIS 打包

NSIS 打包 win7 中无法删除快捷方式

转载于:https://www.cnblogs.com/08shiyan/archive/2011/05/10/2042099.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值