Jump to content

I found a script that I want to use but it does not working as it should


elzo
 Share

Recommended Posts

Hello people, I found a script that I want to use for my own project, but it does not work. I want to make a GUI with one button that it will run one cmd command. But when I run the script that I found it opens the GUI but I can not run any commands. here is the script: I am on a windows 10 machine x64

 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
Local $vDos, $sline = ""
#Region ### START Koda GUI section ### Form=
Local $Form1 = GUICreate("IPConfig GUI", 623, 434, 196, 125)
$MenuItem1 = GUICtrlCreateMenu("&MenuItem1")
$MenuItem2 = GUICtrlCreateMenuItem("MenuItem2"&@TAB&"", $MenuItem1)
$MenuItem3 = GUICtrlCreateMenu("M&enuItem3")
$MenuItem4 = GUICtrlCreateMenuItem("MenuItem4"&@TAB&"", $MenuItem3)
Local $Edit1 = GUICtrlCreateEdit("", 112, 0, 505, 353)
GUICtrlSetData(-1, "")
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x008080)
$Tab1 = GUICtrlCreateTab(0, 0, 113, 401)
GUICtrlCreateTabItem("")
Local $Button1 = GUICtrlCreateButton("/all", 8, 40, 75, 25)
Local $Button2 = GUICtrlCreateButton("/renew", 8, 72, 75, 25)
Local $Button3 = GUICtrlCreateButton("/release", 8, 136, 75, 25)
Local $Button4 = GUICtrlCreateButton("/flushdns", 8, 200, 75, 25)
$Button5 = GUICtrlCreateButton("/displaydns", 8, 232, 75, 25)
$Button6 = GUICtrlCreateButton("/registerdns", 8, 264, 75, 25)
$Button7 = GUICtrlCreateButton("/showclassid", 8, 296, 75, 25)
$Button8 = GUICtrlCreateButton("ipconfig", 8, 8, 75, 25)
$Button9 = GUICtrlCreateButton("/setclassid", 8, 328, 75, 25)
$Button10 = GUICtrlCreateButton("Clear", 8, 360, 75, 25)
$Button20 = GUICtrlCreateButton("/release6", 8, 168, 75, 25)
$Button22 = GUICtrlCreateButton("/renew6 ", 8, 104, 75, 25)
$Button11 = GUICtrlCreateButton("?", 88, 8, 17, 17, -1, $WS_EX_STATICEDGE)
$Button12 = GUICtrlCreateButton("?", 88, 40, 17, 17, -1, $WS_EX_STATICEDGE)
$Button13 = GUICtrlCreateButton("?", 88, 72, 17, 17, -1, $WS_EX_STATICEDGE)
$Button14 = GUICtrlCreateButton("?", 88, 104, 17, 17, -1, $WS_EX_STATICEDGE)
$Button15 = GUICtrlCreateButton("?", 88, 136, 17, 17, -1, $WS_EX_STATICEDGE)
$Button16 = GUICtrlCreateButton("?", 88, 168, 17, 17, -1, $WS_EX_STATICEDGE)
$Button17 = GUICtrlCreateButton("?", 88, 200, 17, 17, -1, $WS_EX_STATICEDGE)
$Button18 = GUICtrlCreateButton("?", 88, 232, 17, 17, -1, $WS_EX_STATICEDGE)
$Button19 = GUICtrlCreateButton("?", 88, 264, 17, 17, -1, $WS_EX_STATICEDGE)
$Button21 = GUICtrlCreateButton("?", 88, 296, 17, 17, -1, $WS_EX_STATICEDGE)
$Button23 = GUICtrlCreateButton("?", 88, 328, 17, 17, -1, $WS_EX_STATICEDGE)
Local $Edit2 = GUICtrlCreateEdit("", 192, 360, 425, 49)
GUICtrlSetData(-1, "")
$Label1 = GUICtrlCreateLabel("Parameters =>", 120, 368, 72, 17, -1, $WS_EX_STATICEDGE)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$hGUI_Child_1 = GUICreate("Follower", 626, 150, -1, -1, BitOR($WS_POPUP, $WS_BORDER), 0, $Form1)
GUISetState(@SW_HIDE, $hGUI_Child_1)
$hGUI_Child_2 = GUICreate("Follower", 626, 150, -1, -1, BitOR($WS_POPUP, $WS_BORDER), 0, $Form1)
GUISetState(@SW_HIDE, $hGUI_Child_2)
$hGUI_Child_3 = GUICreate("Follower", 626, 150, -1, -1, BitOR($WS_POPUP, $WS_BORDER), 0, $Form1)
GUISetState(@SW_HIDE, $hGUI_Child_3)
$hGUI_Child_4 = GUICreate("Follower", 626, 150, -1, -1, BitOR($WS_POPUP, $WS_BORDER), 0, $Form1)
GUISetState(@SW_HIDE, $hGUI_Child_4)
$hGUI_Child_5 = GUICreate("Follower", 626, 150, -1, -1, BitOR($WS_POPUP, $WS_BORDER), 0, $Form1)
GUISetState(@SW_HIDE, $hGUI_Child_5)
$hGUI_Child_6 = GUICreate("Follower", 626, 150, -1, -1, BitOR($WS_POPUP, $WS_BORDER), 0, $Form1)
GUISetState(@SW_HIDE, $hGUI_Child_6)
$hGUI_Child_7 = GUICreate("Follower", 626, 150, -1, -1, BitOR($WS_POPUP, $WS_BORDER), 0, $Form1)
GUISetState(@SW_HIDE, $hGUI_Child_7)
$hGUI_Child_8 = GUICreate("Follower", 626, 150, -1, -1, BitOR($WS_POPUP, $WS_BORDER), 0, $Form1)
GUISetState(@SW_HIDE, $hGUI_Child_8)
$hGUI_Child_9 = GUICreate("Follower", 626, 150, -1, -1, BitOR($WS_POPUP, $WS_BORDER), 0, $Form1)
GUISetState(@SW_HIDE, $hGUI_Child_9)
$hGUI_Child_10 = GUICreate("Follower", 626, 150, -1, -1, BitOR($WS_POPUP, $WS_BORDER), 0, $Form1)
GUISetState(@SW_HIDE, $hGUI_Child_10)
$hGUI_Child_11 = GUICreate("Follower", 626, 150, -1, -1, BitOR($WS_POPUP, $WS_BORDER), 0, $Form1)
GUISetState(@SW_HIDE, $hGUI_Child_11)



