cottage Posted April 9, 2006 Posted April 9, 2006 I'm working on a simple script that includes the 'net user' command. I would like to use the "/fullname:" option of the net user command within my script. However if my "/fullname:" option contains a space (example: bill smith) the account is not created. Assigning "bill smith" to the $techname string prevents the account from being created. Using four strings, one for the first name, a second for a space, a third for the last name and then combining them into a fourth string called $techname still prevents the account from being created. Following some other lines of autoit code (not listed here), my net user command line looks like this: RunWait(@Comspec & " /C " & " net user " & $username & "t6y7u*" & " /add " & " /fullname:" & $techname) Where am I going wrong? Any advise is greatly appreciated !! Bill
Valuater Posted April 9, 2006 Posted April 9, 2006 ********NOT TESTED $Run_String = FileGetShortName($username & "t6y7u*" & " /add " & " /fullname:" & $techname) RunWait(@Comspec & " /C " & " net user " & $Run_String ) 8)
cottage Posted April 9, 2006 Author Posted April 9, 2006 ********NOT TESTED $Run_String = FileGetShortName($username & "t6y7u*" & " /add " & " /fullname:" & $techname) RunWait(@Comspec & " /C " & " net user " & $Run_String ) 8)Thanks for the super fast reply. However that didn't seem to make any difference. No account was created substituting your code.
billmez Posted April 9, 2006 Posted April 9, 2006 I'm working on a simple script that includes the 'net user' command. I would like to use the "/fullname:" option of the net user command within my script. However if my "/fullname:" option contains a space (example: bill smith) the account is not created. Assigning "bill smith" to the $techname string prevents the account from being created. Using four strings, one for the first name, a second for a space, a third for the last name and then combining them into a fourth string called $techname still prevents the account from being created. Following some other lines of autoit code (not listed here), my net user command line looks like this: RunWait(@Comspec & " /C " & " net user " & $username & "t6y7u*" & " /add " & " /fullname:" & $techname) Where am I going wrong? Any advise is greatly appreciated !! Bill Try this: RunWait(@Comspec & " /C " & " net user " & '"' & $username & '"' & " t6y7u*" & " /add " & " /fullname:" & $techname) It should put quotes around the $username. Note that I also added a space infront of t6y7u* to separate it on the command line form the user name. Let me know if it works.
cottage Posted April 9, 2006 Author Posted April 9, 2006 Try this: RunWait(@Comspec & " /C " & " net user " & '"' & $username & '"' & " t6y7u*" & " /add " & " /fullname:" & $techname) It should put quotes around the $username. Note that I also added a space infront of t6y7u* to separate it on the command line form the user name. Let me know if it works.The only part of my script that doesn't work correctly is the "/fullname:" option of the 'net user' command. All other parts of the line work correctly. I can create the user, I can add the password, however I cannot get it to use the "/fullname:" option correctly. If the fullname was "bill smith", as soon as the net user command sees the space between bill and smith, it errors out. Without using AutoIt, typing straight from the command line: user 'username' 'password' /add /fullname:"bill smith" works. However WITHIN autoit, I want to use a string ($techname) to pass the fullname (bill smith) to the command line. For whatever reason AutoIt doesn't seem to like using Net User /fullname: within a script. If the name was together, such as "BillSmith", it works. However 'Bill Smith' doesn't.
billmez Posted April 9, 2006 Posted April 9, 2006 (edited) The only part of my script that doesn't work correctly is the "/fullname:" option of the 'net user' command. All other parts of the line work correctly. I can create the user, I can add the password, however I cannot get it to use the "/fullname:" option correctly. If the fullname was "bill smith", as soon as the net user command sees the space between bill and smith, it errors out. Without using AutoIt, typing straight from the command line: user 'username' 'password' /add /fullname:"bill smith" works. However WITHIN autoit, I want to use a string ($techname) to pass the fullname (bill smith) to the command line. For whatever reason AutoIt doesn't seem to like using Net User /fullname: within a script. If the name was together, such as "BillSmith", it works. However 'Bill Smith' doesn't. Did you try what I suggested? It appears there may have been a problem with your spacing too in your example: & $username & "t6y7u*" would have the username and password as one string since there is no space after the quote. This may be your problem, not the /fullname parameter. In your command line exampel you are also enclosing the username and password in quotes, which you are not doing in your AutoIt example. Note my suggestion above does enclose the username in double quotes. [edit] You can also use the /k parameter instead of /c to leave the command window open and see what it says after you try to execute the AutoIt script. [/edit] Edited April 9, 2006 by billmez
PsaltyDS Posted April 9, 2006 Posted April 9, 2006 (edited) The only part of my script that doesn't work correctly is the "/fullname:" option of the 'net user' command. All other parts of the line work correctly. I can create the user, I can add the password, however I cannot get it to use the "/fullname:" option correctly. If the fullname was "bill smith", as soon as the net user command sees the space between bill and smith, it errors out. Without using AutoIt, typing straight from the command line: user 'username' 'password' /add /fullname:"bill smith" works. However WITHIN autoit, I want to use a string ($techname) to pass the fullname (bill smith) to the command line. For whatever reason AutoIt doesn't seem to like using Net User /fullname: within a script. If the name was together, such as "BillSmith", it works. However 'Bill Smith' doesn't. I'm assuming you still aren't getting the double quotes right around your parameters, so I took a stab at it: $Result = RunWait(@Comspec & ' /C net user "' & $UserName & '" "' & $PassWord & '" /add /fullname:"' & $TechName & '"') Note I changed all the AutoIT quotes to single quotes. Where you want double quotes in the CMD line, they are inside the single quotes, and I added the one at the end. There should now be double quotes around $UserName, $PassWord, and $TechName. The $Result variable catches the ErrorLevel from the NET USER command. $Result = 0 is good. You can test things like this in a couple of additional ways, too: 1) Change the /c to /k so the CMD shell is left open to see the errors that might come up. 2) Change the string you are creating into a message box, just to see that it comes out the way you wanted: MsgBox(64, "Debug", @Comspec & ' /C net user "' & $UserName & '" "' & $PassWord & '" /add /fullname:"' & $TechName & '"') Of course, I didn't do either since I'm not on a windows box right now... Edit: Ok, billmez was typing faster than I was, but at least I beat Valuater! :-) Edited April 9, 2006 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Valuater Posted April 9, 2006 Posted April 9, 2006 maybe you could test you spacing and quotes with this MsgBox(0, "", " net user " & '"' & $username & '"' & " t6y7u*" & " /add " & " /fullname:" & $techname) 8)
cottage Posted April 9, 2006 Author Posted April 9, 2006 (edited) I'm assuming you still aren't getting the double quotes right around your parameters, so I took a stab at it: $Result = RunWait(@Comspec & ' /C net user "' & $UserName & '" "' & $PassWord & '" /add /fullname:"' & $TechName & '"') Note I changed all the AutoIT quotes to single quotes. Where you want double quotes in the CMD line, they are inside the single quotes, and I added the one at the end. There should now be double quotes around $UserName, $PassWord, and $TechName. The $Result variable catches the ErrorLevel from the NET USER command. $Result = 0 is good. You can test things like this in a couple of additional ways, too: 1) Change the /c to /k so the CMD shell is left open to see the errors that might come up. 2) Change the string you are creating into a message box, just to see that it comes out the way you wanted: MsgBox(64, "Debug", @Comspec & ' /C net user "' & $UserName & '" "' & $PassWord & '" /add /fullname:"' & $TechName & '"') Of course, I didn't do either since I'm not on a windows box right now... Edit: Ok, billmez was typing faster than I was, but at least I beat Valuater! :-)That was the trick PsaltyDS!!!!! Thanks a million. My quotes weren't in the correct place obviously. And thanks to everyone else that responsed to this so quickly. Anyone have an answer for this one... it's not about AutoIt directly, however it is this same script. I want to force a password change on first login once this new account has been created. I've tried all sorts of ways with the net user command but can't find the one that sets ""User must change password at next logon". Thanks again for the help on my code thus far. Edited April 9, 2006 by cottage
billmez Posted April 9, 2006 Posted April 9, 2006 That was the trick PsaltyDS!!!!! Thanks a million. My quotes weren't in the correct place obviously. And thanks to everyone else that responsed to this so quickly.Anyone have an answer for this one... it's not about AutoIt directly, however it is this same script. I want to force a password change on first login once this new account has been created. I've tried all sorts of ways with the net user command but can't find the one that sets ""User must change password at next logon". Thanks again for the help on my code thus far.Look here: http://www.microsoft.com/resources/documen...r.mspx?mfr=true
cottage Posted April 9, 2006 Author Posted April 9, 2006 Look here: http://www.microsoft.com/resources/documen...r.mspx?mfr=trueThanks billmez... I've been checking all over the web (including this link) for a way to force a password change from the command line (via net user). Haven't had any luck yet though. As you are probably aware, if you create a new account using XP and 'Manage'. You never run into trouble because the system puts a tick mark in the "User must change password on next logon" box automatically. I haven't found a way to do this from the command line with net user.
billmez Posted April 9, 2006 Posted April 9, 2006 (edited) Thanks billmez... I've been checking all over the web (including this link) for a way to force a password change from the command line (via net user). Haven't had any luck yet though. As you are probably aware, if you create a new account using XP and 'Manage'. You never run into trouble because the system puts a tick mark in the "User must change password on next logon" box automatically. I haven't found a way to do this from the command line with net user.I don't believe you can as I think it is a system (or local) policy. You may be able to change the policy through WMI, but I doubt the net command line too will help. Of couse any policy change will not just apply to the new user you are creating. Edited April 9, 2006 by billmez
cottage Posted April 9, 2006 Author Posted April 9, 2006 I don't believe you can as I think it is a system (or local) policy. You may be able to change the policy through WMI, but I doubt the net command line too will help. Of course any policy change will not just apply to the new user you are creating.Thought maybe so. Sure is strange that you can set a new account to not require a password, or set it to have the password never expire via the command line. You just can't force a password change on the first logon from the command line. Oh well, with everyone's help, one success tonight was GREAT!
PsaltyDS Posted April 9, 2006 Posted April 9, 2006 (edited) Look here: http://www.microsoft.com/resources/documen...r.mspx?mfr=true I don't think "Change password at next logon" is one of the options you can set from NET USER. JdeB hooked me up with the following in thread #23470: ; Init objects $UserName = 'Fred' $Password = 'Wil"ma' $oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler $strComputer = @ComputerName $colAccounts = ObjGet("WinNT://" & $strComputer & "") $objUser = $colAccounts.Create("user", $UserName) $objUser.SetPassword ($Password) $objUser.Put ("Fullname", "Test User") $objUser.Put ("Description", "Test User description") $objUser.SetInfo This avoids the CMD shell and instead calls the Windows API for local user manager and adds a user with password, full name, and description. Per this TechNet article, you can also add a change the pwdLastSet object to 0, which forces the password change: objUser.Put "pwdLastSet", 0 So your whole user add becomes: ; Init objects $UserName = 'Fred' $Password = 'Wil"ma' $oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler $strComputer = @ComputerName $colAccounts = ObjGet("WinNT://" & $strComputer & "") $objUser = $colAccounts.Create("user", $UserName) $objUser.SetPassword ($Password) $objUser.Put ("Fullname", "Test User") $objUser.Put ("Description", "Test User description") $objUser.Put ("pwdLastSet", "0"); Set "Change password on next logon" $objUser.SetInfo Some things you just can't do from the CMD shell... Edit: Tweaked out some unnecesary comments. Edited April 9, 2006 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
cottage Posted April 9, 2006 Author Posted April 9, 2006 I don't think "Change password at next logon" is one of the options you can set from NET USER.PsaltyDS,Thanks again for all the good code and for your assistance. It has certainly help with my scripting. Tomorrow will tell the true story - if my code will work correctly in the real world! :-)Again thanks!Bill
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