Я использую макрос WMI здесь https://nsis.sourceforge.io/WMI_Macro (я изменил некоторые места для себя), чтобы прочитать информацию о графических процессорах на ноутбуках.
На ноутбуке, у которого нет дискретного графического процессоракарта, код работает очень хорошо.
Unicode true
RequestExecutionLevel user
!include 'LogicLib.nsh'
!include 'TextFunc.nsh'
!include 'x64.nsh'
!include 'WinVer.nsh'
Var /GLOBAL Var_GPU
/* Macro to remove leading and trailing white spaces from a string.
https://nsis.sourceforge.io/WMI_Macro
Derived from the function originally posted by Iceman_K at:
http://nsis.sourceforge.net/Remove_leading_and_trailing_whitespaces_from_a_string
--------------------------------------------------------------------------------- */
!ifmacrondef _Trim
!macro _Trim _UserVar _OriginalString
!define Trim_UID ${__LINE__}
Push $R1
Push $R2
Push `${_OriginalString}`
Pop $R1
Loop_${Trim_UID}:
StrCpy $R2 "$R1" 1
StrCmp "$R2" " " TrimLeft_${Trim_UID}
StrCmp "$R2" "$\r" TrimLeft_${Trim_UID}
StrCmp "$R2" "$\n" TrimLeft_${Trim_UID}
StrCmp "$R2" "$\t" TrimLeft_${Trim_UID}
GoTo Loop2_${Trim_UID}
TrimLeft_${Trim_UID}:
StrCpy $R1 "$R1" "" 1
Goto Loop_${Trim_UID}
Loop2_${Trim_UID}:
StrCpy $R2 "$R1" 1 -1
StrCmp "$R2" " " TrimRight_${Trim_UID}
StrCmp "$R2" "$\r" TrimRight_${Trim_UID}
StrCmp "$R2" "$\n" TrimRight_${Trim_UID}
StrCmp "$R2" "$\t" TrimRight_${Trim_UID}
GoTo Done_${Trim_UID}
TrimRight_${Trim_UID}:
StrCpy $R1 "$R1" -1
Goto Loop2_${Trim_UID}
Done_${Trim_UID}:
Pop $R2
Exch $R1
Pop ${_UserVar}
!undef Trim_UID
!macroend
!ifndef Trim
!define Trim `!insertmacro _Trim`
!endif
!endif
/* RunWMIC - Retrieves a single property value from a WMI Class
https://nsis.sourceforge.io/WMI_Macro
--------------------------------------------------------- */
!ifmacrondef _RunWMIC
!macro _RunWMIC _USERVAR _NAMESPACE _CLASSNAME _PROPERTY
!define WMIC_UID ${__LINE__}
ClearErrors
Push $0
Push $1
Push $2
Push ${_USERVAR}
Pop $0 ; _USERVAR
Push ${_CLASSNAME}
Pop $1 ; _CLASSNAME
Push ${_PROPERTY}
Pop $2 ; _PROPERTY
DOS::ExecToStack /OEM 'wmic /namespace:\\${_NAMESPACE} path $1 get $2 /format:textvaluelist.xsl'
Pop $0
StrCmp $0 0 0 Else_${WMIC_UID}
Pop $0
${Trim} $0 $0
StrLen $1 $2
IntOp $1 $1 + 1
StrCpy $0 $0 ${NSIS_MAX_STRLEN} $1
Goto End_${WMIC_UID}
Else_${WMIC_UID}:
SetErrors
StrCpy $0 ''
End_${WMIC_UID}:
Pop $2
Pop $1
Exch $0
Pop ${_USERVAR}
!undef WMIC_UID
!macroend
!ifndef RunWMIC
!define RunWMIC '!insertmacro _RunWMIC'
!endif
!endif
Section
SetDetailsView show
${RunWMIC} $R1 'root\CIMV2' 'Win32_VideoController' 'Caption'
${RunWMIC} $R2 'root\CIMV2' 'Win32_VideoController' 'CurrentHorizontalResolution'
${RunWMIC} $R3 'root\CIMV2' 'Win32_VideoController' 'CurrentVerticalResolution'
StrCpy $Var_GPU '$R1 ($R2x$R3)'
DetailPrint '----------------GPU(s)----------------'
DetailPrint '$Var_GPU'
SectionEnd
Но если на ноутбуке более 1 GPU, результат не такой, как ожидалось.
На DetailPrint:
----------------GPU(s)----------------
Intel(R) UHD Graphics 620
Caption=NVIDIA GeForce MX130 (1920
CurrentHorizontalResolution=x1080
CurrentVerticalResolution=)
Как исправить?.