Jump to content
Sign in to follow this  
kevinward13

Window Closing

Recommended Posts

kevinward13

trying to get PSlogged on to run and display results for a test.

However the cmd window keeps closing. any idea how to get to to stay open?

code below

FileInstall('.\Include\Psexec.exe', @TempDir & '\')
FileInstall('.\Include\Psloggedon.exe', @TempDir & '\')

Global Const $PsExecReg = 'HKCU\Software\Sysinternals\PsExec'
Global Const $PsLoggReg = 'HKCU\Software\Sysinternals\PsLoggedon'
Global Const $PS = 'psexec.exe'
Global Const $PL = 'psloggedon.exe'

$WNAME = InputBox("Workstation name", "")

    If RegRead($PsExecReg, 'EulaAccepted') = '' Then RegWrite($PsExecReg, 'EulaAccepted', 'REG_DWORD', 1)
    If RegRead($PsLoggReg, 'EulaAccepted') = '' Then RegWrite($PsLoggReg, 'EulaAccepted', 'REG_DWORD', 1)

$FL = 'psloggedon.exe -l -x \\' & $WNAME

$Pid = Run(@ComSpec & ' /c ' & $FL)

Share this post


Link to post
Share on other sites
Delta

There is no loop in your code so once everything has been executed it just quits.

Try adding this to the end of your code.

While 1 
 Sleep(50)
WEnd

[size="1"]Please stop confusing "how to" with "how do"[/size]

Share this post


Link to post
Share on other sites
kevinward13

I finially got it to display a window for me with something in it.

However the inputbox is adding a '0' to the end of the string. Somewhere between these lines..

$WNAME = InputBox("Workstation name", "Workstation name:")

    If RegRead($PsExecReg, 'EulaAccepted') = '' Then RegWrite($PsExecReg, 'EulaAccepted', 'REG_DWORD', 1)
    If RegRead($PsLoggReg, 'EulaAccepted') = '' Then RegWrite($PsLoggReg, 'EulaAccepted', 'REG_DWORD', 1)

$FL = 'psloggedon.exe -l -x \\' & $WNAME

ConsoleWrite($FL)

The ConsoleWrite($FL) gives the output of

psloggedon.exe -l -x \\xxxxxxxxxx0

why is that 0 there?

Share this post


Link to post
Share on other sites
Delta

Does the 0 show up if you run psloggedon.exe in a batch script? I've never used either of those programs so I don't know what their outputs should be.


[size="1"]Please stop confusing "how to" with "how do"[/size]

Share this post


Link to post
Share on other sites
kevinward13

nope it does not

Share this post


Link to post
Share on other sites
Delta

Well since I don't know what you intend to do with $FL aside from displaying it in console my only suggestion is to trim the 0 off with StringTrimRight.

Should look something like this.

ConsoleWrite(StringTrimRight($FL, 1))

[size="1"]Please stop confusing "how to" with "how do"[/size]

Share this post


Link to post
Share on other sites
wakillon

did you try

$Pid = Run( @ComSpec & ' /k ' & $FL )
Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites
kevinward13

ok i got some of the code working. But now i am stuck again.

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=PsexecGUIMenu.exe
#AutoIt3Wrapper_UseUpx=n
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****



#include <Crypt.au3>
#include <Constants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <StatusBarConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <GUIComboBox.au3>
#include <GuiListView.au3>
#include <File.au3>
#include <GuiTab.au3>
#include <IE.au3>
#include <Array.au3>
#include <Color.au3>
#include <GuiRichEdit.au3>

FileInstall('.\Include\Psexec.exe', @TempDir & '\')
FileInstall('.\Include\Psloggedon.exe', @TempDir & '\')

Global Const $PsExecReg = 'HKCU\Software\Sysinternals\PsExec'
Global Const $PsLoggReg = 'HKCU\Software\Sysinternals\PsLoggedon'
Global Const $PS = 'psexec.exe'
Global Const $PL = 'psloggedon.exe'
Global Const $TxtLog = 'LoggedOn.txt'
Global Const $TxtDir = 'C:\'
Global $CurrentLoggedOn




If RegRead($PsExecReg, 'EulaAccepted') = '' Then RegWrite($PsExecReg, 'EulaAccepted', 'REG_DWORD', 1)
If RegRead($PsLoggReg, 'EulaAccepted') = '' Then RegWrite($PsLoggReg, 'EulaAccepted', 'REG_DWORD', 1)


_TxtDelete()

_Loggedon()

_TxtOpen()

Func _TxtDelete()

    If FileExists($TxtDir & $TxtLog) Then
        FileDelete($TxtDir & $TxtLog)
    EndIf

EndFunc   ;==>_TxtDelete


Func _Loggedon()

    $WNAME = InputBox("Workstation name", "ENTER WORKSTATION NAME:")

    $ListSave = (' >> ' & $TxtDir & $TxtLog)

    $FL = 'psloggedon.exe -l -x \\' & $WNAME

    Run(@ComSpec & ' /k ' & $FL & '| FIND "AD\"' & $ListSave)


EndFunc   ;==>_Loggedon


Func _TxtOpen()

    WinClose("[Class:Command]", "C:\WINDOWS\system32\cmd.exe")

    $File = FileOpen($TxtDir & $TxtLog, 0)

ConsoleWrite($File)
    ; Check if file opened for reading OK
    If $File = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf

    ; Read in lines of text until the EOF is reached
    While 1
        $Line = FileReadLine($File)
        ConsoleWrite($Line)
        If @error = -1 Then ExitLoop

    WEnd



    FileClose($File)


EndFunc   ;==>_TxtOpen

I am now getting the information i wanted to save to the txt file. I was able to get it to FileOpen() just fine. Then it just quit working and keep getting the -1 error back.

Any ideas?

Share this post


Link to post
Share on other sites
kevinward13

ah never mind. Had to add a sleep(100) between the function calls

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  

×