Jump to content

My script doesn't open


Recommended Posts

Hi people, when I run my script it just flashes the Gui and it closes, I can't understand why this happening, can you check my code and tell me what is wrong.

#include <AutoItConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#include <ScrollBarsConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
Local $aWndPos
Local $idFilemenu = GUICtrlCreateMenu("&File")
Local $idExititem = GUICtrlCreateMenuItem("Exit", $idFilemenu)
Local $idButton = GUICtrlCreateButton("IPConfig", 10, 10, 190, 25)
    GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKWIDTH, $GUI_DOCKHEIGHT))


$NetAs = GUICreate("NetAs-Network Assistant", 1096, 497, 182, 135)
Local $idInput = GUICtrlCreateEdit("", 168, 24, 921, 465)
Local $Button1 = GUICtrlCreateButton("IPconfig", 16, 32, 75, 25)
Local $Button2 = GUICtrlCreateButton("?", 96, 32, 19, 25)
Local $Button3 = GUICtrlCreateButton("Button3", 16, 72, 75, 25)
Local $Button4 = GUICtrlCreateButton("?", 96, 72, 19, 25)
Local $Button5 = GUICtrlCreateButton("Button5", 16, 112, 75, 25)
Local $Button6 = GUICtrlCreateButton("?", 96, 112, 19, 25)
Local $Button7 = GUICtrlCreateButton("Button7", 16, 152, 75, 25)
Local $Button8 = GUICtrlCreateButton("?", 96, 152, 19, 25)
Local $Button9 = GUICtrlCreateButton("Button9", 16, 192, 75, 25)
Local $Button10 = GUICtrlCreateButton("?", 96, 192, 19, 25)
Local $Button11 = GUICtrlCreateButton("Button11", 16, 232, 75, 25)
Local $Button12 = GUICtrlCreateButton("?", 96, 232, 19, 25)
Local $Button13 = GUICtrlCreateButton("Button13", 16, 272, 75, 25)
Local $Button14 = GUICtrlCreateButton("?", 96, 272, 19, 25)
Local $Button15 = GUICtrlCreateButton("Button15", 16, 312, 75, 25)
Local $Button16 = GUICtrlCreateButton("?", 96, 312, 19, 25)
Local $Button17 = GUICtrlCreateButton("Button17", 16, 352, 75, 25)
Local $Button18 = GUICtrlCreateButton("?", 96, 352, 19, 25)
Local $Button19 = GUICtrlCreateButton("Button19", 16, 392, 75, 25)
Local $Button20 = GUICtrlCreateButton("?", 96, 392, 19, 25)
Local $Button21 = GUICtrlCreateButton("Button21", 16, 432, 75, 25)
Local $Button22 = GUICtrlCreateButton("?", 96, 432, 19, 25)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idExititem
            Exit
        Case $Button1
            GUICtrlSetData($idInput, _CmdInfo() & @CRLF)
            _GUICtrlEdit_Scroll($idInput, $SB_SCROLLCARET)
            _GUICtrlEdit_Scroll($idInput, $SB_SCROLLCARET)
    EndSwitch
WEnd

Func _CmdInfo($_sCmdInfo = "ipconfig /all")
    Local $iPID = Run(@ComSpec & " /c " & $_sCmdInfo, "", @SW_HIDE,  BitOR($STDERR_CHILD, $STDOUT_CHILD))
    ; Wait until the process has closed using the PID returned by Run.
    ProcessWaitClose($iPID)
    ; Read the Stdout stream of the PID returned by Run. This can also be done in a while loop. Look at the example for StderrRead.
    Local $sOutput = StringReplace(StdoutRead($iPID), @CRLF & @CRLF, @CRLF)
    Local $sOutErr = StringReplace(StderrRead($iPID), @CRLF & @CRLF, @CRLF)
    Local $sReult = $sOutput <> "" ? $sOutput : $sOutErr
    Return $sReult
EndFunc

 

Link to comment
Share on other sites

  • Moderators

@zoel you need to start at least trying things for yourself rather than asking forum members to do everything for you. Your While statement has 3 Case clauses that could potentially close your GUI. Start commenting them out one at a time to find the culprit.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Your menu is created before the gui it belongs in, try putting those three after the GUICreate.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

