Sign in to follow this  
Followers 0

Unexpected Result...Send scripts in same CMD

15 posts in this topic

Posted · Report post

I am trying to create some scripts with cmd commands like this
Run(@ComSpec & ' /kipconfig/all ')
compile it to exes and running them .

But i want to make buttons in my gui and run the corresponding exe/command
what i would like to know if possible, is how to make these exe/commands to open in the same cmd window. (no in different instances of cmd)

The Unexpected Result in the title is because i made this script to open my 2 exe/commands
and made me reboot my pc...

WARNING do not run this script (it opens very fast lots of cmd windows)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Local $Button_1, $Button_2, $msg
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 338, 221, 299, 132)
$Button1 = GUICtrlCreateButton("ipconfig", 48, 128, 75, 25)
$Button2 = GUICtrlCreateButton("netstat", 216, 128, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
asssdd()
Func asssdd()
While 1
	    $msg = GUIGetMsg()
	    Select
		    Case $msg = $GUI_EVENT_CLOSE
			    ExitLoop
		    Case $msg = $Button_1
			    Run('ipco.exe') ; Will Run ipco.exe that exist in the same folder as the script
		    Case $msg = $Button_2
			   Run('netstat.exe') ; Will Run netstat.exe that exist in the same folder as the script
	    EndSelect
    WEnd
EndFunc

Share this post


Link to post
Share on other sites



Posted · Report post

armoros,

Your variable names do NOT match...$Button_1 in the select stmt, but, $Button1 in the definition...

kylomas
armoros likes this

Share this post


Link to post
Share on other sites

Posted · Report post

armoros,

Your variable names do NOT match...$Button_1 in the select stmt, but, $Button1 in the definition...

kylomas


Thank you Kylomas ur right.... ;)

but except my bad script is it possible to open different commands/scripts in same cmd window

Share this post


Link to post
Share on other sites

Posted · Report post

armoros,

You'll have to wait for someone with expertise to answer. I rarely, if ever, use the CMD window.

Good Luck,

kylomas
armoros likes this

Share this post


Link to post
Share on other sites

Posted · Report post

armoros,

You'll have to wait for someone with expertise to answer. I rarely, if ever, use the CMD window.

Good Luck,

kylomas


Thank you my friend you were helpful...
I have an issue of passion with cmd ;)

Share this post


Link to post
Share on other sites

Posted · Report post

Why are you creating separate exes for the different commands you want to run? Why not just run them directly from the main script, seeing as how the exes you're running are just AutoIt exes?

Share this post


Link to post
Share on other sites

Posted · Report post

Why are you creating separate exes for the different commands you want to run? Why not just run them directly from the main script, seeing as how the exes you're running are just AutoIt exes?


Thank you for the response BrewManNH, but i don't understand what you mean ...

Share this post


Link to post
Share on other sites

Posted · Report post

It's possible, but you need 2 different scripts.
If you create a console script WITHOUT GUI and compile it with the option "Create CUI instead of GUI EXE", your compiled script, if run from the cmd box, will read from the cmd box and output to it. That compiled script could launch another autoit script with a GUI and wait for its disappearence or a command from it before it exits. That second (GUI) script has buttons and is compiled with the GUI option.
With this setup, the 2 scripts can talk to each other, communicate data, one can read the cmd box and write to it, it's the "puppet", the GUI one is the "puppet master".
armoros likes this

Share this post


Link to post
Share on other sites

Posted · Report post

Thank you for the response BrewManNH, but i don't understand what you mean ...

Try this, compile it, then run the resulting exe and see what it does.

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Change2CUI=y
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
GUICreate("")
$button = GUICtrlCreateButton(" IPConfig ", 20, 20)
$button2 = GUICtrlCreateButton(" NetStat ", 20, 70)
GUISetState()
While 1
    $msg = GUIGetMsg()
    Switch $msg
	    Case -3
		    Exit
	    Case $button
		    _IPConfig()
	    Case $button2
		    _NetStat()
    EndSwitch
WEnd
Func _IPConfig()
    $PID = Run("ipconfig /all", "", @SW_HIDE, 8)
    While ProcessExists($PID)
	    $line = StdoutRead($PID)
	    If @error Then ExitLoop
	    If $line <> "" Then ConsoleWrite($line & @CRLF)
    WEnd
EndFunc   ;==>_IPConfig
Func _NetStat()
    $PID = Run("netstat", "", @SW_HIDE, 8)
    While ProcessExists($PID)
	    $line = StdoutRead($PID)
	    If @error Then ExitLoop
	    If $line <> "" Then ConsoleWrite($line & @CRLF)
    WEnd
EndFunc

This is just a quick demo and you can prettify it however you'd like, but it gives you the general idea of what I'm talking about.
armoros likes this

Share this post


Link to post
Share on other sites

Posted · Report post

armoros,

