Guest Toaster-MTL Posted August 1, 2005 Posted August 1, 2005 When I run the following script $DestDomain = "DomainXYZ" $AdminGrpCode = runwait((@ComSpec & " /c " &'net localgroup Administrators "'&$DestDomain&"\"&@UserName&'" /add',"c:\") MsgBox(0,"Test",$AdminGrpCode) The "net localgroup" command always ends up failing with the error number 2, which according to "net helpmsg" means "The system cannot find the file specified." When I run this line from an interactive command prompt it works fine. I have even tried using the full path to net.exe (with and without the ComSpec portion) and have tried specifying c:\windows\system32 for the working directory. All return the same error. Oh yeah, the user running the script is already a memeber of the local administrators group.
HighGuy Posted August 1, 2005 Posted August 1, 2005 For easier debugging try to start the @ComSpec with "/k" instead of "/c". Then you can see the output of the net-command.
Guest Toaster-MTL Posted August 1, 2005 Posted August 1, 2005 For easier debugging try to start the @ComSpec with "/k" instead of "/c". Then you can see the output of the net-command.<{POST_SNAPBACK}>The /k option actually helped quite a bit. We are now able to see the "real" error code instead of the one returned by the RunWait command.However, I would like to check the error message programatically and that is proving difficult. When I try and redirect the output of the command into a file, the file is always empty. For instance I am using the following code:$AdminGrpCode = runwait(@ComSpec & " /k " &'net localgroup Administrators "'&$DestDomain&'\'&@UserName&'" /ADD 2>'&$SystemDrive&'\FCWin2K3\AddUser.txt') if $AdminGrpCode = 0 Then LogLine("Domain user added to local administrators group") Else $AdminGrpReturn = FileOpen($SystemDrive &"\FCWin2K3\AddUser.txt",2) $AdminGrpReturnVal = FileReadLine($AdminGrpReturn, 1) FileClose($AdminGrpReturn) LogLine("Adding domain user to local administrators group returned: "&$AdminGrpReturnVal) Crashed("Error adding user to local admin group: "&$AdminGrpReturnVal) EndIfThe AddUser.txt file is always 0 bytes and empty (when I use /k or /c). I have also tried $AdminGrpCode = runwait(@ComSpec & " /k " &'net localgroup Administrators "'&$DestDomain&'\'&@UserName&'" /ADD >'&$SystemDrive&'\FCWin2K3\AddUser.txt')with the same results. Any help would be greatly appreciated.
blindwig Posted August 1, 2005 Posted August 1, 2005 If the NET command isn't working, then it's probably outputting to the ErrOut instead of StdOut. To redirect ErrOut, use "2>(filename)" instead of just ">(filename)" My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions
Guest Toaster-MTL Posted August 2, 2005 Posted August 2, 2005 If the NET command isn't working, then it's probably outputting to the ErrOut instead of StdOut. To redirect ErrOut, use "2>(filename)" instead of just ">(filename)"<{POST_SNAPBACK}>If you take a look at the coderunwait(@ComSpec & " /k " &'net localgroup administrators "'&$DestDomain&'\'&@UserName&'" /ADD 2>'&$SystemDrive&'\FCWin2K3\AddUser.txt')I am using the 2> format to capture ErrOut, but still the file is empty after the command completes with an error.
DaveF Posted August 2, 2005 Posted August 2, 2005 I don't have access to a MS domain, so I can't dynamically test your code, Toaster-MTL, but as a guess I'm saying that it's either the child FCWin2K3 folder isn't being created or the $SystemDrive variable is not being assigned correctly. When in doubt I'll pop open a MsgBox with such a filesystem path to see if it's being built right...If you're in a situation where it's permissable to use the beta version of AutoIt3, you can call NET.EXE (+ its command line args) directly with Run(), then use the StdoutRead and StderrRead functions to capture any output to strings and test the content of the strings to determine your results. If you still want a permanent record for log purposes you can write the result to the system registry or a file or whatever... Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.
Guest Toaster-MTL Posted August 2, 2005 Posted August 2, 2005 I don't have access to a MS domain, so I can't dynamically test your code, Toaster-MTL, but as a guess I'm saying that it's either the child FCWin2K3 folder isn't being created or the $SystemDrive variable is not being assigned correctly. When in doubt I'll pop open a MsgBox with such a filesystem path to see if it's being built right...If you're in a situation where it's permissable to use the beta version of AutoIt3, you can call NET.EXE (+ its command line args) directly with Run(), then use the StdoutRead and StderrRead functions to capture any output to strings and test the content of the strings to determine your results. If you still want a permanent record for log purposes you can write the result to the system registry or a file or whatever...<{POST_SNAPBACK}>The FCWin2K3 folder is created and the $SystemDrive variable is properly set (there are several functions that use both those items not listed in the code I published), so that's not the issue.However your suggestion about using the beta with StoutRead and SterrRead is a really good idea. I'll look into it.Is the beta considered stable at this point?
DaveF Posted August 2, 2005 Posted August 2, 2005 Is the beta considered stable at this point?Hmm. I think "beta" says it most honestly; there are some known bugs and there are new features still being added that might break. The StdxxxYyy code itself is pretty insular and has been in the beta since February, I guess, and has had its share of fixes and "makes sense" changes in behavior. I'd declare it fairly stable by now.If you haven't played with the beta you don't know what you're missing. Most of the buzz on this forum is about stuff with COM, DLL calls and GUI construction that you need the beta to do... Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.
blademonkey Posted August 3, 2005 Posted August 3, 2005 (edited) If you take a look at the coderunwait(@ComSpec & " /k " &'net localgroup administrators "'&$DestDomain&'\'&@UserName&'" /ADD 2>'&$SystemDrive&'\FCWin2K3\AddUser.txt')I am using the 2> format to capture ErrOut, but still the file is empty after the command completes with an error.<{POST_SNAPBACK}>Have you tried doing arunwait(@ComSpec & " /k " &'net localgroup administrators "'&$DestDomain&'\'&@UserName&'" /ADD >'&$SystemDrive&'\FCWin2K3\AddUser.txt' & ' 2>&1') Redirects both standard output and standard err to the file. Edited August 3, 2005 by blademonkey ---"Educate the Mind, Make Savage the Body" -Mao Tse Tung
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