heathy Posted July 9, 2007 Posted July 9, 2007 I'm making a small domain removal tool, nothing complicated. My first simple script worked just fine. If I was in the the domain it would remove my machine and give me the appropriate message. If I wasn't then it would tell me it would fail. #include <Constants.au3> FileInstall("C:\netdom.exe", @SystemDir & "\netdom.exe") $foo = Run(@ComSpec & " /c " & "netdom REMOVE " & @ComputerName, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $line = StdoutRead($foo) If @error Then ExitLoop If $line = "The command completed successfully." then MsgBox(0, "Progress", $line & " Click to Reboot") If $line <> "The command completed successfully." Then MsgBox(0, "Progress", "Process failed Remove from domain manually") Wend Exit So then I decided to try and make it a little more complex by trying to have the machine reboot after someone click the OK button after removal. The problem with this script is that it removes the machine from the domain but never puts up a MSG box stating anything. If I run it after the machine is out of the domain the second message box does show up. So I guess my issue is why isn't the message box showing up when it successfully removes itself from the domain. #include <Constants.au3> FileInstall("C:\netdom.exe", @SystemDir & "\netdom.exe") $foo = Run(@ComSpec & " /c " & "netdom REMOVE " & @ComputerName, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $line = StdoutRead($foo) If @error Then ExitLoop If $line = "The command completed successfully." then MsgBox(0, "Progress", $line & " Click to Reboot") Run(@ComSpec & " /c " & "shutdown -r -t 1") endif If $line <> "The command completed successfully." Then MsgBox(0, "Progress", "Process failed Remove from domain manually") exit endif Wend Exit Any help would be appreciated TIA
evilertoaster Posted July 9, 2007 Posted July 9, 2007 find out what it says from the console read- #include <Constants.au3> FileInstall("C:\netdom.exe", @SystemDir & "\netdom.exe") $foo = Run(@ComSpec & " /c " & "netdom REMOVE " & @ComputerName, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $line = StdoutRead($foo) MsgBox(0,"Line read",$line) If @error Then ExitLoop If $line = "The command completed successfully." then MsgBox(0, "Progress", $line & " Click to Reboot") Run(@ComSpec & " /c " & "shutdown -r -t 1") endif If $line <> "The command completed successfully." Then MsgBox(0, "Progress", "Process failed Remove from domain manually") exit endif Wend Exit see what the message box says
heathy Posted July 9, 2007 Author Posted July 9, 2007 Yeah I had done that. That's how I got the "The command completed successfully." originally. However it does appear that there are extra things in the output that don't show in the console. I change my code with While 1 $line = StdoutRead($foo) If @error Then ExitLoop MsgBox(0, "STDOUT read:", $line) Wend It came up with 2 boxes. So to solve my issue I changed "$line = StdoutRead($foo)" to $line = StdoutRead($foo,35) so it will only read the first 35 characters, which is "The command completed successfully." With that addition my script now works like I want it. If anyone cares, this is the code. Nothing special. #include <Constants.au3> FileInstall("C:\netdom.exe", @SystemDir & "\netdom.exe") $foo = Run(@ComSpec & " /c " & "netdom REMOVE " & @ComputerName, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $line = StdoutRead($foo, 35) If @error Then ExitLoop If $line = "The command completed successfully." then MsgBox(0, "Progress", $line & " Click to Reboot") Run(@ComSpec & " /c " & "shutdown -r -t 1") endif If $line <> "The command completed successfully." Then MsgBox(0, "Progress", "Process failed Remove from domain manually") exit endif Wend Exit
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