According to help for GUICtrlCreateMenu https://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateMenu.htm

here is your code fixed to be working

#include <AutoItConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#include <ScrollBarsConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>

Local $aWndPos

$NetAs = GUICreate("NetAs-Network Assistant", 1096, 497, 182, 135)

Local $idFilemenu = GUICtrlCreateMenu("&File")
Local $idExititem = GUICtrlCreateMenuItem("Exit", $idFilemenu)

;~ Local $idButton = GUICtrlCreateButton("IPConfig", 10, 10, 190, 25)
;~     GUICtrlSetResizing(-1, BitOR($GUI_DOCKLEFT, $GUI_DOCKTOP, $GUI_DOCKWIDTH, $GUI_DOCKHEIGHT))

Local $idInput = GUICtrlCreateEdit("", 168, 24, 921, 465)
Local $Button1 = GUICtrlCreateButton("IPconfig", 16, 32, 75, 25)
Local $Button2 = GUICtrlCreateButton("?", 96, 32, 19, 25)
Local $Button3 = GUICtrlCreateButton("Button3", 16, 72, 75, 25)
Local $Button4 = GUICtrlCreateButton("?", 96, 72, 19, 25)
Local $Button5 = GUICtrlCreateButton("Button5", 16, 112, 75, 25)
Local $Button6 = GUICtrlCreateButton("?", 96, 112, 19, 25)
Local $Button7 = GUICtrlCreateButton("Button7", 16, 152, 75, 25)
Local $Button8 = GUICtrlCreateButton("?", 96, 152, 19, 25)
Local $Button9 = GUICtrlCreateButton("Button9", 16, 192, 75, 25)
Local $Button10 = GUICtrlCreateButton("?", 96, 192, 19, 25)
Local $Button11 = GUICtrlCreateButton("Button11", 16, 232, 75, 25)
Local $Button12 = GUICtrlCreateButton("?", 96, 232, 19, 25)
Local $Button13 = GUICtrlCreateButton("Button13", 16, 272, 75, 25)
Local $Button14 = GUICtrlCreateButton("?", 96, 272, 19, 25)
Local $Button15 = GUICtrlCreateButton("Button15", 16, 312, 75, 25)
Local $Button16 = GUICtrlCreateButton("?", 96, 312, 19, 25)
Local $Button17 = GUICtrlCreateButton("Button17", 16, 352, 75, 25)
Local $Button18 = GUICtrlCreateButton("?", 96, 352, 19, 25)
Local $Button19 = GUICtrlCreateButton("Button19", 16, 392, 75, 25)
Local $Button20 = GUICtrlCreateButton("?", 96, 392, 19, 25)
Local $Button21 = GUICtrlCreateButton("Button21", 16, 432, 75, 25)
Local $Button22 = GUICtrlCreateButton("?", 96, 432, 19, 25)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idExititem
            Exit
        Case $Button1
            GUICtrlSetData($idInput, _CmdInfo() & @CRLF)
            _GUICtrlEdit_Scroll($idInput, $SB_SCROLLCARET)
            _GUICtrlEdit_Scroll($idInput, $SB_SCROLLCARET)
    EndSwitch
WEnd

Func _CmdInfo($_sCmdInfo = "ipconfig /all")
    Local $iPID = Run(@ComSpec & " /c " & $_sCmdInfo, "", @SW_HIDE,  BitOR($STDERR_CHILD, $STDOUT_CHILD))
    ; Wait until the process has closed using the PID returned by Run.
    ProcessWaitClose($iPID)
    ; Read the Stdout stream of the PID returned by Run. This can also be done in a while loop. Look at the example for StderrRead.
    Local $sOutput = StringReplace(StdoutRead($iPID), @CRLF & @CRLF, @CRLF)
    Local $sOutErr = StringReplace(StderrRead($iPID), @CRLF & @CRLF, @CRLF)
    Local $sReult = $sOutput <> "" ? $sOutput : $sOutErr
    Return $sReult
EndFunc

 

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