Jump to content
Sign in to follow this  
n0manarmy

Echo runwait commands to the screen

Recommended Posts

n0manarmy

I am using autoit to run a series of commands to turn on the registry of a remote machine, delete profiles older than 14 days and then turn off the remote registry on our windows 7 machines. I cannot figure out how to either have the commands outputs displayed in their cmd boxes.

I see no outputs when I turn on remote registry, delete old profiles, and then turn off the remote registry. The application works so far, however the outputs being displayed in some way or another would be great because it can take a long time to run.

If I can use runwait or shellexecutewait to see the outputs of the commands I run it would be a huge help

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=C:\Users\pwilbert\Desktop\temp\autodelprof.exe
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;
;
;Profile cleanup automation utility
;

#include <GUIConstantsEx.au3>
;declarations
Global Const $mainWindow = GUICreate("Profile Deletion", 500, 500)
Global Const $statusWindow = GUICtrlCreateList("", -1, 80, 500)
Global Const $deleteProfiles = GUICtrlCreateButton("Del Profiles", 30, 50, 100)
Global Const $computerNameInput = GUICtrlCreateInput("none", 150, 50, 100)
Global Const $scCommand = "sc \\"
Global Const $scStart = " start remoteregistry"
Global Const $scQuery = " query remoteregistry"
Global Const $scStop = " stop remoteregistry"
Global $delprof = @TempDir & "\delprof2.exe /q /u /d:14 /c:\\"
Global $computerName = String("none")

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApplication")
GUICTRLSetOnEvent($deleteProfiles, "Main")
GUISetState(@SW_SHOW)

FileInstall("c:\users\pwilbert\Desktop\work\delprof\delprof2.exe", @TempDir & "\delprof2.exe", 1)

While 1
Sleep(1000)
WEnd

;starting of the application, makes respective calls.
Func Main()
$computerName = GUICtrlRead($computerNameInput)
$startRemoteRegistry = $scCommand & $computerName & $scStart
$stopRemoteRegistry = $scCommand & $computerName & $scStop
$delprof = $delprof & $computerName

GUICtrlSetData($statusWindow, "")
Call ("StartRemoteRegistry", $startRemoteRegistry)
Call ("DelProfiles", $delprof)
Call ("StopRemoteRegistry", $stopRemoteRegistry)
EndFunc


Func StartRemoteRegistry($startRemoteRegistry)
GUICtrlSetData($statusWindow, "Starting Remote Registry|")
$results = RunWait($startRemoteRegistry)
If $results = 0 Then
GUICtrlSetData($statusWindow, "Success|")
Else
GUICtrlSetData($statusWindow, "Failed|")
EndIf
EndFunc


Func StopRemoteRegistry($stopRemoteRegistry)
GUICtrlSetData($statusWindow, "Stopping remote registry|")
$results = RunWait($stopRemoteRegistry)
If $results = 0 Then
GUICtrlSetData($statusWindow, "Success|")
Else
GUICtrlSetData($statusWindow, "Failed|")
EndIf
EndFunc


Func DelProfiles($delprof)
GUICtrlSetData($statusWindow, "Deleting old profiles|")
RunWait($delprof)
WEnd
EndFunc


Func ExitApplication()
Exit
EndFunc

Share this post


Link to post
Share on other sites
water

You could replace RunWait with Run and use $STDOUT_CHILD to grab the output of the program. To wait until the program has finished use something like:

Local $iPID = Run(...)
Local $sStdOutRead = ""
While ProcessExists($iPID)
    $sStdOutRead &= StdoutRead($iPID)
WEnd
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

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  

×