SLightly different from BrewmanNH but same concept (can't type as fast as the Brewman)

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

Local $Button1, $Button2, $msg, $edit010
$Form1   = GUICreate("Network Properties", 400, 400)
$Button1 = GUICtrlCreateButton("ipconfig",10,  10, 75, 25)
$Button2 = GUICtrlCreateButton("netstat", 315, 10, 75, 25)
$Edit010 = GUICtrlCreateEdit("", 10,40,380,300, $ES_AUTOVSCROLL + $WS_VSCROLL + $ws_hscroll + $es_readonly)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
asssdd()
Func asssdd()

	Local $rslt,$out

	While 1
			$msg = GUIGetMsg()
			Select
				Case $msg = $GUI_EVENT_CLOSE
					ExitLoop
				Case $msg = $Button1
					$rslt = Run(@ComSpec & " /c ipconfig", @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDOUT_CHILD) ; Will Run ipco.exe that exist in the same folder as the script
					While 1
						$out = StdoutRead($rslt)
						If @error then exitloop
						GUICtrlSetData($edit010,$out & @lf,1)
					WEnd

				Case $msg = $Button2
					$rslt = Run(@ComSpec & " /c netstat", @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDOUT_CHILD) ; Will Run ipco.exe that exist in the same folder as the script
					While 1
						$out = StdoutRead($rslt)
						If @error then exitloop
						GUICtrlSetData($edit010,$out & @lf,1)
					WEnd
			EndSelect
	WEnd
EndFunc


kylomas
armoros likes this

Share this post


Link to post
Share on other sites

Posted · Report post

It's possible, but you need 2 different scripts.
If you create a console script WITHOUT GUI and compile it with the option "Create CUI instead of GUI EXE", your compiled script, i".

Try this, compile it, then run the resulting exe and see what it does.


This is just a quick demo and you can prettify it however you'd like, but it gives you the general idea of what I'm talking about.

armoros,

SLightly different from BrewmanNH but same concept (can't type as fast as the Brewman)


kylomas


1) Redont1 Thank you for the info you show me the path to try achieve what i want..

2) BrewManNH Thank you too for the guidance and the script but when i compile it, opens the gui but nothing else happens .
ill test it more.

3) Kylomas thank you again its nice your script i had this in my mind after a simillar script from user Country73 here

Thank you all for the help guys . Now i know more ;)

Share this post


Link to post
Share on other sites

Posted · Report post

2) BrewManNH Thank you too for the guidance and the script but when i compile it, opens the gui but nothing else happens .
ill test it more.

Did you actually press one of the buttons? Because it will display the results of that command in the command window when you do. Although I like kylomas' idea of using an edit box to display the information, much cleaner.

Share this post


Link to post
Share on other sites

Posted · Report post

armoros,

Something else that I am working on broke my brain so I've been goofing around with this. Here's a more complete way to do this.

; example of using stdout with network commands
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <Constants.au3>
#include <StaticConstants.au3>
Local $Gui010  = GUICreate("Network Properties", 800, 600)
Local $Button1 = GUICtrlCreateButton("IPCONFIG",10,  10, 75, 25)
Local $Button2 = GUICtrlCreateButton("NETSTAT", 90, 10, 75, 25)
Local $clear   = GUICtrlCreateButton("Clear Display", 700, 10, 90, 25)
	 GUICtrlSetBkColor($clear,0xff0000)
	 GUICtrlSetFont($clear,8.5,800,default,'times new roman')
				 GUICtrlCreateLabel("PARM = ",200,15,75,25)
Local $parm    = GUICtrlCreateEdit('',250,10,75,25,$ss_sunken)
	 GUICtrlSetFont($parm,12,800)
	 GUICtrlSetState($parm,$gui_focus)
Local $Edit010 = GUICtrlCreateEdit("", 10,40,780,550, $ES_AUTOVSCROLL + $WS_VSCROLL + $ws_hscroll + $es_readonly)
				 GUICtrlSetFont(-1,8.5,800,default,'courier new')
GUISetState(@SW_SHOW)
net_properties()
Func net_properties()
 Local $rslt,$out
 While 1
   $msg = GUIGetMsg()
   Select
	Case $msg = $GUI_EVENT_CLOSE
	 ExitLoop
	Case $msg = $Button1
	 $rslt = Run(@ComSpec & " /c ipconfig " & GUICtrlRead($parm), @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDOUT_CHILD) ; Will Run ipco.exe that exist in the same folder as the script
	 While 1
	  $out = StdoutRead($rslt)
	  If @error then exitloop
	  GUICtrlSetData($edit010,$out & @lf,1)
	 WEnd
	Case $msg = $Button2
	 $rslt = Run(@ComSpec & " /c netstat " & GUICtrlRead($parm), @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDOUT_CHILD) ; Will Run ipco.exe that exist in the same folder as the script
	 While 1
	  $out = StdoutRead($rslt)
	  If @error then exitloop
	  GUICtrlSetData($edit010,$out & @lf,1)
	 WEnd
	Case $msg = $clear
	 GUICtrlSetData($edit010,"")
   EndSelect
 WEnd
EndFunc


kylomas
armoros likes this

Share this post


Link to post
Share on other sites

Posted · Report post

Did you actually press one of the buttons? Because it will display the results of that command in the command window when you do. Although I like kylomas' idea of using an edit box to display the information, much cleaner.


Yes i did it compile it and run it but when i press the buttons nothing happens, (i am on a xp sp3 )


armoros,

Something else that I am working on broke my brain so I've been goofing around with this. Here's a more complete way to do this.


kylomas


Yeah very nice script it gives me an idea.....

Share this post


Link to post
Share on other sites

Posted (edited) · Report post

Try this, compile it, then run the resulting exe and see what it does.

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Change2CUI=y
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
GUICreate("")

This is just a quick demo and you can prettify it however you'd like, but it gives you the general idea of what I'm talking about.

I am sorry BrewManNH it was my fault your script is exactly what i wanted but i was so blind that i didn't notice ;)

the
AutoIt3Wrapper_Change2CUI=y


Yes it works perfect
Thank you very much.... :)

Thank you also for your permission to use it..

Thank you all guys Kylomas your 2 script is super..

I will use all Edited by armoros

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
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.