Jump to content

Form + stdout in cmd.exe


Recommended Posts

Ok i want to explain what i want to do, i want a form in a gui with like 4 questions, (GUICtrlCreateInput)

and i want to take the return of these questions to create 4 $var.

after all 4 questions complete i want to execute a cmd promp with a start button and include my var in a syntaxe like that

#psexec -i -u $var_user -p $var_password @ $var_hostfile -e notepad.exe $var_txt

this is the begin of my FORM

#include <GUIConstants.au3>
$widthCell=70
GUICreate(" My GUI", 220,200, @DesktopWidth/2-160, @DesktopHeight/2-45, -1, 0x00000018)
GUICtrlCreateLabel ("Username: ", 5, 10, $widthCell)
GUICtrlCreateLabel ("Password: ", 5, 40, $widthCell)
GUICtrlCreateLabel ("HOST File: ", 5, 70, 100)
GUICtrlCreateLabel ("TXT File: ", 5, 100, 100)
$username = GUICtrlCreateInput ("", 90, 5, 100, 20)
$password = GUICtrlCreateInput ("", 90, 35, 100, 20)
$hostfile = GUICtrlCreateInput ("", 90, 65, 100, 20)
$txtfile = GUICtrlCreateInput ("", 90, 95, 100, 20)
$btn = GUICtrlCreateButton ("Ok", 100, 120, 60, 20)
GUISetState ()


$msg = 0
While $msg <> $GUI_EVENT_CLOSE
$msg = GUIGetMsg()

INCLUDE CODE HERE

exitloop
EndSelect
Wend

i have found this script to send command to CMD.EXE but it not take $var

#AutoIt3Wrapper_Change2CUI=n
#include <Constants.au3>
Local $foo = run("cmd.exe" & " /c " & "ping www.google.com", @SystemDir, @SW_MAXIMIZE, $STDIN_CHILD + $STDOUT_CHILD)
ConsoleWrite("open wodrivswt4" & @CR)
Local $data
While True
    $data &= StdoutRead($foo)
    If @error Then ExitLoop
    Sleep(25)
WEnd
MsgBox(0, "Debug", $data)
Edited by DarkAnel
Link to comment
Share on other sites

Have you tried wrapping your variables in quotations?

'#psexec -i -u "' & $var_user & '" "-p "' & $var_password '" @ "' & $var_hostfile & '" -e notepad.exe "' & $var_txt

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. 

Link to comment
Share on other sites

Have you tried wrapping your variables in quotations?

'#psexec -i -u "' & $var_user & '" "-p "' & $var_password '" @ "' & $var_hostfile & '" -e notepad.exe "' & $var_txt

i have try this to do something easy but its not work, i will search about wrapping vraiable in quotations

#AutoIt3Wrapper_Change2CUI=n
#include <Constants.au3>
$ip = 192.168.0.1
$cmd = ping
Local $foo = run("cmd.exe" & " /c " & "$cmd" & "$ip", @SystemDir, @SW_MAXIMIZE, $STDIN_CHILD + $STDOUT_CHILD)
ConsoleWrite("open wodrivswt4" & @CR)
Local $data
While True
    $data &= StdoutRead($foo)
    If @error Then ExitLoop
    Sleep(25)
WEnd
MsgBox(0, "Debug", $data)
Edited by DarkAnel
Link to comment
Share on other sites

This worked for me:

#AutoIt3Wrapper_Change2CUI=n
#include <Constants.au3>
$ip = "192.168.0.1" ; strings need to be enclosed in quotes
$cmd = "ping" ;  ditto
Local $foo = run("cmd.exe" & " /c " & '"' & $cmd & '"' & '" ' & $ip & ' "', @SystemDir, @SW_MAXIMIZE, $STDIN_CHILD + $STDOUT_CHILD) ; see where the quotes are wrapping the variables?
ConsoleWrite("open wodrivswt4" & @CR)
Local $data
While True
    $data &= StdoutRead($foo)
    If @error Then ExitLoop
    Sleep(25)
WEnd
MsgBox(0, "Debug", $data)

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

