Jump to content

Get information about my computer - (Moved)


Recommended Posts

Hi everyone, I'm not sure I can ask a question on this topic. I really need help to implement another piece in my code to upload a computer configuration report. I no have idea, how can do that....

My code:

#RequireAdmin
#NoTrayIcon
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>
Opt("MustDeclareVars",1)

Global $idComboBox  
Global  $hFile, $sInfo,$idComboBox ,$CopyBtn , $sComboRead, $fFile = @ScriptDir & "\" & "(" & @ComputerName & ")" & ".txt"
$hFile = FileOpen(@ScriptDir & "\" & "(" & @ComputerName & ")" & ".txt", 1)

                    $sInfo &= _InfoPC()
                    $sInfo &= _InfoRAM()
                    FileWrite($hFile, $sInfo)
                    FileClose($hFile)


Func _InfoPC()
    Local $ObjService = ObjGet('winmgmts:{impersonationLevel = impersonate}!\\' & @ComputerName & '\root\cimv2')
    Local $ObjMB = $ObjService.ExecQuery('SELECT * FROM Win32_BaseBoard', 'WQL', 0x30)
    Local $ObjProcessor = $ObjService.ExecQuery('SELECT * FROM Win32_Processor', 'WQL', 0x30)
    Local $ObjMemory = $ObjService.ExecQuery('SELECT * FROM Win32_PhysicalMemory')
    Local $ObjNet = $ObjService.ExecQuery('SELECT * FROM Win32_NetworkAdapter', 'WQL', 0x30)
    Local $ObjGraph = $ObjService.ExecQuery('SELECT * FROM Win32_VideoController', 'WQL', 0x30)
    Local $ObjDrive = $ObjService.ExecQuery('SELECT * FROM Win32_DiskDrive', 'WQL', 0x30)
    Local $ObjCDDrive = $ObjService.ExecQuery('SELECT * FROM Win32_CDROMDrive', 'WQL', 0x30)
    Local $ObjRam = $ObjService.ExecQuery('SELECT * FROM Win32_ComputerSystem')
    Local $ObjModel = $ObjService.ExecQuery('SELECT * FROM Win32_ComputerSystem')
    Local $ObjBIOS = $ObjService.ExecQuery('SELECT * FROM Win32_BIOS')
    Local $sNameComput = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\DataStore\Machine\0', 'szTargetName')
    Local $sProduct = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'ProductName')
    Local $sVersion = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'DisplayVersion')
    Local $sBuild = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'ReleaseId')
    Local $sItemM, $sItemMa, $sInfo = ''& @CRLF & '[Configuration:] (' & @MDAY & "." & @MON & "." & @YEAR & ' - ' & @HOUR & ":" & @MIN & ":" & @SEC & ')' & @CRLF & @TAB & 'Computer Name............' & @ComputerName & @CRLF & @TAB &'Operaton System: ... ' & $sProduct & ' ' & $sVersion & ' ' & $sBuild & ' ' & '(' & @OSArch & ')' & @CRLF
    If IsObj($ObjService) Then
        For $objItemP In $ObjProcessor
            $sInfo &= @TAB & 'Processor: .............. ' & $objItemP.Name & @CRLF
        Next
        For $objItemMB In $ObjMB
            $sInfo &= @TAB & 'Motherboard: ...... ' & $objItemMB.Product & @CRLF
        Next
        For $ObjItemM In $ObjMemory
            $sItemM = $objItemM.Speed
            $sItemMa = $objItemM.Manufacturer
        Next
        For $objItemR In $ObjRam
            $sInfo &= @TAB & 'RAM: .................... ' &  Round($objItemR.TotalPhysicalMemory / 1024 / 1024 ^ 2, 0) & ' GB | ' & $ObjMemory.Count & ' слот | ' & $sItemM & ' Mhz' & @CRLF
        Next
        For $ObjItemG In $ObjGraph
            $sInfo &= @TAB & 'Videocard: ............. ' & $ObjItemG.Name & ' | RAM: ' & $ObjItemG.AdapterRAM / 1024 ^ 2 & ' Mb' & @CRLF
        Next
        For $ObjItemD In $ObjDrive
            $sInfo &= @TAB & 'Hard Drives: ........... ' & $ObjItemD.Model & ' | Объем: ' & Round($ObjItemD.Size / 1024 / 1024 / 1024) & ' Gb | S\N:' & $ObjItemD.SerialNumber & '' & @CRLF
        Next
        For $ObjItemCD In $ObjCDDrive
            $sInfo &= @TAB & 'Дисковод: ............... ' & $ObjItemCD.Name & @CRLF
        Next
        For $ObjItemN In $ObjNet
            If $ObjItemN.PhysicalAdapter = True Then
                $sInfo &= @TAB & 'Network adapters: ........ ' & $ObjItemN.Name & @CRLF
             EndIf
         Next
         For $i = 0 to (ubound($ObjRam)/2)-1
            $sInfo &= @TAB & "1: ........  " & $i+1 & ": 1: " & $ObjRam[(2*$i)] & @CRLF
            $sInfo &= @TAB & "1: ........  " & $i+1 & ": 1: " & $ObjRam[(2*$i)+1] & @CRLF
        
         Next
          For $ObjItemModel In $ObjModel
             $sInfo &= @CRLF &'[Model and serial number:]' & @CRLF  
             $sInfo &= @TAB & 'Model: ............... ' & $ObjItemModel.Model & @CRLF
         Next
         For $ObjItemBIOS In $ObjBIOS  
             $sInfo &= @TAB & 'Serial number: ............... ' & $ObjItemBIOS.SerialNumber & @CRLF
             $sInfo &= @CRLF &'[Monitors:]' & @CRLF
         Next
    EndIf
   
    Local $aDisplayInfo = Display_Info()
    if $aDisplayInfo = "" then
        ConsoleWrite("$aDisplayInfo is not an array" & @crlf)
    Else
        for $i = 0 to (ubound($aDisplayInfo)/2)-1
            $sInfo &= @TAB & "Monitor: ........  " & $i+1 & ": Model: " & $aDisplayInfo[(2*$i)] & " |" & " Serial Number: " & $aDisplayInfo[(2*$i)+1] & @CRLF
        Next
    EndIf
    $sInfo &= @CRLF
    Return $sInfo
