Simple IsDomainMember Test
From NSIS Wiki
Jump to navigationJump to search
Author: Zinthose (talk, contrib) |
About
This is a very basic domain membership testing macro intended for use in companies that use NSIS to repackage software. This has been successfully tested on Windows XP and Windows XP x64 but should work fine on Windows 2000 and newer.
I also added a precompiler check to automatically add the dependencies if the code is pasted into the global namespace.
Example
/* Don't forget to add these! -------------------------- !include "LogicLib.nsh" !include "StrFunc.nsh" ${StrStr} ${StrRep} --------------------------*/ Section IsDomainMember_Example ${If} ${IsDomainMember} "internal.microsoft.com" MessageBox MB_OK 'This will NEVER run!' ${Else} MessageBox MB_OK 'Hello normal people!' ${EndIf} SectionEnd
Macro
/* IsDomainMember LogicLib Extention Example: ${If} ${IsDomainMember} "internal.mycompany.com" ----------------------------------------*/ !ifmacrondef _IsDomainMember !ifndef LOGICLIB | STRFUNC | StrStr_INCLUDED | StrRep_INCLUDED !ifdef __GLOBAL__ !ifndef LOGICLIB !include "LogicLib.nsh" !endif !ifndef STRFUNC !include "StrFunc.nsh" !endif !ifdef STRFUNC !ifndef StrStr_INCLUDED ${StrStr} !endif !ifndef StrRep_INCLUDED ${StrRep} !endif !endif !else !error `The IsDomainMember LogicLib extention is missing a required dependancy: LogicLib.nsh | StrFunc.nsh [StrStr & StrRep]` !endif !endif !macro _IsDomainMember _a _b _t _f !insertmacro _LOGICLIB_TEMP /* Get the System's Distinguished Name from the registry -----------------------------------------------------*/ SetRegView 64 ClearErrors ReadRegStr $_LOGICLIB_TEMP HKLM `SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine` `Distinguished-Name` SetRegView lastused /* If we were unable to get the Distinguished Name so we'll asume the system is not a member of a domain. --------------------------------------------------------*/ IfErrors `${_f}` /* Parse the DistinguishedName for the system's domain name. -------------------------------------------------------*/ ${StrStr} $_LOGICLIB_TEMP $_LOGICLIB_TEMP "DC=" IfErrors `${_f}` ${StrRep} $_LOGICLIB_TEMP $_LOGICLIB_TEMP ",DC=" "." IfErrors `${_f}` StrCpy $_LOGICLIB_TEMP $_LOGICLIB_TEMP ${NSIS_MAX_STRLEN} 3 IfErrors `${_f}` /* Do we have a match? -------------------------------------------------------*/ !insertmacro _== $_LOGICLIB_TEMP ${_b} `${_t}` `${_f}` !macroend !ifndef IsDomainMember !define IsDomainMember `"" IsDomainMember` !endif !endif