Jump to content

Recommended Posts

Posted

I would like to ask how I can rewrite this PS to AutoIT so it will still be a WmiObject.

 

 Write-Host "Model-" (Get-WmiObject -Namespace "root\SMS\site_PEN" -ComputerName "ServerName" -Class SMS_G_System_COMPUTER_SYSTEM -Filter "Name='$computer'").Model

 

Yours sincerely

Kenneth.

Posted

Or search the example scripts forum for "Scriptomatic". This generates AutoIt-code to query WMI.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

Yes, thank you I manage to figure it out. :)

 

I do have a small question in this matter. I have the code below and it do work until I'm trying to fetch the MAC address, then it will not. I'm not sure why, but I think metadata is an array, but I can't get the job done to show it. Do I do something wrong?

If GUICtrlRead($idListBox) <> $sLastSel Then
        $sLastSel = GUICtrlRead($idListBox)
        ; Wait to see if there is a double click
        Sleep(150)
        If $fAction = 1 Then
            if FileExists(@WindowsDir & "\system32\msra.exe") Then
                Run(@ComSpec & ' /c ' & 'msra /offerra ' & GUICtrlRead($idListBox) ,"", @SW_HIDE)
            Else
                MsgBox(0, "", "You can't remote!")
            EndIf
            $fAction = 0
        Else
            Local $ComputerName = GUICtrlRead($idListBox)
            Local $iPing = Ping($ComputerName,250)
            If $iPing Then ; If a value greater than 0 was returned then display the following message.
                _GUICtrlStatusBar_SetText($g_hStatus, "Online")
                _GUICtrlStatusBar_SetIcon($g_hStatus, 0, _WinAPI_LoadShell32Icon($ahIcons[2]))
                $sQuery = "SELECT * FROM SMS_G_System_COMPUTER_SYSTEM Where Name='" & $ComputerName & "'"
                $oComputers = $oConnectSrv.ExecQuery($sQuery)
                For $oComputer In $oComputers
                    GUICtrlSetData($ComputerModel,"")
                    GUICtrlSetData($ComputerModel,$oComputer.Model)
                    $sQuery = "SELECT * FROM SMS_G_System_PC_BIOS Where RESOURCEID='" & $oComputer.ResourceId & "'"
                    $oBIOSs = $oConnectSrv.ExecQuery($sQuery)
                    For $oBIOS In $oBIOSs
                        GUICtrlSetData($SN,"")
                        GUICtrlSetData($SN,$oBIOS.SerialNumber)
                        GUICtrlSetData($BIOS,"")
                        GUICtrlSetData($BIOS,$oBIOS.SMBIOSBIOSVersion)
                    Next
                    $sQuery = "SELECT * FROM SMS_R_System Where RESOURCEID='" & $oComputer.ResourceId & "'"
                    $oRSystems = $oConnectSrv.ExecQuery($sQuery)
                    For $oRSystem In $oRSystems
                        _ArrayDisplay($oRSystems,"")
                        MsgBox(32, "", "Computer Name: " & $oComputer.Name & @CRLF & "ResourceId: " & $oRSystem.MACAddresses)
                        GUICtrlSetData($MAC,"")
                        GUICtrlSetData($MAC,$oRSystem.MACAddresses)
                        GUICtrlSetData($OWNER,"")
                        GUICtrlSetData($OWNER,$oRSystem.managedBy)
                    Next
                Next
;               MsgBox(32, "", "Computer Name: " & $oComputer.Name & @CRLF & "ResourceId: " & $oComputer.ResourceId & @CRLF & "Model: " & $oComputer.Model)
            Else
                _GUICtrlStatusBar_SetText($g_hStatus, "Offline")
;               $ahIcons[1] = _WinAPI_LoadShell32Icon($ahIcons[1])
                _GUICtrlStatusBar_SetIcon($g_hStatus, 0, _WinAPI_LoadShell32Icon($ahIcons[1]))
            EndIf
        EndIf
        $fAction = 0
    Else

 

Yours sincerely

Kenneth.

Posted

I get the below error:

 