EndFunc   ;==>_InfoPC


Func _a()
 Local $sls=ObjGet("winmgmts:{impersonationLevel=impersonate," _
 &"authenticationLevel=Pkt}!\\"& _
 @ComputerName&'\root\wmi'),$lss=$sls.ExecQuery _
 ('SELECT * FROM WmiMonitorID'), _
 $lll,$sll,$sss="",$lsl,$lls,$i,$z
 For $z In $lss
 $lsl=$z.UserFriendlyName
 For $i=0 To Ubound($lsl)-1
 if ($lsl[$i]) Then $lll&=Chr($lsl[$i])
 Next
 $lls=$z.SerialNumberID
 For $i=0 To Ubound($lls)-1
 if ($lls[$i]) Then $sll&=Chr($lls[$i])
 Next
 $sss&="Модель"&@TAB&@TAB&":   "&$lll&@CR&"Serial Number"&@TAB&":   "&$sll&@CR&@CR
 $lll=""
 $sll=""
 Next
 $lss=Null
$sls=Null
 $sInfo &= @CRLF
EndFunc
Func _InfoRAM()
  Local $objWMIService = ObjGet('winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2')
  If Not IsObj($objWMIService) Then Return "Error RAM" & @CRLF
  Local $colItems = $objWMIService.ExecQuery('Select * From Win32_PhysicalMemory')
  Local $i = 0, $infoRAM = "[RAM:]" & @CRLF
  For $ObjItem In $colItems
     $i += 1
    $infoRAM &= @TAB & "Slot " & $i & ": " & $objItem.DeviceLocator & "|" & "Объём: " & $ObjItem.Capacity / 1024^3 & " GB"  & "|" & "Марка: " & $objItem.Manufacturer  & "|" & "Частота: " & $objItem.Speed & "|" & "S/N: " & $objItem.PartNumber & @CRLF
  Next
  Return $infoRAM
