Jump to content

Recommended Posts

Posted (edited)

Hello,

                   Im trying to capture information from a dos command using StdoutRead() and have it appear in an edit box in my GUI. For some reason when i run the command with a msgbox in the while loop it will transfer the data to the edit box properly. but when i eliminate the msg box from the while loop nothing appears in the edit box. I cant sem to figure out exactly where i am going wrong here.

Sample code:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <inet.au3>
#include <Constants.au3>
#RequireAdmin


#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 449, -815, 111)
$User = GUICtrlCreateButton("Who's Logged On", 16, 16, 171, 33)
$Host = GUICtrlCreateButton("Get Hostname", 16, 64, 171, 33)
$Mac = GUICtrlCreateButton("Get MAC Address", 16, 112, 171, 33)
$sUser = GUICtrlCreateInput("", 216, 24, 217, 21)
$sHost = GUICtrlCreateInput("", 216, 72, 217, 21)
$sMac = GUICtrlCreateInput("", 216, 120, 217, 21)
$pInfo = GUICtrlCreateInput("", 448, 168, 169, 21)
$Label1 = GUICtrlCreateLabel("Version", 448, 150, 164, 19)
$Acc = GUICtrlCreateButton("User Account", 456, 16, 155, 41)
$IP = GUICtrlCreateInput("IP/Host Name", 8, 408, 193, 21)
$Version = GUICtrlCreateButton("Check Version", 16, 160, 171, 33)
$pName = GUICtrlCreateInput("Enter Program", 216, 168, 217, 21)
$Ping = GUICtrlCreateButton("Ping", 232, 392, 169, 41)
$mDrive = GUICtrlCreateButton("Remote C$", 432, 392, 163, 41)
$nPrinter = GUICtrlCreateButton("Mapped Printers", 16, 208, 171, 33)
$pList = GUICtrlCreateEdit("", 216, 208, 217, 73)
GUICtrlSetData(-1, "Edit1")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $User
            remote_user()
        case $Host
            remote_host()
        case $Mac
            remote_Mac()
        Case $Version
            remote_program()
        case $ping
            ping_customer()
        case $mDrive
            map_drive()
        case $nPrinter
            get_printers()
        Case $acc
            Account()
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

func remote_user()
    $pid= Run(@ComSpec & " /c wmic /node:214.47.41.200 computersystem get username", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

While 1
    $line = StdoutRead($pid)
    If @error Then ExitLoop
    MsgBox(0, "STDOUT read:", $line) ;<----- this msgbox i would like to get rid off but code doesnt seem to wrk without it 
    guictrlsetdata($pList, $line)
Wend
While 1
    $line = StderrRead($pid)
    If @error Then ExitLoop
   guictrlsetdata($pList, $line)
Wend
EndFunc

thank you to all that help or reply

 

 

 

Edited by Milas
wanted to edit the code
Posted

alright while no one seems to have respond thank you for anyone who tried and just did not reply. Now im not sure if its the most correct answer but i added a sleep command for one second in between the run function and the while loop. i guess the wmic process needs time to resolve. hopefully i can find a better answer to this dilemma.

  • Moderators
Posted

Milas,

Please remember this is not a 24/7 support forum - those who answer are only here because they like helping others and have some time to spare.  You just have to wait until someone who knows something about your particular problem, and is willing to help, comes online.

M23

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

  • Developers
Posted

Try:

Func remote_user()
    $pid = Run(@ComSpec & " /c wmic computersystem get username", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    Local $line
    While 1
        $line &= StdoutRead($pid)
        If @error Then ExitLoop
        GUICtrlSetData($pList, $line)
    WEnd
    While 1
        $line &= StderrRead($pid)
        If @error Then ExitLoop
        GUICtrlSetData($pList, $line)
    WEnd
EndFunc    ;==>remote_user

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...