FMS

error in returning valeus

8 posts in this topic

Hello,

I'm rather new at Autoit (picked it up again afther a couple of years) but i dont know what I'm doing wrong here.
I hope somebody can help me making this script "better readeble" and explain what I'm doing wrong here.
The thing that i want to do here is making a tool that helps me whit doing mine work.
Also want to do the "ping" command in the background whit only a msgbox if ok or not.
In the code I'm writing now I'm using Send commands but know that there is a better way for this.

At this point there is a error also whish i do not udnerstand where it is comming from.
the error i get is:

MsgBox($MB_SYSTEMMODAL, "Error", " Error no IP or name is filled in")
MsgBox(^ ERROR

Could somebody help me whit looking at this code?
 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>


$Form1 = GUICreate("Form1", 385, 112, 192, 124)
$iIP = GUICtrlCreateInput("", 80, 16, 209, 21)
$btn_ping = GUICtrlCreateButton("Ping", 24, 56, 89, 25)
$btn_vnc = GUICtrlCreateButton("VNC", 136, 56, 89, 25)
$btn_evr = GUICtrlCreateButton("Eventvieuwer", 248, 56, 89, 25)
GUISetState(@SW_SHOW)

Func check_input()
   If GUICtrlRead($iIP) = "" Then
        Return False
    Else
        Return True
    Endif
 EndFunc

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $btn_ping
            $check = check_input()
            If ($check = False) Then
               Run ("cmd.exe")
               WinWaitActive("C:\WINDOWS\system32\cmd.exe")
               Send ("ping " & GUICtrlRead($iIP) & "{ENTER}")
               WinClose ("C:\WINDOWS\system32\cmd.exe")
               ;if ping OK then msgbox OK else NOK
            Else
               MsgBox($MB_SYSTEMMODAL, "Error", " Error no IP or name is filled in")
            EndIf
         Case $btn_vnc
            $check = check_input()
            If ($check = False) Then
               Run ("cmd.exe")
               WinWaitActive("C:\WINDOWS\system32\cmd.exe")
               Send ("eventvwr.exe " & GUICtrlRead($iIP) & "{ENTER}")
               WinClose ("C:\WINDOWS\system32\cmd.exe")
            Else
               MsgBox($MB_SYSTEMMODAL, "Error", " Error no IP or name is filled in")
            EndIf
         Case $btn_evr
            $check = check_input()
            If ($check = False) Then
               Run ("cmd.exe")
               WinWaitActive("C:\WINDOWS\system32\cmd.exe")
               Send ("vncviewer " & GUICtrlRead($iIP) & "{ENTER}")
               WinClose ("C:\WINDOWS\system32\cmd.exe")
            Else
               MsgBox($MB_SYSTEMMODAL, "Error", " Error no IP or name is filled in")
            EndIf
    EndSwitch
 WEnd

 


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites



You need to add

#include <MsgBoxConstants.au3>

at the top of your script.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

thanks - added :)
Do you also know how to ping in the background and iff result is good a massagebox apears?

thanks in advanced


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

AutoIt offers a Ping function. So there is no need to run CMD.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

thanks this helps a lot...
The thing is :
the ping command is very usefull for the 1st button.
for the other buttons (VNC and eventviewer) I want to run like a batch script and I only know to do it whit "in screen"  commands like "Send" ,
Could u help me whit this? :

VNC button:

set /p ipadres=Wwhat is the IP of machine?
:LOOP
ping %ipadres% -w 1 > nul
IF ERRORLEVEL 1 GOTO :DEAD
IF ERRORLEVEL 0 GOTO :ALIVE
:DEAD
Echo Time-Out on %ipadres%...
GOTO :LOOP
:ALIVE
ECHO The machine is online and VNC wil be started
cd\
cd "C:\Program Files\Realvnc\vnc4"
vncviewer %ipadres%

cls

 

EVENTVIEWER button:

set /p ipadres=What is the IP of the machine?
net use z: /DELETE /Y
net use z: \\%ipadres%\C$ /user:username password
CLS
ECHO Event Viewer will be started...
c:\WINDOWS\system32\eventvwr.exe %ipadres%
CLS
ECHO Event Viewer wordt gestart...
ping -n 20 127.0.0.1 > nul
net use z: /DELETE /Y

 


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

Should be quite easy:

$sIP = InputBox("Prompt", "What is the IP of the machine?")
If Ping($sIP) > 0 Then
    Run("C:\Program Files\Realvnc\vnc4\vncviewer.exe " & $sIP)
Else
    MsgBox($MB_ICONERROR, "Error", $sIP & " is dead. @error = " & @error)
EndIf

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

who knows,....
this will make mine code a lot simpler and shorter!
Many thanks :)


as finishing touch god created the dutch

Share this post


