Jump to content

Remote Information (Help please) - (Moved)


Willazuie
 Share

Recommended Posts

Good night Guys, how are you?
I'm new here in the Forum and in the Autoit language, I tried to learn some things on my own and I even managed to, but as a work with T.I, I'm trying to develop a little program
which fetches information from other remote computers.
However, I'm trying to get information, but I can't send the computer name when I press the button for the command $ objWMIService = ObjGet ("winmgmts: \\" & $ strComputer & "\ root \ CIMV2").

 

 

#Include <Constants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>


exemplo()
Func exemplo()
    Local $Form1   = GUICreate("", 360, 190, 192, 124)
    Local $strComputer = GUICtrlCreateLabel("Enter the IP or Hostname", 10, 10, 140, 100)
    Local $infsn = GUICtrlCreateLabel("The Model you computer is: ", 10, 31, 140,100)
    Local $inserir = GUICtrlCreateInput("the IP or Hostname", 200, 10, 150, 20, 0x00020000)
    Local $result = GUICtrlCreateInput("Result", 200, 31, 150, 20, 0x00020000)
    Local $botao = GUICtrlCreateButton("Send", 200, 100, -1, -1)


    GUISetState(@SW_SHOW)

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_Process")
For $objItem in $colItems
     $model=$objItem.Model
Next

While 1
$saida = GUIGetMsg()
Switch $saida
    Case $GUI_EVENT_CLOSE  ;$botao_1, $botao_2
        ExitLoop

    Case $botao
         $inserir = $model
        GUICtrlSetData($result, $inserir)
EndSwitch

WEnd
EndFunc

Erro_Autoit.JPG

Link to comment
Share on other sites

38 minutes ago, Willazuie said:

Good night Guys, how are you?

I'm blind from looking at those huge letters ;)

but seriously.....

:welcome: to AutoIt forum.

Please edit your post accordingly to this How to post scriptsource   Forum etiquette  Forum Rules 
And please do not use such big letters  in more than 2 words.

Good night Guys, how are you?

because it looks like you're yelling at people.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

  • Moderators

Moved to the appropriate forum.

Moderation Team

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

The problem is in the line

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")

$strComputer is defined, and is returning the handle of the Label. 

But you want to read and insert the text from the $inserir

do something like this:

Local $ip=GuiCtrlRead($inserir)
$objWMIService = ObjGet("winmgmts:\\" & $ip & "\root\cimv2")

 

Some of my script sourcecode

Link to comment
Share on other sites

15 hours ago, mLipok said:

Estou cego de olhar para aquelas letras enormes ;)

mas seriamente.....

:bem-vinda: para o fórum AutoIt.

Por favor, edite sua postagem de acordo com este  Como postar scriptsource    Regras de etiqueta do fórum   
E por favor, não use letras tão grandes em mais de 2 palavras.


Boa noite galera tudo bem

porque parece que você está gritando com as pessoas.

Sorry for the letters being large, I used google to translate and copied the font.

Link to comment
Share on other sites

  • Developers

Just paste without formatting and PLEASE do not post the translated reply like in the last post! ;) 

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

11 hours ago, Dan_555 said:

O problema está na linha

$ objWMIService  =  ObjGet ( "winmgmts: \\"  &  $ strComputer  &  "\ root \ cimv2" )

$ strComputer está definido e está retornando o identificador do Label. 

Mas você deseja ler e inserir o texto do $ inserir

faça algo assim:

Local  $ ip = GuiCtrlRead ( $ inserir ) 
$ objWMIService  =  ObjGet ( "winmgmts: \\"  &  $ ip  &  "\ root \ cimv2" )

 

Thanks for your help, I tried to use what you told me, but something I'm doing is still not making the code work, it could help me with that code.
Thank you again.

Link to comment
Share on other sites

