Skeeter

Simple GPResult summary script issue

7 posts in this topic

I'm trying to rewrite a working script I created to simply make it cleaner.  The first script below works but I didn't want repeated Input boxes popping up and decided to clean it up.  

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=GroupPolicyInfo.ico
#AutoIt3Wrapper_Outfile=GroupPolicyInfoRemote.exe
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_Run_Au3Stripper=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <FileConstants.au3>
#include <Constants.au3>
#include <file.au3>
Global $techname = InputBox('Technician Login', 'Please enter your tech- username', '', '', 300, 200)
Global $techpass = InputBox('Technician Password', 'Please enter your tech- password', '', '*', 300, 200)
Global $Username = InputBox('Group Policy Info', 'Please enter the Username for which to acquire information', '', '', 300, 200)
Global $Computername = InputBox('Group Policy Info', 'Please enter the Hostname for which to acquire information', '', '', 300, 200)
Global $DOS, $Message
$DOS = RunAs($techname, @LogonDNSDomain, $techpass, 0, @ComSpec & ' /c ' & 'gpresult /R /S ' & $Computername & ' /USER ' & $Username, '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
ProcessWaitClose($DOS)
$Message = StdoutRead($DOS)
FileOpen(@TempDir & '\output.txt', 0)
FileWrite(@TempDir & '\output.txt', $Message)
$file = (@TempDir & '\output.txt')
RunWait('notepad.exe ' & $file, @WindowsDir, @SW_MAXIMIZE)
FileDelete(@TempDir & '\output.txt')

Now after putting labels and input boxes all into one windows I get the output file but its blank.  Not sure where I'm going wrong.  New script below.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <Constants.au3>
#include <file.au3>
#Region ### START Koda GUI section ### Form=
Global $GroupPolicyInfo = GUICreate("Group Policy Info", 340, 215, -1, -1)
GUISetFont(8, 800, 0, "MS Sans Serif")
Global $Label1 = GUICtrlCreateLabel("Tech Username", 16, 16, 114, 20)
Global $Label2 = GUICtrlCreateLabel("Tech Password", 16, 56, 111, 20)
Global $Label3 = GUICtrlCreateLabel("UserID", 16, 96, 52, 20)
Global $Label4 = GUICtrlCreateLabel("Hostname", 16, 136, 74, 20)
Global $OK = GUICtrlCreateButton("OK", 136, 176, 75, 25)
Global $Cancel = GUICtrlCreateButton("Cancel", 248, 176, 75, 25)
Global $techuser = GUICtrlCreateInput("", 136, 16, 185, 24)
Global $techpass = GUICtrlCreateInput("", 136, 56, 185, 24, $ES_PASSWORD)
Global $EU_ID = GUICtrlCreateInput("", 136, 96, 185, 24)
Global $EU_Hostname = GUICtrlCreateInput("", 136, 136, 185, 24)
Global $DOS, $Message
GUICtrlSetState($techuser, $GUI_FOCUS)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $OK
            $DOS = RunAs($techuser, @LogonDNSDomain, $techpass, 0, @ComSpec & ' /c ' & 'gpresult /R /S ' & $EU_Hostname & ' /USER ' & $EU_ID, '', @SW_HIDE, $STDOUT_CHILD)
            ProcessWaitClose($DOS)
            $Message = StdoutRead($DOS)
            FileOpen(@TempDir & '\output.txt', 0)
            FileWrite(@TempDir & '\output.txt', $Message)
            $file = (@TempDir & '\output.txt')
            RunWait('notepad.exe ' & $file, @WindowsDir, @SW_MAXIMIZE)
            FileDelete(@TempDir & '\output.txt')
            WinClose('Group Policy Info')

        Case $Cancel
            Exit

    EndSwitch
WEnd

I'm still very new to this but trying to learn fast.

 

Thanks in advance

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Whenever you need to use the input of a GuiCtrlCreateInput you need to read it.

For example...

Case $OK
            $DOS = RunAs(GUICtrlRead($techuser), @LogonDNSDomain, GUICtrlRead($techpass), 0, @ComSpec & ' /c ' & 'gpresult /R /S ' & GUICtrlRead($EU_Hostname) & ' /USER ' & GUICtrlRead($EU_ID), '', @SW_HIDE, $STDOUT_CHILD)

 

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

You could also try:
gpresult /H report.html /USER theuser
Or
gpresult /X report.xml /USER theuser

Or just:

$DOS = RunAs($techuser, @LogonDNSDomain, $techpass, 0, @ComSpec & ' /c ' & 'gpresult /R /S ' & $EU_Hostname & ' /USER ' & $EU_ID & '>output.txt', '', @SW_HIDE, $STDOUT_CHILD)

As you see you could redirect gpresult output to a file and you don't need FileOpen() or FileWrite()

Regards
Alien.

Share this post


Link to post
Share on other sites

Try:
 

Opt("TrayMenuMode", 3)
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <Constants.au3>
;~ Global Const $ES_PASSWORD = 32
;~ Global Const $GUI_EVENT_CLOSE = -3
;~ Global Const $GUI_FOCUS = 256
;~ Global Const $FO_OVERWRITE = 2
;~ Global Const $FO_CREATEPATH = 8
;~ Global Const $STDOUT_CHILD = 2
;~ Global Const $STDERR_CHILD = 4
#Region ### START Koda GUI section ### Form=
Global $GroupPolicyInfo = GUICreate("Group Policy Info", 340, 215, -1, -1)
GUISetFont(8, 800, 0, "MS Sans Serif")
GUICtrlCreateLabel("Tech Username", 16, 16, 114, 20)
GUICtrlCreateLabel("Tech Password", 16, 56, 111, 20)
GUICtrlCreateLabel("UserID", 16, 96, 52, 20)
GUICtrlCreateLabel("Hostname", 16, 136, 74, 20)
Global $OK = GUICtrlCreateButton("OK", 136, 176, 75, 25)
Global $Cancel = GUICtrlCreateButton("Cancel", 248, 176, 75, 25)
Global $itechuser = GUICtrlCreateInput("", 136, 16, 185, 24)
Global $itechpass = GUICtrlCreateInput("", 136, 56, 185, 24, $ES_PASSWORD)
Global $iEU_ID = GUICtrlCreateInput("", 136, 96, 185, 24)
Global $iEU_Hostname = GUICtrlCreateInput("", 136, 136, 185, 24)
Global $FileReport = @TempDir & '\output.txt', $DOS, $Message, $techuser, $techpass, $EU_ID, $EU_Hostname
GUICtrlSetState($techuser, $GUI_FOCUS)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $Cancel
            Exit
        Case $OK
            $techuser = GUICtrlRead($techuser)
            $techpass = GUICtrlRead($techpass)
            $EU_ID = GUICtrlRead($EU_ID)
            $EU_Hostname = GUICtrlRead($EU_Hostname)
            $DOS = RunAs($techuser, @LogonDNSDomain, $techpass, 0, @ComSpec & ' /c ' & 'gpresult /R /S ' & $EU_Hostname & ' /USER ' & $EU_ID, '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
            ProcessWaitClose($DOS)
            $Message = StdoutRead($DOS)
            Local $hOpen = FileOpen($FileReport, $FO_OVERWRITE + $FO_CREATEPATH)
            FileWrite($hOpen, $Message)
            FileClose($hOpen)
            RunWait('notepad.exe ' & $FileReport, @WindowsDir, @SW_MAXIMIZE)
            FileDelete($FileReport)
;~             WinClose('Group Policy Info')
    EndSwitch
    Sleep(10)
WEnd

 


Regards,
 

Share this post


Link to post
Share on other sites

@JohnOne thx much.  That worked perfectly.

@VIP I tried but that still produced a blank output.txt.

@alien4u I had done that previously but didn't want to save a file by default only to have that option if needed by opening it in notepad.

 

Thx all.  I'm loving AutoIt more and more each day.

Share this post


Link to post
Share on other sites
2 hours ago, Skeeter said:

 

@VIP I tried but that still produced a blank output.txt.

 

Try edit commandline:
 

$DOS = RunAs($techuser, @LogonDNSDomain, $techpass, 0, @ComSpec & ' /c ' & 'gpresult /R /S ' & $EU_Hostname & ' /USER ' & $EU_ID, '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

to:

$DOS = RunAs($techuser, @LogonDNSDomain, $techpass, 0, @ComSpec & ' /c ' & 'gpresult /R /S ' & $EU_Hostname & ' /USER ' & $EU_ID, '', @SW_HIDE, $STDERR_CHILD)

:)


Regards,
 

Share this post


Link to post
Share on other sites

Hi there

I have been looking for a tool just like this, did you get round the blank output.txt file issue?

I copied the code above and tried using it but am getting a blank output file as well, what syntax should I be using in the boxes?

Do I need to add the domain name before the username?

Thanks for any advice :)

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