Jump to content

Echo runwait commands to the screen


Recommended Posts

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
Link to comment
Share on other sites

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 (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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