Link to post
Share on other sites

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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

  • Similar Content

    • hcI
      By hcI
      Hello I would like to know if there is a way to return a sentence in cmd when I launch from it (because I add arguments).
      For example, diskpart.exe which help to manage the key and hdd connected, when you launch it with the parameter "/f" the app return a sentence saying that it don't recognize the parameter "/f" and it return the sentence in the cmd where i started the application, not a new one.
      That's what I want to do but I couldn't find anything that would solve my problem on internet and on AutoIt like ConsoleWrite / ConsoleWriteError (don't work).
       
      Thanks
    • Duck
      By Duck
      I'm attempting to capture the output from the command line tool PSEXEC. I'm using AutoIT to run an instance of PSEXEC against a remote PC to audit Local Admins in my environment using net.exe (C:\Windows\System32> net localgroup administrators). However the usual trick I use to capture command line output does not appear to work well with PSEXEC, as the bottom portion of the output is missing from the return. Any ideas or recommendations are greatly appreciated.  
       
      Here is what I'm working with: 
      ;This script will read from a list of hosts and report who has local admin privileges on the machine #RequireAdmin Global $fileName = @ScriptDir & '\test.txt' ;hostlist, one host per line readHostList() ;Read list of hosts Func readHostList() Local $file = FileOpen($fileName, 0) While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop ConsoleWrite($line & @CRLF) ;MsgBox(0,0,$line) getLocalAdmins($line) WEnd FileClose($file) EndFunc ;run PSEXEC to list local admins Func getLocalAdmins($remotePC) Local $testFile = @ScriptDir &'\test234.txt' FileOpen($testFile, 1) Local $psexec = 'psexec \\' & $remotePC & ' net localgroup administrators' FileWriteLine($testFile, _RunCmd($psexec) ) FileClose($testFile) EndFunc ;Used to return CLI output Func _RunCmd($sCommand) Local $nPid = Run(@Comspec & " /c" & $sCommand, @SystemDir, @SW_Hide, 8), $sRet = "" If @Error then Return "ERROR:" & @ERROR ProcessWait($nPid) While 1 $sRet &= StdoutRead($nPID) If @error Or (Not ProcessExists ($nPid)) Then ExitLoop WEnd Return $sRet EndFunc  
      ## If i manually run the command on the remote PC via PSEXEC I will get the following output: 
      PsExec v2.11 - Execute processes remotely
      Copyright (C) 2001-2014 Mark Russinovich
      Sysinternals - www.sysinternals.com
      Starting net on PCNAME... on PCNAME...
      net exited on PCNAME with error code 0.
      -------------------------------------------------------------------------------
      admin
      Administrator
      Alias name     administrators
      Domain\Domain Admins
      Comment        Administrators have complete and unrestricted access to the computer/domain
      Members
      The command completed successfully.
       
      ## The returned output from running the above script is as follows:
      PsExec v2.11 - Execute processes remotely
      Copyright (C) 2001-2014 Mark Russinovich
      Sysinternals - www.sysinternals.com
      Alias name     administrators
      Connecting to PCNAME...
      Starting PSEXESVC service on PCNAME...
      Connecting with PsExec service on PCName...
      Starting net on PCNAME..
      net exited on PCNAME with error code 0.
       
      **Note to test this script PSEXEC must be in the system dir or the path in the script changed 
      PSEXEC tool: https://docs.microsoft.com/en-us/sysinternals/downloads/psexec
    • Nareshm
      By Nareshm
      I have autoit script like this :
      winActivate ("BillReceipt") ControlClick ( "BillReceipt", "", "[NAME:winviewer]", "right") Send ( "{ENTER}") WinWait ("Print") ControlClick ("Print", "", "[CLASS:Button; INSTANCE:13]") Winwait ("Save As") WinActivate ("Save As") Send ("{TAB 5} {Backspace} ^v {Enter}") I need Saved successfully msgbox with file name as i saved like Filename.extension (Example = test.pdf is saved successfull)

      Please Help
    • luckyluke
      By luckyluke
      Hello,
      Im trying to read the output from CMD using Dllcall, here is my code:
      #include <WinAPI.au3> #include <array.au3> Global Const $STD_OUTPUT_HANDLE = -11 Global Const $_CONSOLE_SCREEN_BUFFER_INFO = _ "struct;int dwSizeX;" & _ "short dwSizeY;" & _ "short dwCursorPositionX;" & _ "short dwCursorPositionY;" & _ "short wAttributes;" & _ "short Left;" & _ "short Top;" & _ "short Right;" & _ "short Bottom;" & _ "short dwMaximumWindowSizeX;" & _ "short dwMaximumWindowSizeY;endstruct" $pCmd = Run( "cmd.exe" ) Sleep(1000) $hCmd = WinGetHandle("") ConsoleWrite('handle:' & $hCmd & @CRLF) $aRet = DllCall("kernel32.dll", "int", "AttachConsole", "dword", $pCmd) ;_ArrayDisplay($aRet) If $aRet[0] <> 0 Then $vHandle_data='' $vHandle='' $vHandle_data = DllStructCreate($_CONSOLE_SCREEN_BUFFER_INFO) ; Screen Buffer structure $aRet1 = DllCall("kernel32.dll", "hwnd", "GetStdHandle", "dword", $STD_OUTPUT_HANDLE) if not @error Then $vHandle = $aRet1[0] $aRet = DllCall("kernel32.dll", "int", "GetConsoleScreenBufferInfo", "hwnd", $vHandle, _ "ptr", $vHandle_data) MsgBox(0, '1',DllStructGetData($vHandle_data, 'dwSizeX') & _WinAPI_GetLastErrorMessage()) EndIf It did not work, i got the message 'The handle is invalid'. Please help?
      Thank you in advance!
    • mihaijulien
      By mihaijulien
      Hello,
      I compiled a script I made that takes a command line parameter (the version of a .msi installer) when launched. The script was compiled with the /console option. The script (.au3) works fine but the executable returns  the following error:  
      Error: array variable has incorrect number of subscripts or subscript dimension range exceeded