There are a few major issues with your script:

  1. On 9/19/2020 at 10:16 PM, Willazuie said:

    $strComputer = GUICtrlCreateLabel("Enter the IP or Hostname", 10, 10, 140, 100)

    As @Dan_555 said, GUICtrlCreateLabel returns a control ID, not the value of the control. GuiCtrlRead() returns the value of a input control.

  2. On 9/19/2020 at 10:16 PM, Willazuie said:

    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
    $colItems = $objWMIService.ExecQuery("Select * from Win32_Process")
    For $objItem in $colItems
         $model=$objItem.Model
    Next

    The Win32_Process class returns process information not computer system information.  Also, "model" is not a valid property of Win32_Process.  The Win32_ComputerSystem class has a "Model" property.  I think that is what you may have been wanting to use.

  3. Your script only attempts to execute the retrieval of the model once, right after showing the form.  If you want to be able to get the model each time you hit the send button, then that logic needs to be called or executed when you receive the message that button has been pressed.  I have suggested putting it a function so that you can easily reuse the function in other scripts.  However, you could have also put the logic in the message loop where the button message is processed.

 

Here is a reworked, over-simplified, well-documented example with error-checking for you to compare & contrast:

#AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d

#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

Global $Form1    = GUICreate("", 360, 150, 192, 124)
Global $lblHost  = GUICtrlCreateLabel("Enter the IP or Hostname", 10, 10, 140, 100)
Global $inpHost  = GUICtrlCreateInput("the IP or Hostname", 200, 10, 150, 20, 0x00020000)
Global $lblModel = GUICtrlCreateLabel("The Model you computer is: ", 10, 31, 140,100)
Global $inpModel = GUICtrlCreateInput("Result", 200, 31, 150, 20, 0x00020000)
Global $btnSend  = GUICtrlCreateButton("Send", 200, 60, -1, -1, $BS_DEFPUSHBUTTON)

example()
Func example()

    Local $sHost = "", $sModel = ""

    ;Initialize host field with the current computer name
    GUICtrlSetData($inpHost, @ComputerName)

    ;Show form and process messages
    GUISetState(@SW_SHOW, $Form1)
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $btnSend
                ;Get model and update form field
                $sHost  = GUICtrlRead($inpHost)
                $sModel = get_computer_model($sHost)
                GUICtrlSetData($inpModel, $sModel)
        EndSwitch
    WEnd

EndFunc

Func get_computer_model($sHost = @ComputerName)

    Local $oWmi, $oCollection

    ObjEvent("AutoIt.Error", com_error_handler)

    ;Create WMI object
    $oWmi = ObjGet("winmgmts:\\" & $sHost & "\root\cimv2")
    If Not IsObj($oWmi) Then
        MsgBox($MB_ICONERROR, "ERROR", "Error creating WMI object for " & $sHost)
        Return ""
    EndIf

    ;Get computer info instance
    $oCollection = $oWmi.ExecQuery("SELECT model FROM Win32_ComputerSystem")
    If Not IsObj($oCollection) Then
        MsgBox($MB_ICONERROR, "ERROR", "Error retrieving computer information.")
        Return ""
    EndIf

    ;Return model
    Return $oCollection.ItemIndex(0).Model ;Only 1 instance so no need for ForNext.

EndFunc

Func com_error_handler($oComErr)
    Local $sErrMsg

    With $oComErr
        $sErrMsg =  @CRLF
        $sErrMsg &= ">>>  COM ERROR  <<<" & @CRLF
        $sErrMsg &= StringFormat("Script Line Number : %s", .ScriptLine) & @CRLF
        $sErrMsg &= StringFormat("HRESULT            : 0x%x (%s)", .Number, .Number) & @CRLF
        $sErrMsg &= StringFormat("Windows Error      : %s", StringStripWS(.WinDescription, $STR_STRIPTRAILING)) & @CRLF
        $sErrMsg &= StringFormat("Object Description : %s", StringStripWS(.Description, $STR_STRIPTRAILING)) & @CRLF
        ConsoleWrite($sErrMsg)
    EndWith

    Exit
EndFunc

 

Edited by TheXman
Fixed typos and tweaked example script
Link to comment
Share on other sites

