Bitness from NppExec



  • Is there a way to determine the bitness (32 or 64) of Notepad++ from the NppExec plugin? I can get the N++ version:

    NPP_SENDMSG NPPM_GETNPPVERSION
    SET nppmajver ~ int($(MSG_RESULT)/65536)
    SET nppminver ~ $(MSG_RESULT)%65536
    echo $(nppmajver).$(nppminver)
    

    But wondering if there’s a way to determine 32 or 64 bit? Obviously getting the bitness of the NppExec plugin itself would work. I was trying a clever math thing with INT but not working.

    Any insights?



  • @Michael-Vincent

    If a 32 bit process runs on a 64 bit OS it has a slightly different set of environment variables than a 64 bit process, they differ e.g. in the value of the ProgramFiles(x86) environment variable.

    For a 32 bit process on a 64 bit OS its value is the same like the value of the ProgramFiles variable. For a 64 bit process the values of these variables are different. And for a 32 bit process on a 32 bit OS there is no ProgramFiles(x86) variable.

    Thus, the detection path would be:

    1. Check if there is ProgramFiles(x86) variable : No -> 32 bit, finish
    2. Check if ProgramFiles(x86) is equal to ProgramFiles : Yes -> 32 bit, No -> 64 bit

    Unfortunately it is not possible to use NppExec’s $(SYS.ProgramFiles(x86)) because the parser is not able to deal with the paranthesis in the variable name (testet with NppExec v0.6 RC2). But there is a workaround: parsing the output of the console’s SET command.

    Test the following NppExec script:

    npe_console -- m-
    npp_console disable
    
    npe_console -- v+
    cmd.exe /c "for /f "tokens=1* delims==" %a in ('set ProgramFiles^(x86^) 2^>NUL') do @echo %b"
    set local $(CallResult) = $(OUTPUT)
    npe_console -- v-
    
    if "$(CallResult)" == "" then
      set local $(Bitness) = 32
    else
      if "$(CallResult)" == "$(SYS.ProgramFiles)" then
        set local $(Bitness) = 32
      else
        set local $(Bitness) = 64
      endif
    endif
    
    npp_console enable
    echo $(Bitness)
    


  • @dinkumoil : Works great!


Log in to reply