JoelG Posted September 30, 2020 Share Posted September 30, 2020 I'm trying to write a script that will check the password expiry of a user account. I just can't find a way to get the output of the command to a variable so I can display it to the user in a MsgBox: #include <Constants.au3> ; Request username Local $UserID = InputBox ( "Password Expiry Checker", "Please enter the username you want to check.") ; Set Net User command $NETCMD = 'NET USER ' & $UserID & ' /DOMAIN |FIND /I "Password expires"' ; Run Net User command Local $CMD = Run(@ComSpec & " /c " & $NETCMD) ProcessWaitClose($CMD) ; Output results MsgBox (64, "Password Expiry Checker", $UserID & " " & $PassExpiry) The above will run the command and display the data I'm looking for in a command prompt window (I'll hide that when I get the rest working). I've tried using STDOUT but I just can't get it to output anything to a variable (I know that piece is missing here). Can anyone suggest a way to output the $NETCMD to $PassExpiry variable that I can use in the MsgBox? Thanks, Joel Link to comment Share on other sites More sharing options...
TheXman Posted September 30, 2020 Share Posted September 30, 2020 (edited) Look up StdoutRead in the help file and look at its example. Edited September 30, 2020 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
JoelG Posted September 30, 2020 Author Share Posted September 30, 2020 I have, but it does not seem to work for this. Two things I've noticed with StdOutRead: As soon as I add , $STDOUT_CHILD to my command, the line runs far to quickly to have actually completed - ie. I get the msgbox immediately, not after 5 seconds like it takes for the cmd to return a result. The StdOutRead ends up empty. Joel Link to comment Share on other sites More sharing options...
TheXman Posted September 30, 2020 Share Posted September 30, 2020 Post the script where you tried to use stdoutread. Use the "< >" tags in the editor ribbon when posting code. CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
JoelG Posted September 30, 2020 Author Share Posted September 30, 2020 #include <Constants.au3> ; Request username Local $UserID = InputBox ( "Password Expiry Checker", "Please enter the username you want to check.") ; Set Net User command $NETCMD = 'NET USER ' & $UserID & ' /DOMAIN |FIND /I "Password expires"' ; Run Net User command Local $CMD = Run(@ComSpec & " /c " & $NETCMD,@SW_HIDE, $STDOUT_CHILD) ProcessWaitClose($CMD) ; Set PassExpiry from output of CMD Local $PassExpiry = StdoutRead($CMD) ; Output results MsgBox (64, "Password Expiry Checker", $UserID & " " & $PassExpiry) Link to comment Share on other sites More sharing options...
JoelG Posted September 30, 2020 Author Share Posted September 30, 2020 Thank you for your help BTW, meant to add that in my last reply.. Link to comment Share on other sites More sharing options...
TheXman Posted September 30, 2020 Share Posted September 30, 2020 (edited) 5 minutes ago, JoelG said: Run(@ComSpec & " /c " & $NETCMD,@SW_HIDE, $STDOUT_CHILD) You have @sw_hide where the working directory should be. Try: Run(@ComSpec & " /c " & $NETCMD, "", @SW_HIDE, $STDOUT_CHILD) If @error Then Exit MsgBox($MB_ICONERROR, "ERROR", "An error occurred executing command - @error = " & @error) You should also add error checking. If you had checked @error, you would have seen that you had a problem with the statement. Edited September 30, 2020 by TheXman JockoDundee 1 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
JoelG Posted September 30, 2020 Author Share Posted September 30, 2020 Yup, that was it. Sorry I didn't realize that was a required variable as I'm not really referencing the path in the command. Stupid mistake on my part. The following script is working as expected: #include <Constants.au3> Local $FilePath = @ScriptDir ; Request username Local $UserID = InputBox ( "Password Expiry Checker", "Please enter the username you want to check.") ; Set Net User command $NETCMD = 'NET USER ' & $UserID & ' /DOMAIN |FIND /I "Password expires"' ; Run Net User command Local $CMD = Run(@ComSpec & " /c " & $NETCMD,$FilePath, @SW_HIDE, $STDOUT_CHILD) ProcessWaitClose($CMD) ; Set PassExpiry from output of CMD Local $PassExpiry = StdoutRead($CMD) ; Output results MsgBox (64, "Password Expiry Checker", $UserID & " " & $PassExpiry) Link to comment Share on other sites More sharing options...
TheXman Posted September 30, 2020 Share Posted September 30, 2020 17 minutes ago, JoelG said: Thank you for your help BTW, meant to add that in my last reply. You're welcome! CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
JoelG Posted September 30, 2020 Author Share Posted September 30, 2020 Updated script with MsgBox in the event the account does not exist, in case this is useful form someone else: #include <Constants.au3> Local $FilePath = @ScriptDir ; Request username Local $UserID = InputBox ( "Password Expiry Checker", "Please enter the username you want to check.") ; Set Net User command $NETCMD = 'NET USER ' & $UserID & ' /DOMAIN |FIND /I "Password expires"' ; Run Net User command Local $CMD = Run(@ComSpec & " /c " & $NETCMD, $FilePath, @SW_HIDE, $STDOUT_CHILD) ProcessWaitClose($CMD) ; Set PassExpiry from output of CMD Local $PassExpiry = StdoutRead($CMD) ; Output results If $PassExpiry = "" then MsgBox (64, "Password Expiry Checker", "The " & $UserID & " account does not exist") Else MsgBox (64, "Password Expiry Checker", "The " & $UserID & " account " & $PassExpiry) EndIf Link to comment Share on other sites More sharing options...
JockoDundee Posted September 30, 2020 Share Posted September 30, 2020 2 hours ago, TheXman said: You have @sw_hide where the working directory should be. Good eye! Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Skysnake Posted October 27, 2020 Share Posted October 27, 2020 I had to read the output of a python script and could not manage. So, workaround was to have python dump it to text, set a flag and then get AutoIt to read the text and delete the flag. The "deleted flag" was the trigger for the next loop. Primitive, slow, very effective. Skysnake Why is the snake in the sky? Link to comment Share on other sites More sharing options...
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