"C:\Users\Documents\AutoIT\Projekt\Alfalaval\Test Apps\FindComputer.au3" (158) : ==> Expected a variable in user function call.:
MsgBox(32, "", "Computer Name: " & $oComputer.Name & @CRLF & "ResourceId: " & _ArrayToString($oRSystem.MACAddresses))
MsgBox(32, "", "Computer Name: " & $oComputer.Name & @CRLF & "ResourceId: " & _ArrayToString(^ ERROR

 

Yours sincerely

Kenneth.

Posted
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=FindComputer.Exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListBox.au3>
#include <ScreenCapture.au3>
#include <GuiStatusBar.au3>
#include <AD.au3>
#include <ListBoxConstants.au3>
#include <StructureConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

$cEnterPressed = GUICtrlCreateDummy()
Global $hGUI, $hBitmap, $hBitmap_Scaled, $hGraphics, $sUserName
Global $aAccelKeys[1][2] = [["{ENTER}", $cEnterPressed]];x <<<<<<<<<<<<<<<<<<<<<<<<< accelerator  ON
GUISetAccelerators($aAccelKeys);x

_GDIPlus_Startup()
Local Const $iWidth = 300, $iHeight = 305, $aParts[3] = [75, 185, -1], $iBgColor = 0xFFE8FF, $ahIcons[3] = [109,131,144] ;$iBgColor format RRGGBB
Local Const $sServerName = "760", $sSiteCode = "SiteCode"
Local $oSWBEMLoc = ObjCreate("WbemScripting.SWbemLocator")
Local $oConnectSrv = $oSWBEMLoc.ConnectServer($sServerName, "root\SMS\site_" & $sSiteCode)
$hGUI = GUICreate("GDI+ test", $iWidth, $iHeight, -1, -1) ;create a test gui to display the resized image
;GUISetBkColor($iBgColor, $hGUI) ;set GUI background color
GUICtrlCreateLabel("Enter shortname of user:",110, 5)
$idShortName = GUICtrlCreateInput("", 110, 20, 185, 20) ; First
GUICtrlCreateLabel("Name:",110, 42)
$idName = GUICtrlCreateInput("", 110, 55, 185, 20) ; First
GUICtrlSetState($idName,$gui_disable)
GUICtrlCreateLabel("Email:",110, 80)
$idEmail = GUICtrlCreateInput("", 110, 93, 185, 20) ; First
GUICtrlSetState($idEmail,$gui_disable)
GUICtrlCreateLabel("Manager:",110, 115)
$idManager = GUICtrlCreateInput("", 110, 130, 185, 20) ; First
GUICtrlSetState($idManager,$gui_disable)

GUICtrlCreateLabel("MODEL:",110, 160)
$ComputerModel = GUICtrlCreateLabel("",160, 160, 100,40)

GUICtrlCreateLabel("S/N:",110, 180)
$SN = GUICtrlCreateLabel("",160, 180,100,40)

GUICtrlCreateLabel("BIOS:",110, 200)
$BIOS = GUICtrlCreateLabel("",160, 200,100,40)

GUICtrlCreateLabel("MAC:",110, 220)
$MAC = GUICtrlCreateLabel("",160, 220,100,40)

GUICtrlCreateLabel("OWNER:",110, 240)
$OWNER = GUICtrlCreateLabel("",160, 240,100,40)

$idListBox = GUICtrlCreateList("", 4, 155, 101, 125)
$hWndListBox = GUICtrlGetHandle($idListBox)

$g_hStatus = _GUICtrlStatusBar_Create($hGUI)
;_GUICtrlStatusBar_SetParts($g_hStatus, 75,150,-1)
_GUICtrlStatusBar_SetParts($g_hStatus, $aParts)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

GUISetState(@SW_SHOW)

$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
Local $hPen = _GDIPlus_PenCreate()
_GDIPlus_GraphicsDrawRect($hGraphics, 4, 4, 100, 145)
Local $hBrush = _GDIPlus_BrushCreateSolid(0xFFF0F0F0);0xFFEE88BB
_GDIPlus_GraphicsFillRect($hGraphics, 5, 5, 99, 144, $hBrush)
$hBrush = _GDIPlus_BrushCreateSolid(0x7F00007F)
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$hFont = _GDIPlus_FontCreate($hFamily, 12, 2)
$tLayout = _GDIPlus_RectFCreate(15, 70, 100, 20)
_GDIPlus_GraphicsDrawStringEx($hGraphics, "No Image", $hFont, $tLayout, $hFormat, $hBrush)
;$tLayout = _GDIPlus_RectFCreate(110, 170, 200, 20)
;_GDIPlus_GraphicsDrawStringEx($hGraphics, "Model:", $hFont, $tLayout, $hFormat, $hBrush)

_AD_Open()
$fAction = 0
$sLastSel = ""
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $idShortName  ; Dummy
;           $sUserName = GUICtrlRead ( $idShortName )
            Local $sSamAccountNameToFQDN = _AD_SamAccountNameToFQDN(GUICtrlRead ( $idShortName ))
            Local $aResult = _AD_GetObjectAttribute($sSamAccountNameToFQDN, 'thumbnailPhoto')
            If @error Then
                Local $hBrush = _GDIPlus_BrushCreateSolid(0xFFF0F0F0);0xFFEE88BB
                _GDIPlus_GraphicsFillRect($hGraphics, 5, 5, 99, 144, $hBrush)
                $hBrush = _GDIPlus_BrushCreateSolid(0x7F00007F)
                $hFormat = _GDIPlus_StringFormatCreate()
                $hFamily = _GDIPlus_FontFamilyCreate("Arial")
                $hFont = _GDIPlus_FontCreate($hFamily, 12, 2)
                $tLayout = _GDIPlus_RectFCreate(15, 70, 100, 20)
                _GDIPlus_GraphicsDrawStringEx($hGraphics, "No Image", $hFont, $tLayout, $hFormat, $hBrush)
            Else
;               $hBitmap = _GDIPlus_BitmapCreateFromMemory(_AD_GetObjectAttribute(GUICtrlRead ( $idShortName ), 'thumbnailPhoto')) ;load binary saved GIF image and convert it to GDI+ bitmap format
                $hBitmap = _GDIPlus_BitmapCreateFromMemory($aResult) ;load binary saved GIF image and convert it to GDI+ bitmap format
                $hBitmap_Scaled = _GDIPlus_ImageResize($hBitmap, 99, 144) ;resize image
                _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap_Scaled, 5, 5) ;display scaled image
            EndIf
            GUICtrlSetData($idName,_AD_GetObjectAttribute($sSamAccountNameToFQDN, 'cn'))
            GUICtrlSetData($idEmail,_AD_GetObjectAttribute($sSamAccountNameToFQDN, 'mail'))
            local $sManager = _AD_GetObjectAttribute($sSamAccountNameToFQDN, 'manager')
            GUICtrlSetData($idManager,StringMid($sManager,4,StringInStr($sManager,',')-4))
            Local $aComputerOwner = _AD_GetObjectsInOU("OU=Company,DC=AD,DC=Company,DC=ORG","(&(objectclass=computer)(managedby=" & $sSamAccountNameToFQDN & "))",Default,"cn")
;           _ArrayDisplay($aComputerOwner, $sSamAccountNameToFQDN)
            GUICtrlSetData($SN,"")
            GUICtrlSetData($BIOS,"")
            GUICtrlSetData($ComputerModel,"")
            GUICtrlSetData($MAC,"")
            GUICtrlSetData($OWNER,"")
            If IsArray($aComputerOwner) Then
                GUICtrlSetData($idListBox, "")
                For $x = 1 to UBound($aComputerOwner)-1
                    GUICtrlSetData($idListBox, $aComputerOwner[$x])
                Next
            EndIf
    EndSwitch

    If GUICtrlRead($idListBox) <> $sLastSel Then
        $sLastSel = GUICtrlRead($idListBox)
        ; Wait to see if there is a double click
        Sleep(150)
        If $fAction = 1 Then
            if FileExists(@WindowsDir & "\system32\msra.exe") Then
                Run(@ComSpec & ' /c ' & 'msra /offerra ' & GUICtrlRead($idListBox) ,"", @SW_HIDE)
            Else
                MsgBox(0, "", "You can't remote!")
            EndIf
            $fAction = 0
        Else
            Local $ComputerName = GUICtrlRead($idListBox)
            Local $iPing = Ping($ComputerName,250)
            If $iPing Then ; If a value greater than 0 was returned then display the following message.
                _GUICtrlStatusBar_SetText($g_hStatus, "Online")
                _GUICtrlStatusBar_SetIcon($g_hStatus, 0, _WinAPI_LoadShell32Icon($ahIcons[2]))
                $sQuery = "SELECT * FROM SMS_G_System_COMPUTER_SYSTEM Where Name='" & $ComputerName & "'"
                $oComputers = $oConnectSrv.ExecQuery($sQuery)
                For $oComputer In $oComputers
                    GUICtrlSetData($ComputerModel,"")
                    GUICtrlSetData($ComputerModel,$oComputer.Model)
                    $sQuery = "SELECT * FROM SMS_G_System_PC_BIOS Where RESOURCEID='" & $oComputer.ResourceId & "'"
                    $oBIOSs = $oConnectSrv.ExecQuery($sQuery)
                    For $oBIOS In $oBIOSs
                        GUICtrlSetData($SN,"")
                        GUICtrlSetData($SN,$oBIOS.SerialNumber)
                        GUICtrlSetData($BIOS,"")
                        GUICtrlSetData($BIOS,$oBIOS.SMBIOSBIOSVersion)
                    Next
                    $sQuery = "SELECT * FROM SMS_R_System Where RESOURCEID='" & $oComputer.ResourceId & "'"
                    $oRSystems = $oConnectSrv.ExecQuery($sQuery)
                    For $oRSystem In $oRSystems
                        _ArrayDisplay($oRSystems,"")
                        MsgBox(32, "", "Computer Name: " & $oComputer.Name & @CRLF & "ResourceId: " & _ArrayToString($oRSystem.MACAddresses))
;                       GUICtrlSetData($MAC,"")
;                       GUICtrlSetData($MAC,_ArrayToString ($oRSystem.MACAddresses))
                        GUICtrlSetData($OWNER,"")
                        GUICtrlSetData($OWNER,$oRSystem.managedBy)
                    Next
                Next
;               MsgBox(32, "", "Computer Name: " & $oComputer.Name & @CRLF & "ResourceId: " & $oComputer.ResourceId & @CRLF & "Model: " & $oComputer.Model)
            Else
                _GUICtrlStatusBar_SetText($g_hStatus, "Offline")
;               $ahIcons[1] = _WinAPI_LoadShell32Icon($ahIcons[1])
                _GUICtrlStatusBar_SetIcon($g_hStatus, 0, _WinAPI_LoadShell32Icon($ahIcons[1]))
            EndIf
        EndIf
        $fAction = 0
    Else
        If $fAction = 1 Then
            if FileExists(@WindowsDir & "\system32\msra.exe") Then
                Run(@ComSpec & ' /c ' & 'msra /offerra ' & GUICtrlRead($idListBox) ,"", @SW_HIDE)
            Else
                MsgBox(0, "", "You can't remote!")
            EndIf
            $fAction = 0
        EndIf
    EndIf
WEnd
_AD_Close()

;cleanup resources
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_BitmapDispose($hBitmap_Scaled)
_GDIPlus_Shutdown()
GUIDelete($hGUI)

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg

    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)

    $hWndFrom = $lParam
    $iCode = BitShift($wParam, 16) ; Hi Word

    Switch $hWndFrom
        Case $hWndListBox
            Switch $iCode
                Case $LBN_DBLCLK ; Sent when the user double-clicks a string in a list box
                    $fAction = 1
            EndSwitch
    EndSwitch
EndFunc

 

Yours sincerely

Kenneth.

Posted

Oh, I forgot about that.  You cannot use directly the object.property directly in _Array* () functions.  You need to use a $aTmp array variable like this :

Local $aTmp = $oRSystem.MACAddresses
GUICtrlSetData($MAC,_ArrayToString ($aTmp))

It should work now 

Posted

I see. Well it is a solution.  You can also use .ItemIndex(n) to access directly one object instead of using For loops.  I don't have those SMS* classes, so I cannot run your script.  Just read about the different methods and properties of WMI classes here.  You can then decide what is best for you.

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
  • Recently Browsing   0 members

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