Balragh Posted August 13, 2024 Posted August 13, 2024 Hello, First of all i'm new and not that good at coding in general, i'm trying to create a simple gui that will achieve a simple goal : * one input (username) * one button (start a powershell with the inputT used) So far I have this going : #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> ;Creating GUI GUICreate("search last logon",150,110) GUICtrlCreateLabel("Entrer un Snumber",30,20,200,30) $inputSnumber = GUICtrlCreateInput("",25,35,100,20) $config = GUICtrlCreateButton("Lancer recherche", 25, 60, 100, 20) $snumber = GUICtrlRead($inputSnumber) $sPSCmd = "Get-ADUser -Identity" & $snumber & "-Properties 'LastLogon'| Select-Object Name, @{N='LastLogon'; E {[DateTime]::FromFileTime($_.LastLogon)}}" ;affichage de la fenêtre GUISetState(@SW_SHOW) While 1 $idMsg = GUIGetMsg() Switch $idMsg Case $GUI_EVENT_CLOSE ExitLoop Case $config RunWait(@comspec & ' /c powershell.exe -nologo -executionpolicy bypass -WindowStyle hidden -noprofile -command "&' & $sPSCmd & '"') ;trying to find why this does not work ;( MsgBox($MB_SYSTEMMODAL,"", GUICtrlRead($inputSnumber)) MsgBox($MB_SYSTEMMODAL,"",$sPSCmd) EndSwitch WEnd I tried this thingy : $sPSCmd = "Get-ADUser -Identity" & $snumber & "-Properties 'LastLogon'| Select-Object Name, @{N='LastLogon'; E {[DateTime]::FromFileTime($_.LastLogon)}}" with & $snumber & or directly GUICtrlRead($inputSnumber) but, when outputting the command ($sPSCmd) the variable does not shows up. Would someone be kind enough to give this a try and guide me ? Thanks again from a baguette technician
Nine Posted August 13, 2024 Posted August 13, 2024 At the start of the script there is nothing inside the input box. Read the input box when you click the button. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
ioa747 Posted August 13, 2024 Posted August 13, 2024 without knowing Here is the pattern from $sPSCmd = "Get-ADUser -Identity" & $snumber & "-Properties 'LastLogon'| to $sPSCmd = "Get-ADUser -Identity " & $snumber & " -Properties 'LastLogon'| I know that I know nothing
Balragh Posted August 13, 2024 Author Posted August 13, 2024 Ok thanks guys, I just had to get the input read from inside the while .. my mistake. Now it's working fine. Just have to find how to get the response from powershell which seems to be an other problem haha I naively tried to set the command as a variable et print what's inside but no luck of course : $response = RunWait(@comspec & ' /c ' & 'powershell.exe -command "&' & $sPSCmd & '"') but of course that does not do the trick. If you still have an idea on this, I will keep locking if someone had the same problem I had
Nine Posted August 13, 2024 Posted August 13, 2024 Here one way : #include <Constants.au3> Local $iPID = Run(@comspec & ' /c powershell.exe Get-ChildItem -path c:\apps', "", @SW_HIDE, $STDERR_MERGED) ProcessWaitClose($iPID) ConsoleWrite(StdoutRead($iPID) & @CRLF) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Balragh Posted August 13, 2024 Author Posted August 13, 2024 27 minutes ago, Nine said: Here one way : #include <Constants.au3> Local $iPID = Run(@comspec & ' /c powershell.exe Get-ChildItem -path c:\apps', "", @SW_HIDE, $STDERR_MERGED) ProcessWaitClose($iPID) ConsoleWrite(StdoutRead($iPID) & @CRLF) Thanks for this solution, but when trying to consolowrite or msgbox it, it's not showing anything. Basically what i'm trying to do is to get the returned last logon and show it in the GUI.
Balragh Posted August 13, 2024 Author Posted August 13, 2024 Just added the -noexit to the command and it's working fine, the command is successful. for the horrible while I have so far, it looks like this : While 1 $idMsg = GUIGetMsg() $snumber = GUICtrlRead($inputSnumber) $sPSCmd = "Get-ADUser -Identity" & " '" & $snumber & "' " & "-Properties 'LastLogonDate'| Select-Object Name, LastLogonDate" Switch $idMsg Case $GUI_EVENT_CLOSE ExitLoop Case $config $pwCMD = Run(@comspec & ' /c powershell.exe -NoExit -command "&' & $sPSCmd) ProcessWaitClose($pwCMD) msgbox($MB_SYSTEMMODAL,"",StdoutRead($pwCMD) & @CRLF) EndSwitch WEnd
Balragh Posted August 13, 2024 Author Posted August 13, 2024 Thank you for your time, Just tried you solution but the same extact problem occurs, the msgbox opens empty The GUICtrlRead is working fine and the command also, but when it reaches the msgbox it's empty 😕
Solution Nine Posted August 13, 2024 Solution Posted August 13, 2024 your run should be : $pwCMD = Run(@ComSpec & ' /c powershell.exe "' & $sPSCmd, "", @SW_HIDE, $STDERR_MERGED) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Balragh Posted August 13, 2024 Author Posted August 13, 2024 AMENO. Thanks so much mysterious @Nine for the help, for the rest, I think I'll just tinker around to make it cleaner
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now