Jump to content
FMS

error in returning valeus

Recommended Posts

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 (2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-03-02 - Version 1.3.5.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-01-22 - Version 0.1.0.0) - Download - General Help & Support
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

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 (2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-03-02 - Version 1.3.5.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-01-22 - Version 0.1.0.0) - Download - General Help & Support
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
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 (2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-03-02 - Version 1.3.5.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-01-22 - Version 0.1.0.0) - Download - General Help & Support
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-03-02 - Version 1.3.5.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-01-22 - Version 0.1.0.0) - Download - General Help & Support
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
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

    • By lee321987
      Sometimes when I call several MsgBox's they start popping up under other windows, which the requires ALT + TAB or click the taskbar icon.
      I just wanted to share this workaround:
      Just add a simple GUI in your program:
      #include <GUIConstantsEx.au3> $Form1 = GUICreate("Form1", 1, 1, 0, 0) GUISetState(@SW_SHOW) The GUI window size here is 1x1 so it will be nearly invisible, and at the top-left of your screen.
      It seems as long as that GUI is there all MsgBox's appear on top!
      I only tend to create several MsgBox's in a row when I'm actually writing and testing scripts, so the GUI being there is no big deal (I just remove/comment the GUI creation right before I build the .EXE).
      Have a great day!!!
       
       
    • By Burgs
      Greetings,
        I would like to be able to write a script to send commands to the console for creation of Gstreamer pipelines.  I was thinking of something similar to this:
      Local $iPID = Run("C:\Windows\System32\cmd", "", @SW_MAXIMIZE) ;THIS OPENS THE CONSOLE...!!! if $iPID == 0 Then ConsoleWrite(@CRLF & "I DID NOT OPEN CMD...error: " & @error & @CRLF) if $iPID <> 0 Then ConsoleWrite(@CRLF & "I OPENED CMD...!!!" & @CRLF) $hCmd = WinGetHandle("C:\WINDOWS\system32\cmd.exe") if $hCmd <> 0 Then WinActivate($hCmd) ;ensure command console is active... $sOutput = Send("cd C:\gstreamer\1.0\x86_64\bin" & @CRLF, $SEND_RAW) $sOutput = Send("gst-launch-1.0 videotestsrc ! autovideosink" & @CRLF, $SEND_RAW) Sleep(3000) ControlSend($hCmd, "", "", "exit" & @CR) EndIf ;$hCmd NOT "0"... I don't really know if this is the best way to open the console and send commands into it.  I'm also not sure about how to best catch any errors that may occur...likely this needs to be accomplished with the STDOUTREAD command however I've not had experience using it before and therefore would appreciate some advice that anybody may offer. 
      Basically I'm seeking guidance on how to best automate the opening of the console, sending lines of commands to be executed, and handling any potential errors in the execution of those commands...I thank you in advance.  Regards.
    • By MadhaN
      Hi all,
      I have a csv file as below, I wand to find srno from csv and send corresponding ip and pass to commend cmd prompt. 
      Please guide me to create script .
      srno,name,ip,pass
      1,name1,ip1,pass1
      2,name2,ip2,pass2
       
       
       
       
    • By editcheck
      Hi, after years of use autoit i am tired to type all time:
      msgbox('','','Hi')
      So, wanna mod the function for set default values... or some more changes.
      where is the function?
      or there are another modes for debug messages that i do not knowed ? XD [just wanna like alert('text')]
      And is there any place for all integrates functions ?
      Thank. Sry my english =E
    • By Ackerz
      Hi guys,
      So I am trying to automate a task and this task has an input box with an already set character "9". 
      I have just decided that I don't really need the input as an option but it's good to leave however for this instance I would like it to run past this point automatically. I've tried numerous ways to try and automate the use of the "OK" button using ControlClick and various other options. I just can't seem to see where this point in the script is. Scoured the forums for anything similar but didn't have any luck finding anything. Sorry to be a pain and I hope someone can help, if I haven't explained in enough detail please don't hesitate to ask for more.
      Many thanks,
      Ackerz
       
      Local $len Local $n Local $buff Local $aMyDate $Len = InputBox("Test",$msgPrompt,"9") $len = StringStripWS($len,$STR_STRIPALL) ;Check that user has entered a vaild password length if not StringIsDigit($len) or $len = 0 Then MsgBox(48,"Error","Invaild Integer was entered" & @CRLF & "Program will now exit.") Exit EndIf ;This creates the random password. for $i = 1 to $Len ;Pick a random char between 1 and the pwsMask Length $n = int(random(1,StringLen($pwsMask))) ;Concat each char that has been picked out of pwsMask to $buff $buff = $Buff & StringMid($pwsmask,$n,1) Next  
×
×
  • Create New...