Just because i'm newb, and a bit lazy..

BrewManNH >

1. in your example, that means you could output the read out "realtime" to a text field in GUI right? (i should just put it in the sleep loop, right?)

2. From the example it looks like StdoutRead only returns "new" data , is that right?

Edited by squadjot
Link to comment
Share on other sites

squadjot,

1. - yes

2. - yes

This code is from a recent thread and provided an example of what you are asking

; 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,0xaaaaaa)
                 GUICtrlSetFont($clear,10,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

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Just because i'm newb, and a bit lazy..

BrewManNH >

1. in your example, that means you could output the read out "realtime" to a text field in GUI right? (i should just put it in the sleep loop, right?)

Yes, you could use GUICtrlSetData for a label or an Edit box using $data as the data to send to the control.

2. From the example it looks like StdoutRead only returns "new" data , is that right?

I'm not sure what you're asking here, but you have to use StdOutRead in a loop like that, so that it can get all the information from the program as it's sent.

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

Thanks

@2 i mean... the purpose of doing it realtime, would be to "visualize" a process..(example: reading % done from FFMPEG).. now.. if i read the console in a loop. I read the entire console..or only "new" data..?.. Hence your reply, i guess it just reads the entire window again then?

Link to comment
Share on other sites

squadjot,

1. - yes

2. - yes

This code is from a recent thread and provided an example of what you are asking

; 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,0xaaaaaa)
                 GUICtrlSetFont($clear,10,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

This is for me a good start for my script i love the idea, i have change the CMD ipconfig for a CMD PING with 2 paramater

but what is the best way to take the second paramater

; 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("PING",10,  10, 75, 25)
Local $Button2 = GUICtrlCreateButton("NETSTAT", 90, 10, 75, 25)
Local $clear   = GUICtrlCreateButton("Clear Display", 700, 10, 90, 25)
                 GUICtrlSetBkColor($clear,0xaaaaaa)
                 GUICtrlSetFont($clear,10,800,default,'times new roman')
                 GUICtrlCreateLabel("PARM = ",200,15,75,25)
     GUICtrlCreateLabel("PARM2 = ",350,15,75,25)
Local $parm = GUICtrlCreateEdit('',250,10,75,25,$ss_sunken)
                 GUICtrlSetFont($parm,12,800)
                 GUICtrlSetState($parm,$gui_focus)
Local $ip   = GUICtrlCreateEdit('',400,10,125,25,$ss_sunken)
                 GUICtrlSetFont($ip,12,800)
                 GUICtrlSetState($ip,$gui_focus)
Local $Edit010 = GUICtrlCreateEdit("", 10,200,780,350, $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 ping " & GUICtrlRead($parm +$ip), @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
Edited by DarkAnel
Link to comment
Share on other sites

ok i have found the way to add 2 $parameter

$rslt = Run(@ComSpec & " /c ping " & GUICtrlRead($parm) + GUICtrlRead($ip)

That's not the way to combine two variables, you need to use & instead of + unless you're adding the values together, which you're not in this case.

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

someone can tell me what is wrong with my wraping?? it need to look like

psexec -i -s -d -u $user -p $pass @$hostfile notepad.exe $msgfile

$rslt = Run(@ComSpec & " /c c:PSToolsPsExec -i -s -d -u " & '"' &  GUICtrlRead($user) & '" -p ' & '"' &  GUICtrlRead($pass) & '"' &  " @ " & '"' & GUICtrlRead($hostfile) & '" ' & "notepad.exe " & '"' & GUICtrlRead($msgfile) & '"', @SystemDir, @SW_HIDE, $STDERR_MERGED + $STDOUT_CHILD)
Edited by DarkAnel
Link to comment
Share on other sites

  • 4 weeks later...

Why are you opening the file in notepad on the target computer instead of the one you're on?

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

  • 2 weeks later...

i need to send a message on the remote computer, notepad need to open and notepad need to open a source file dirrectly by UNC serverfile.txt i dont think psexec can open directly the file serverfile.txt i think i need to past by the notepad.exe serverfile.txt

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