Simple OU Membership Test

From NSIS Wiki

Author: Zinthose (talk, contrib)


About

This is a very basic OU testing macro intended for use in companies that use nsis to repackage software. This has been successuly tested on Windows XP and Windows XP x64 but should work fine on Windows 2000 and newer.

Example

/*  Don't forget to add these!
    --------------------------
      !include "LogicLib.nsh"
      !include "WordFunc.nsh"
    --------------------------*/
Section IsOUMember_Example
 
    ${If} ${IsOUMember} "Cool People"
        MessageBox MB_OK 'System is in the Cool People OU!'
    ${Else}
        MessageBox MB_OK 'Ah, the system is not cool enough.  Sorry.'
    ${EndIf} 
 
SectionEnd

Macro

/*  IsOUMember LogicLib Extention
    Example:
        ${If} ${IsOUMember} "CAD External"
    ----------------------------------------*/
    !ifmacrondef _IsOUMember
        !macro _IsOUMember _a _b _t _f
            !ifndef LOGICLIB | WORDFUNC_INCLUDED
                !error `The IsOUMember LogicLib extention is missing a required dependancy: WordFunc.nsh | LogicLib.nsh`
            !else
                !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}`
 
                /*  Search the DistinguishedName for the requested OU name.
                    -------------------------------------------------------*/         
                    ClearErrors
                    ${WordFind} $_LOGICLIB_TEMP "OU=${_b}," "E+1{" $_LOGICLIB_TEMP
                    StrCpy $_LOGICLIB_TEMP ''
 
                /*  Depending on  the results jump.
                    -------------------------------*/
                    IfErrors `${_f}`
                    Goto `${_t}`
            !endif
        !macroend
        !ifndef IsOUMember
            !define IsOUMember `"" IsOUMember`
        !endif
    !endif
Personal tools
donate