【已解决】脚本中只要包含#include <lsasecur.au3>就会未响应
本帖最后由 zqjares 于 2016-11-23 13:36 编辑#include <Constants.au3>
#include <lsasecur.au3>
Opt("MustDeclareVars",1)
Local $isadmin
$isadmin = _SeIsUserAdminEx(@UserName)
If $isadmin = TRUE Then
Run(@ComSpec & ' /c netsh -c interface ip set address "本地连接" dhcp')
Else
MsgBox(0,"123","没有权限")
EndIf如上图的脚本,只是简单的判断本机用户有无管理员权限,要用到<lsasecur.au3>,但是一运行就会未响应,如图
这是论坛里面有人发出来的用来检测电脑是否有管理员权限的 可以搜索到他的帖子:http://www.autoitx.com/forum.php?mod=viewthread&tid=20442&highlight=lsasecur.au3 没有#include <lsasecur.au3>,谁也看不出问题 回复 2# chzj589
添加了附件了,麻烦帮忙看看 谢谢 将“lsasecur.au3”文件和脚本放同目录试试!
#include <Constants.au3>
#include 'lsasecur.au3'
Opt("MustDeclareVars", 1)
Local $isadmin
$isadmin = _SeIsUserAdminEx(@UserName)
If $isadmin = True Then
Run(@ComSpec & ' /c netsh -c interface ip set address "本地连接" dhcp')
Else
MsgBox(0, "123", "没有权限")
EndIf 回复 4# 水木子
依然是APPCRASH 故障模块 ntdll.dll
你那边运行不会报错吗? 回复 4# 水木子
我把lsasecur.au3里面用来判断管理员权限的那几段抽取出来新建了一个les.au3,然后用你的方法试了一下,就没有报错了 回复 4# 水木子
我把lsasecur.au3里面用来判断管理员权限的那几段抽取出来新建了一个les.au3,然后用你的方法试了一下,就没有报错了#include-once
; #### Flags for _SeGetWellKnownAccountSid ####
; ============================================================================================================
Const $SE_WELLKNOWN_ADMIN = -1
Const $SE_WELLKNOWN_GUEST = -2
Const $SE_WELLKNOWN_POWER_USERS = -3
Const $SE_WELLKNOWN_USERS = -4
Const $SE_WELLKNOWN_ADMINS = -5
Const $SE_WELLKNOWN_GUESTS = -6
; ============================================================================================================
; #### Flags for SE_EXPLICIT_ACCESS.AccessMode ####
; ============================================================================================================
Const $SE_INVALID_ACCESS = 0
Const $SE_GRANT_ACCESS = 1
Const $SE_SET_ACCESS = 2
Const $SE_DENY_ACCESS = 3
Const $SE_REVOKE_ACCESS = 4
Const $SE_AUDIT_SUCCESS = 5
Const $SE_AUDIT_FAILURE = 6
; ============================================================================================================
; #### Maximum SID size ####
; ============================================================================================================
Const $SE_MAX_SID_SIZE = 68
; ============================================================================================================
; #### NT Well-Known Authorities ####
; ============================================================================================================
Const $SE_SECURITY_DIALUP_RID = 0x00000001
Const $SE_SECURITY_NETWORK_RID = 0x00000002
Const $SE_SECURITY_BATCH_RID = 0x00000003
Const $SE_SECURITY_INTERACTIVE_RID = 0x00000004
Const $SE_SECURITY_SERVICE_RID = 0x00000006
Const $SE_SECURITY_ANONYMOUS_LOGON_RID = 0x00000007
Const $SE_SECURITY_PROXY_RID = 0x00000008
Const $SE_SECURITY_SERVER_LOGON_RID = 0x00000009
Const $SE_SECURITY_LOGON_IDS_RID = 0x00000005
Const $SE_SECURITY_LOGON_IDS_RID_COUNT = 3
Const $SE_SECURITY_LOCAL_SYSTEM_RID = 0x00000012
Const $SE_SECURITY_NT_NON_UNIQUE = 0x00000015
Const $SE_SECURITY_BUILTIN_DOMAIN_RID = 0x00000020
; ============================================================================================================
; #### Relative Ids ####
; ============================================================================================================
Const $SE_DOMAIN_USER_RID_ADMIN = 0x000001F4
Const $SE_DOMAIN_USER_RID_GUEST = 0x000001F5
Const $SE_DOMAIN_GROUP_RID_ADMINS = 0x00000200
Const $SE_DOMAIN_GROUP_RID_USERS = 0x00000201
Const $SE_DOMAIN_GROUP_RID_GUESTS = 0x00000202
Const $SE_DOMAIN_ALIAS_RID_ADMINS = 0x00000220
Const $SE_DOMAIN_ALIAS_RID_USERS = 0x00000221
Const $SE_DOMAIN_ALIAS_RID_GUESTS = 0x00000222
Const $SE_DOMAIN_ALIAS_RID_POWER_USERS = 0x00000223
Const $SE_DOMAIN_ALIAS_RID_ACCOUNT_OPS = 0x00000224
Const $SE_DOMAIN_ALIAS_RID_SYSTEM_OPS = 0x00000225
Const $SE_DOMAIN_ALIAS_RID_PRINT_OPS = 0x00000226
Const $SE_DOMAIN_ALIAS_RID_BACKUP_OPS = 0x00000227
Const $SE_DOMAIN_ALIAS_RID_REPLICATOR = 0x00000228
; ============================================================================================================
; #### Lsasecur's structures definition ####
; ============================================================================================================
Const $tagSE_BUFFERW = "word Length;word MaxLength;ptr BufferW"
Const $tagSE_SID_ATTRIBUTES = "ptr Sid;dword Attributes"
Const $tagSE_LUID_ATTRIBUTES = "int64 Luid;dword Attributes"
Const $tagSE_PRIV_SET = "dword Count;dword Control;" & $tagSE_LUID_ATTRIBUTES
Const $tagSE_ACCESS_HEADER = "byte AceType;byte AceFlags;word AceSize"
Const $tagSE_ACCESS_ACE = $tagSE_ACCESS_HEADER & ";ptr AccessMask;dword SidStart"
Const $tagSE_TRUSTEE = "ptr MultiTrustee;dword MultiTrusteeOperation;dword TrusteeFrom;dword TrusteeType;ptr Name"
Const $tagSE_EXPLICIT_ACCESS = "ptr AccessMask;dword AccessMode;dword Inheritance;" & $tagSE_TRUSTEE
Const $tagSE_ACCESS_CONTROL_LIST = "word Revision;word AclSize;dword AceCount;" & $tagSE_ACCESS_ACE
Const $tagSE_ABSOLUTE_DESCRIPTOR = "word Revision;word ControlFlags;ptr Owner;ptr Group;ptr Sacl;ptr Dacl"
Const $tagSE_SELF_RELATIVE_DESCRIPTOR = "word Revision;word ControlFlags;dword Owner;dword Group;dword Sacl;dword Dacl"
Const $tagSE_GENERIC_MAPPING = "dword GenericRead;dword GenericWrite;dword GenericExecute;dword GenericAll"
Const $tagSE_TOKEN_STATISTICS = "int64 TokenId;int64 AuthenticationId;int64 ExpirationTime;long TokenType;long ImpersonationLevel;dword DynamicCharged;dword DynamicAvailable;dword GroupCount;dword PrivilegeCount;int64 ModifiedId"
Const $tagSE_PROCESS_INFO = "handle Process;handle Thread;dword ProcessId;dword ThreadId"
Const $tagSE_STARTUP_INFO = "dword Length;ptr Reserved;ptr Desktop;ptr Title;dword X;dword Y;dword XSize;dword YSize;dword XCountChars;dword YCountChars;dword FillAttributes;dword Flags;word ShowWindow;word Reserved2;ptr Reserved3;handle StdInput;handle StdOuput;handle StdError"
Const $tagSE_TREE_RESET_SECUR = "ptr Object;long ObjType;long SecurInfo;ptr Owner;ptr Group;ptr Dacl;ptr Sacl;bool KeepExplicit;ptr CallBack;ulong Invoke;ptr Context;wchar wzObject"
Const $tagSE_MEMORY_NOTIFY = "ptr BaseAddress;dword Length;ptr CallBack;dword Equaled;hWnd Reserved"
Const $tagSE_SECURITY_QOS = "dword Length;dword ImpersonationLevel;bool ContextTrackingMode;boolean EffectiveOnly"
Const $tagSE_SECUR_ATTRIB = "dword Length;handle RootDir;ptr BufferW;ulong Attributes;ptr Securitydescriptor;ptr SecurityQos"
; ============================================================================================================
; #### Flags for SE_TRUSTEE.TrusteeFrom ####
; ============================================================================================================
Const $SE_TRUSTEE_IS_SID = 0
Const $SE_TRUSTEE_IS_NAME = 1
Const $SE_TRUSTEE_IS_BAD = 2
Const $SE_TRUSTEE_IS_OBJS_AND_SID = 3
Const $SE_TRUSTEE_IS_OBJS_AND_NAME = 4
; ============================================================================================================
; #### Handle to Heap ####
; ============================================================================================================
Const $SE_PROCESSHEAP = _SeProcessHeap()
; ============================================================================================================
Func _SeIsUserAdminEx($sUserName = @UserName)
Local $pDacl, $pSid, $iAccessRights
Local $aAceList = []
$pSid = _SeLookupAccountName($sUserName)
$pDacl = _SeSetEntriesInAcl($aAceList)
$iAccessRights = _SeGetEffectiveRightsFromAcl($pDacl, $pSid)
Return SetError(@error, _SeLocalFree($pDacl), _SeHeapFree($pSid) * 0 + $iAccessRights)
EndFunc ;==>_SeIsUserAdminEx
Func _SeLookupAccountName($sUserName = @UserName, $sSystem = "")
Local $iResult, $pBuffer = _SeHeapAlloc($SE_MAX_SID_SIZE * 2)
$iResult = DllCall("Advapi32.dll", "bool", "LookupAccountName", "str", $sSystem, _
"str", $sUserName, "ptr", $pBuffer, "dword*", $SE_MAX_SID_SIZE, _
"ptr", $pBuffer + $SE_MAX_SID_SIZE, "dword*", $SE_MAX_SID_SIZE, "long*", 0)
If ($iResult) Then
Return SetError(0, $iResult, $pBuffer)
Else
Return SetError(_SeLastError(), _SeHeapFree($pBuffer) * 0 + $iResult, 0)
EndIf
EndFunc ;==>_SeLookupAccountName
Func _SeSetEntriesInAcl(ByRef $aEntry, $pExistingAcl = 0)
Local $iUBound, $pBuffer, $iResult
$iUBound = UBound($aEntry)
$pBuffer = _SeInitExplicitEntries($aEntry, $iUBound)
If ($pBuffer = 0) Then Return SetError(@error, 0, 0)
$iResult = DllCall("AdvApi32.dll", "dword", "SetEntriesInAcl", "ulong", $iUBound, _
"ptr", $pBuffer, "ptr", $pExistingAcl, "ptr*", 0)
If ($iResult) Then
Return SetError($iResult, _SeHeapFree($pBuffer), 0)
Else
Return SetExtended(_SeHeapFree($pBuffer), $iResult)
EndIf
EndFunc ;==>_SeSetEntriesInAcl
Func _SeGetWellKnownAccountSid($iWellKnown)
Local $pSid
Switch $iWellKnown
Case $SE_WELLKNOWN_ADMIN, $SE_WELLKNOWN_GUEST
#CS
Local $aUser, $aRid =
$aUser = _SeEnumLocalUsers($SE_FILTER_NORMAL_ACCOUNT)
For $i = 1 To $aUser
If $aUser[$i] = $aRid Then
$pSid = _SeLookupAccountName($aUser[$i])
Return SetError(@error, 0, $pSid)
EndIf
Next
Return 0
#CE
Local $pDomainSid = _SeLookupAccountName(@ComputerName, @ComputerName)
$pSid = _SeCreateWellKnownSid(37 + Abs($iWellKnown), $pDomainSid)
SetError(@error, _SeHeapFree($pDomainSid))
Case $SE_WELLKNOWN_POWER_USERS
$pSid = _SeAllocAndInitSid(5, $SE_SECURITY_BUILTIN_DOMAIN_RID, $SE_DOMAIN_ALIAS_RID_POWER_USERS)
Case $SE_WELLKNOWN_USERS
$pSid = _SeAllocAndInitSid(5, $SE_SECURITY_BUILTIN_DOMAIN_RID, $SE_DOMAIN_ALIAS_RID_USERS)
Case $SE_WELLKNOWN_ADMINS
$pSid = _SeAllocAndInitSid(5, $SE_SECURITY_BUILTIN_DOMAIN_RID, $SE_DOMAIN_ALIAS_RID_ADMINS)
Case $SE_WELLKNOWN_GUESTS
$pSid = _SeAllocAndInitSid(5, $SE_SECURITY_BUILTIN_DOMAIN_RID, $SE_DOMAIN_ALIAS_RID_GUESTS)
Case Else
$pSid = _SeCreateWellKnownSid($iWellKnown)
EndSwitch
Return SetError(@error, 0, $pSid)
EndFunc ;==>_SeGetWellKnownAccountSid
Func _SeGetEffectiveRightsFromAcl($pDacl, $pSid)
#CS
If Not _SeIsValidSid($pSid) Then
Return SetError(@error, 0, 0)
EndIf
#CE
Local $tBuffer, $pBuffer, $iResult
$tBuffer = DllStructCreate($tagSE_TRUSTEE)
$pBuffer = DllStructGetPtr($tBuffer)
DllStructSetData($tBuffer, "Name", $pSid)
DllStructSetData($tBuffer, "TruesteeFrom", $SE_TRUSTEE_IS_SID)
$iResult = DllCall("AdvApi32.dll", "dword", "GetEffectiveRightsFromAcl", _
"ptr", $pDacl, "ptr", $pBuffer, "dword*", 0)
Return SetError($iResult, 0, $iResult)
EndFunc ;==>_SeGetEffectiveRightsFromAcl
Func _SeLocalFree($pBuffer)
Local $iResult = DllCall("Kernel32.dll", "ptr", "LocalFree", "ptr", $pBuffer)
Return SetError(_SeLastError(), 0, $iResult)
EndFunc ;==>_SeLocalFree
Func _SeHeapFree($pBuffer, $iError = @error, $iExtended = @extended)
If $pBuffer < 1 Then Return SetError($iError, $iExtended, 0)
Local $iResult
$iResult = DllCall("Kernel32.dll", "bool", "HeapFree", "handle", $SE_PROCESSHEAP, _
"int", 0, "ptr", $pBuffer)
Return SetError($iError, $iExtended, $iResult)
EndFunc ;==>_SeHeapFree
Func _SeProcessHeap()
Local $iResult = DllCall("Kernel32.dll", "handle", "GetProcessHeap")
Return $iResult
EndFunc ;==>_SeProcessHeap
Func _SeHeapAlloc($iBytesToAlloc = 8)
If ($iBytesToAlloc < 1) Then Return 0
Local $iResult
$iResult = DllCall("Kernel32.dll", "ptr", "HeapAlloc", "handle", $SE_PROCESSHEAP, _
"int", 8, "int", $iBytesToAlloc)
Return SetExtended($iBytesToAlloc, $iResult)
EndFunc ;==>_SeHeapAlloc
Func _SeLastError()
Local $iResult = DllCall("Kernel32.dll", "long", "GetLastError")
Return $iResult
EndFunc ;==>_SeLastError
Func _SeInitExplicitEntries($aEntry, $iUBound)
If UBound($aEntry, 0) <> 2 Then Return SetError(87, 0, 0)
If UBound($aEntry, 2) <> 4 Then Return SetError(87, 0, 0)
Local $pBuffer, $tBuffer
$pBuffer = _SeHeapAlloc($iUBound * 32)
For $i = 0 To $iUBound - 1
If Not _SeIsValidSid($aEntry[$i]) Then
Return SetError(@error, _SeHeapFree($pBuffer), 0)
EndIf
$tBuffer = DllStructCreate($tagSE_EXPLICIT_ACCESS, $pBuffer + ($i * 32))
DllStructSetData($tBuffer, "AccessMask", $aEntry[$i])
DllStructSetData($tBuffer, "AccessMode", $aEntry[$i])
DllStructSetData($tBuffer, "Inheritance", $aEntry[$i])
DllStructSetData($tBuffer, "TrusteeFrom", $SE_TRUSTEE_IS_SID)
DllStructSetData($tBuffer, "Name", $aEntry[$i])
$tBuffer = 0
Next
Return $pBuffer
EndFunc ;==>_SeInitExplicitEntries
Func _SeCreateWellKnownSid($iWellKnown, $pDomainSid = 0)
Local $iResult, $pSid = _SeHeapAlloc($SE_MAX_SID_SIZE)
$iResult = DllCall("AdvApi32.dll", "bool", "CreateWellKnownSid", "long", $iWellKnown, _
"ptr", $pDomainSid, "ptr", $pSid, "dword*", $SE_MAX_SID_SIZE)
If ($iResult) Then
Return SetError(0, $iResult, $pSid)
Else
Return SetError(_SeLastError(), _SeHeapFree($pSid) * 0, 0)
EndIf
EndFunc ;==>_SeCreateWellKnownSid
Func _SeAllocAndInitSid($iAuthorityId, $iAuth0, $iAuth1 = 0, $iAuth2 = 0, $iAuth3 = 0, _
$iAuth4 = 0, $iAuth5 = 0, $iAuth6 = 0, $iAuth7 = 0)
Local $pAuthority, $iResult
$pAuthority = _SeHeapAlloc(6)
_SeWriteBytes($pAuthority + 5, $iAuthorityId, "byte", 1)
$iResult = DllCall("AdvApi32.dll", "bool", "AllocateAndInitializeSid", "ptr", $pAuthority, _
"byte", @NumParams - 1, "dword", $iAuth0, "dword", $iAuth1, "dword", $iAuth2, _
"dword", $iAuth3, "dword", $iAuth4, "dword", $iAuth5, "dword", $iAuth6, _
"dword", $iAuth7, "ptr*", 0)
Return SetError(_SeLastError(), _SeHeapFree($pAuthority), $iResult)
EndFunc ;==>_SeAllocAndInitSid
Func _SeIsValidSid($pSid)
Local $iResult = DllCall("AdvApi32.dll", "bool", "IsValidSid", "ptr", $pSid)
If $iResult Then
Return 1
Else
Return SetError(1337, 0, 0)
EndIf
EndFunc ;==>_SeIsValidSid
Func _SeWriteBytes($pBuffer, $vData, $sType = "dword", $iBytesToWrite = 4)
Local $fResult
If ($sType <> "str") And ($sType <> "wstr") Then $sType &= "*"
$fResult = _SeWriteProcessMemory(-1, $pBuffer, $vData, $iBytesToWrite, $sType)
Return SetError(@error, @extended, $fResult)
EndFunc ;==>_SeWriteBytes
Func _SeWriteProcessMemory($hProcess, $pBaseAddress, $pBuffer, $iSize, $sBufferType = "ptr")
Switch $sBufferType
Case "binary", "binary*"
$sBufferType = "ptr"
Local $tBuffer = DllStructCreate("ubyte Binary[" & $iSize & "]")
DllStructSetData($tBuffer, "Binary", $pBuffer)
$pBuffer = DllStructGetPtr($tBuffer)
Case "str", "char"
$iSize += 1
Case "wstr", "wchar"
$iSize += 2
EndSwitch
Local $iResult
$iResult = DllCall("Kernel32.dll", "bool", "WriteProcessMemory", "handle", $hProcess, _
"ptr", $pBaseAddress, $sBufferType, $pBuffer, "dword", $iSize, _
"dword*", 0)
If ($sBufferType = "binary") Or ($sBufferType = "binary*") Then $tBuffer = 0
If (@error) Then
Return SetError(87, 0, 0)
Else
Return SetError(_SeLastError(), $iResult, $iResult)
EndIf
EndFunc ;==>_SeWriteProcessMemory 代码第一行添加:#pre_usex64=n 试试 回复 8# haijie1223
卧槽,神了,这一行啥意思 回复 9# zqjares
你的是64位系统,取消64位模式 回复 8# haijie1223
#AutoIt3Wrapper_UseX64 #pre_usex64 这两种是一样的么? 回复 11# 1361739590
应该是一样的 谢谢分享学习了
页:
[1]