;----> Create dummy keys for accelerators
$hENTER = GUICtrlCreateDummy()
Dim $AccelKeys[1][2] = [["{ENTER}", $hENTER]] ; Set accelerators
GUISetAccelerators($AccelKeys)
;<----

GUIRegisterMsg($WM_MOVE, "_Position_Child")

net_properties()
Func net_properties()
    Local $rslt, $out
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case  $GUI_EVENT_CLOSE
                Exit

            Case $Button1, $hENTER
                $vDos = Run(@ComSpec & " /c " & GUICtrlRead($Edit2), @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
                While 1
                    $sline &= StdoutRead($vDos)
                    If @error Then ExitLoop
                WEnd
                GUICtrlSetData($Edit1, $sline & @CRLF)
                GUICtrlSetData($Edit2, "")
                ;----> Reset
                $sline = ""
                ;<----

            Case $Button2
                $rslt = Run(@ComSpec & " /c ipconfig " & GUICtrlRead($Edit2), @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDOUT_CHILD)
                While 1
                    $out = StdoutRead($rslt)
                    If @error Then ExitLoop
                    GUICtrlSetData($Edit1, $out & @LF, 1)
                WEnd
            Case $Button3
                $rslt = Run(@ComSpec & " /c netstat " & GUICtrlRead($Edit2), @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDOUT_CHILD)
                While 1
                    $out = StdoutRead($rslt)
                    If @error Then ExitLoop
                    GUICtrlSetData($Edit1, $out & @LF, 1)
                WEnd
            Case $Button4
                GUICtrlSetData($Edit1, "")
    Case $Button11
            Switch GUICtrlRead($Button11)
                Case "?"
                    _Position_Child($Form1, 0, 0, 0)
                    GUISetState(@SW_SHOW, $hGUI_Child_1)
                    GUICtrlSetData($Button11, "?.")
                Case Else
                    GUISetState(@SW_HIDE, $hGUI_Child_1)
                    GUICtrlSetData($Button11, "?")
            EndSwitch
    Case $Button12
            Switch GUICtrlRead($Button12)
                Case "?"
                    _Position_Child($Form1, 0, 0, 0)
                    GUISetState(@SW_SHOW, $hGUI_Child_2)
                    GUICtrlSetData($Button12, "?.")
                Case Else
                    GUISetState(@SW_HIDE, $hGUI_Child_2)
                    GUICtrlSetData($Button12, "?")
            EndSwitch
Case $Button13
            Switch GUICtrlRead($Button13)
                Case "?"
                    _Position_Child($Form1, 0, 0, 0)
                    GUISetState(@SW_SHOW, $hGUI_Child_3)
                    GUICtrlSetData($Button13, "?.")
                Case Else
                    GUISetState(@SW_HIDE, $hGUI_Child_3)
                    GUICtrlSetData($Button13, "?")
            EndSwitch
Case $Button14
            Switch GUICtrlRead($Button14)
                Case "?"
                    _Position_Child($Form1, 0, 0, 0)
                    GUISetState(@SW_SHOW, $hGUI_Child_4)
                    GUICtrlSetData($Button14, "?.")
                Case Else
                    GUISetState(@SW_HIDE, $hGUI_Child_4)
                    GUICtrlSetData($Button14, "?")
            EndSwitch
Case $Button15
            Switch GUICtrlRead($Button15)
                Case "?"
                    _Position_Child($Form1, 0, 0, 0)
                    GUISetState(@SW_SHOW, $hGUI_Child_5)
                    GUICtrlSetData($Button15, "?.")
                Case Else
                    GUISetState(@SW_HIDE, $hGUI_Child_5)
                    GUICtrlSetData($Button15, "?")
            EndSwitch
Case $Button16
            Switch GUICtrlRead($Button16)
                Case "?"
                    _Position_Child($Form1, 0, 0, 0)
                    GUISetState(@SW_SHOW, $hGUI_Child_6)
                    GUICtrlSetData($Button16, "?.")
                Case Else
                    GUISetState(@SW_HIDE, $hGUI_Child_6)
                    GUICtrlSetData($Button16, "?")
            EndSwitch
Case $Button17
            Switch GUICtrlRead($Button17)
                Case "?"
                    _Position_Child($Form1, 0, 0, 0)
                    GUISetState(@SW_SHOW, $hGUI_Child_7)
                    GUICtrlSetData($Button17, "?.")
                Case Else
                    GUISetState(@SW_HIDE, $hGUI_Child_7)
                    GUICtrlSetData($Button17, "?")
            EndSwitch
Case $Button18
            Switch GUICtrlRead($Button18)
                Case "?"
                    _Position_Child($Form1, 0, 0, 0)
                    GUISetState(@SW_SHOW, $hGUI_Child_8)
                    GUICtrlSetData($Button18, "?.")
                Case Else
                    GUISetState(@SW_HIDE, $hGUI_Child_8)
                    GUICtrlSetData($Button18, "?")
            EndSwitch
Case $Button19
            Switch GUICtrlRead($Button19)
                Case "?"
                    _Position_Child($Form1, 0, 0, 0)
                    GUISetState(@SW_SHOW, $hGUI_Child_9)
                    GUICtrlSetData($Button19, "?.")
                Case Else
                    GUISetState(@SW_HIDE, $hGUI_Child_9)
                    GUICtrlSetData($Button19, "?")
            EndSwitch
Case $Button21
            Switch GUICtrlRead($Button21)
                Case "?"
                    _Position_Child($Form1, 0, 0, 0)
                    GUISetState(@SW_SHOW, $hGUI_Child_10)
                    GUICtrlSetData($Button21, "?.")
                Case Else
                    GUISetState(@SW_HIDE, $hGUI_Child_10)
                    GUICtrlSetData($Button21, "?")
            EndSwitch
Case $Button23
            Switch GUICtrlRead($Button23)
                Case "?"
                    _Position_Child($Form1, 0, 0, 0)
                    GUISetState(@SW_SHOW, $hGUI_Child_11)
                    GUICtrlSetData($Button23, "?.")
                Case Else
                    GUISetState(@SW_HIDE, $hGUI_Child_11)
                    GUICtrlSetData($Button23, "?")
            EndSwitch
        EndSwitch
    WEnd
EndFunc   ;==>net_properties


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

    #forceref $iMsg, $wParam, $lParam

    If $hWnd <> $Form1 Then Return

    Local $aGUI_Main_Pos = WinGetPos($Form1)

    WinMove($hGUI_Child_1, "", $aGUI_Main_Pos[0], $aGUI_Main_Pos[1] + $aGUI_Main_Pos[3])
    WinMove($hGUI_Child_2, "", $aGUI_Main_Pos[0], $aGUI_Main_Pos[1] + $aGUI_Main_Pos[3])
    WinMove($hGUI_Child_3, "", $aGUI_Main_Pos[0], $aGUI_Main_Pos[1] + $aGUI_Main_Pos[3])
    WinMove($hGUI_Child_4, "", $aGUI_Main_Pos[0], $aGUI_Main_Pos[1] + $aGUI_Main_Pos[3])
    WinMove($hGUI_Child_5, "", $aGUI_Main_Pos[0], $aGUI_Main_Pos[1] + $aGUI_Main_Pos[3])
    WinMove($hGUI_Child_6, "", $aGUI_Main_Pos[0], $aGUI_Main_Pos[1] + $aGUI_Main_Pos[3])
    WinMove($hGUI_Child_7, "", $aGUI_Main_Pos[0], $aGUI_Main_Pos[1] + $aGUI_Main_Pos[3])
    WinMove($hGUI_Child_8, "", $aGUI_Main_Pos[0], $aGUI_Main_Pos[1] + $aGUI_Main_Pos[3])
    WinMove($hGUI_Child_9, "", $aGUI_Main_Pos[0], $aGUI_Main_Pos[1] + $aGUI_Main_Pos[3])
    WinMove($hGUI_Child_10, "", $aGUI_Main_Pos[0], $aGUI_Main_Pos[1] + $aGUI_Main_Pos[3])
    WinMove($hGUI_Child_11, "", $aGUI_Main_Pos[0], $aGUI_Main_Pos[1] + $aGUI_Main_Pos[3])
EndFunc   ;==>_Position_Child

Thanks in advance

Link to comment
Share on other sites

He means I think that he just wants 1 button = 1 action, not as in only 1 button in the whole GUI, or 1 button that can do multiple things (like depending on other GUI elements).

 

As for this script/GUI, it's neat, and I didn't have any issues with getting it to do what I wanted to do. What have you tried doing? What is your goal? I see right now that it's set up as a bunch of ipconfig options, but only buttons 1-4 are set up to do anything, and only really 2-3 do anything of any value. 

 

Also there's a few more issues and things with the script, such as a command like netstat ($Button3 which is labeled "/release") will block all other GUI actions while it's running. It would be better to allow the GUI loop to continue and check for new StdoutRead data in the main loop.

 

I don't know where you found this script/GUI from (or if you made some elements yourself), but keep in mind that while you've labeled the buttons, you still need to add the correct actions to the buttons. The buttons that do do something do not match their labels.

 

Edit: Also, the GUI updates constantly (when running a command), even if there's not new data, causing it to flicker.

Edited by mistersquirrle

We ought not to misbehave, but we should look as though we could.

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