Jump to content

StdoutRead gpupdate /force


Recommended Posts

StdoutRead isn't working when I use gpupdate /force (Windows 7 Professional/Enterprise). It's working fine with other switches, e.g. gpudpate /target:computer, but once /force is introduced I get nothing back.

#include <Constants.au3>

$time = 0

; These don't work
; $sCMD = 'c:\windows\System32\gpupdate.exe /force'
$sCMD = 'c:\windows\System32\gpupdate.exe /force /target:computer '

; These do work
; $sCMD = 'c:\windows\System32\gpupdate.exe /target:computer '
; $sCMD = 'c:\windows\System32\ipconfig.exe /all'

Local       $sTMP = ''
Local       $sSTD = ''

Local Const $iPID = Run($sCMD, 'c:\', @SW_HIDE, $STDERR_MERGED)

While 1 = 1

    $sTMP = StdoutRead($iPID, False, False)
    $time = $time +250
    If @error Then

        ExitLoop

    ElseIf $time > 60000 Then

        ConsoleWrite("timeout: exit loop")
        ExitLoop

    Else

        $sSTD &= $sTMP
        ConsoleWrite($sTMP)
        Sleep(250)

    EndIf

WEnd

ConsoleWrite($sSTD)

I'm just getting timeout: exit loop.

For those familiar with gpupdate /force, I'm looking for the OK to Restart?. (Y/N) line so I can notify users they should restart, typically for software updates.

I'm hoping someone has come across this before! I'm getting the same behaviour on a few computers.

Edited by BBrian
Link to comment
Share on other sites

What do you get if you run the command in the command window manually on the same computers?

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

It's working as expected there, immediately the line Updating Policy... appears, then after a while all this will be printed:

Updating Policy...

User Policy update has completed successfully.

The following warnings were encountered during user policy processing:

The Group Policy Client Side Extension Folder Redirection was unable to apply on
e or more settings because the changes must be processed before system startup o
r user logon. The system will wait for Group Policy processing to finish complet
ely before the next startup or logon for this user, and this may result in slow
startup and boot performance.
Computer Policy update has completed successfully.

The following warnings were encountered during computer policy processing:

The Group Policy Client Side Extension Software Installation was unable to apply
 one or more settings because the changes must be processed before system startu
p or user logon. The system will wait for Group Policy processing to finish comp
letely before the next startup or logon for this user, and this may result in sl
ow startup and boot performance.

For more detailed information, review the event log or run GPRESULT /H GPReport.
html from the command line to access information about Group Policy results.

Certain User policies are enabled that can only run during logon.
Certain Computer policies are enabled that can only run during startup.

OK to Restart?. (Y/N)

What's different with the two working examples above is with /force it doesn't close the window after. But I would expect the ConsoleWrite($sTMP) in the loop to still work. I've tried using ProcessClose where my timeout is but it didn't help.

 

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