EndFunc
Func Display_Info()
    Local $oComErr, $oWmi, $oInstances
    $oComErr = ObjEvent("AutoIt.Error", comm_error_handler)
    #forceref $oComErr
    ;Get WMI object
    $oWmi = ObjGet("winmgmts:\root\WMI")
    If Not IsObj($oWmi) Then Exit MsgBox($MB_ICONERROR, "ERROR", "Unable to create WMI object")
    ;Select object instances
    $oInstances = $oWmi.ExecQuery("SELECT * FROM WMIMonitorID")
    If $oInstances.Count = 0 Then Exit MsgBox($MB_ICONWARNING,"Warning","No objects found")
    ; Changed part
    Local $aReturn[2] ; change number if you want to return more info
    Local $iDisplayCount = 1
    ;Display instance properties
    For $oInstance in $oInstances
        With $oInstance
            ConsoleWrite(@CRLF)
            if ubound($aReturn) < $iDisplayCount * 2 then redim $aReturn[2*$iDisplayCount]
            If IsArray(.UserFriendlyName) Then $aReturn[2*($iDisplayCount-1)] = convert_uint16_array_to_string(.UserFriendlyName) ;StringFormat("UserFriendlyName       = %s", convert_uint16_array_to_string(.UserFriendlyName))
            If IsArray(.SerialNumberId)   Then $aReturn[2*($iDisplayCount-1)+1] = convert_uint16_array_to_string(.SerialNumberId) ;StringFormat("SerialNumberId         = %s", convert_uint16_array_to_string(.SerialNumberId))
            $iDisplayCount += 1
        EndWith
    Next
    Return $aReturn
EndFunc
Func convert_uint16_array_to_string($aBytes)
    Local $s  = ""
    For $i in $aBytes
        If $i <> 0 Then $s &= Chr($i)
    Next
    Return $s
EndFunc
Func comm_error_handler($oComError)
    ConsoleWrite(@CRLF)
    ConsoleWrite(StringFormat("Script Line  = %s", $oComError.ScriptLine) & @CRLF)
    ConsoleWrite(StringFormat("Win Err Desc = %s", StringStripWS($oComError.WinDescription, $STR_STRIPTRAILING)) & @CRLF)
    ConsoleWrite(StringFormat("Error Number = %i (0x%x)", $oComError.Number, $oComError.Number) & @CRLF)
    ConsoleWrite(StringFormat("Error Desc   = %s", $oComError.Description) & @CRLF)
    Exit

 

And a piece of code that I need to shove....

Opt('MustDeclareVars', True)
Local _
  $oWMI,    _ 
  $oPrint,  _ 
  $oItem,   _ 
  $iCount,  _ 
  $vTemp      

$oWMI   = ObjGet('winmgmts:\\.\root\cimv2')
$oPrint = $oWMI.ExecQuery('SELECT * FROM Win32_Printer', 'WQL', 0x30)
$iCount = 0
For $oItem In $oPrint
  $iCount += 1
  $vTemp = StringFormat("Printer #%u = '%s'\n", $iCount, $oItem.Name)
  ConsoleWrite($vTemp)
Next
If ($iCount = 0) Then ConsoleWrite('No printer installed')
Exit

 

Link to comment
Share on other sites

  • Developers

Moved to the appropriate AutoIt General Help and Support forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • 3 weeks later...

Add the required UDF includes at the beginning of your script:
 

#include <Array.au3>
#include <ConsoleConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

insert the following code after the _InfoRAM() function:
 

Func _InfoPrinters()
    Local $oWMI = ObjGet("winmgmts:\\.\root\cimv2")
    Local $oPrint = $oWMI.ExecQuery("SELECT * FROM Win32_Printer", "WQL", 0x30)
    Local $iCount = 0, $vTemp = ""

    For $oItem In $oPrint
        $iCount += 1
        $vTemp &= StringFormat("Printer #%u: %s\n", $iCount, $oItem.Name)
    Next

    If $iCount = 0 Then $vTemp = "No printers installed"
    Return $vTemp
EndFunc

Modify the line where you write the computer configuration report to include the printer information:
 

$sInfo &= _InfoPC()
$sInfo &= _InfoRAM()
$sInfo &= _InfoPrinters()
FileWrite($hFile, $sInfo)
FileClose($hFile)

Place the code snippet you provided after the line where you write the computer configuration report:

 

Opt('MustDeclareVars', True)
Local $oWMI, $oPrint, $oItem, $iCount, $vTemp

$oWMI = ObjGet('winmgmts:\\.\root\cimv2')
$oPrint = $oWMI.ExecQuery('SELECT * FROM Win32_Printer', 'WQL', 0x30)
$iCount = 0

For $oItem In $oPrint
    $iCount += 1
    $vTemp = StringFormat("Printer #%u = '%s'\n", $iCount, $oItem.Name)
    ConsoleWrite($vTemp)
Next

If ($iCount = 0) Then ConsoleWrite('No printer installed')
Exit


With these changes, the computer configuration report will include the printer information retrieved using WMI.

❤️

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...