On 9/20/2020 at 11:29 PM, TheXman said:

There are a few major issues with your script:

  1. As @Dan_555 said, GUICtrlCreateLabel returns a control ID, not the value of the control. GuiCtrlRead() returns the value of a input control.

  2. The Win32_Process class returns process information not computer system information.  Also, "model" is not a valid property of Win32_Process.  The Win32_ComputerSystem class has a "Model" property.  I think that is what you may have been wanting to use.

  3. Your script only attempts to execute the retrieval of the model once, right after showing the form.  If you want to be able to get the model each time you hit the send button, then that logic needs to be called or executed when you receive the message that button has been pressed.  I have suggested putting it a function so that you can easily reuse the function in other scripts.  However, you could have also put the logic in the message loop where the button message is processed.

 

Here is a reworked, over-simplified, well-documented example with error-checking for you to compare & contrast:

#AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d

#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

Global $Form1    = GUICreate("", 360, 150, 192, 124)
Global $lblHost  = GUICtrlCreateLabel("Enter the IP or Hostname", 10, 10, 140, 100)
Global $inpHost  = GUICtrlCreateInput("the IP or Hostname", 200, 10, 150, 20, 0x00020000)
Global $lblModel = GUICtrlCreateLabel("The Model you computer is: ", 10, 31, 140,100)
Global $inpModel = GUICtrlCreateInput("Result", 200, 31, 150, 20, 0x00020000)
Global $btnSend  = GUICtrlCreateButton("Send", 200, 60, -1, -1, $BS_DEFPUSHBUTTON)

example()
Func example()

    Local $sHost = "", $sModel = ""

    ;Initialize host field with the current computer name
    GUICtrlSetData($inpHost, @ComputerName)

    ;Show form and process messages
    GUISetState(@SW_SHOW, $Form1)
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $btnSend
                ;Get model and update form field
                $sHost  = GUICtrlRead($inpHost)
                $sModel = get_computer_model($sHost)
                GUICtrlSetData($inpModel, $sModel)
        EndSwitch
    WEnd

EndFunc

Func get_computer_model($sHost = @ComputerName)

    Local $oWmi, $oCollection

    ObjEvent("AutoIt.Error", com_error_handler)

    ;Create WMI object
    $oWmi = ObjGet("winmgmts:\\" & $sHost & "\root\cimv2")
    If Not IsObj($oWmi) Then
        MsgBox($MB_ICONERROR, "ERROR", "Error creating WMI object for " & $sHost)
        Return ""
    EndIf

    ;Get computer info instance
    $oCollection = $oWmi.ExecQuery("SELECT model FROM Win32_ComputerSystem")
    If Not IsObj($oCollection) Then
        MsgBox($MB_ICONERROR, "ERROR", "Error retrieving computer information.")
        Return ""
    EndIf

    ;Return model
    Return $oCollection.ItemIndex(0).Model ;Only 1 instance so no need for ForNext.

EndFunc

Func com_error_handler($oComErr)
    Local $sErrMsg

    With $oComErr
        $sErrMsg =  @CRLF
        $sErrMsg &= ">>>  COM ERROR  <<<" & @CRLF
        $sErrMsg &= StringFormat("Script Line Number : %s", .ScriptLine) & @CRLF
        $sErrMsg &= StringFormat("HRESULT            : 0x%x (%s)", .Number, .Number) & @CRLF
        $sErrMsg &= StringFormat("Windows Error      : %s", StringStripWS(.WinDescription, $STR_STRIPTRAILING)) & @CRLF
        $sErrMsg &= StringFormat("Object Description : %s", StringStripWS(.Description, $STR_STRIPTRAILING)) & @CRLF
        ConsoleWrite($sErrMsg)
    EndWith

    Exit
EndFunc

 

Mr. TheXman,I thank you for all your attention and for helping me with this code that is in perfect formatting and orientation.I will study over this code to have more knowledge on the subject.Thank you for your time in helping me and everyone here who guided me with my problem.
Link to comment
Share on other sites

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...