{"id":67263,"date":"2006-05-23T11:18:00","date_gmt":"2006-05-23T11:18:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2006\/05\/23\/how-can-i-rename-a-user-account-in-a-windows-nt-4-0-domain\/"},"modified":"2006-05-23T11:18:00","modified_gmt":"2006-05-23T11:18:00","slug":"how-can-i-rename-a-user-account-in-a-windows-nt-4-0-domain","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-rename-a-user-account-in-a-windows-nt-4-0-domain\/","title":{"rendered":"How Can I Rename a User Account in a Windows NT 4.0 Domain?"},"content":{"rendered":"<p><P>Hey, Scripting Guy! How can I rename a user account in a Windows NT 4.0 domain?<BR><BR>&#8212; JK<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, JK. You know, as this column is being written it\u2019s a Monday here in Seattle, and it\u2019s raining. And yes, we know what you\u2019re thinking: when <I>isn\u2019t<\/I> it raining in Seattle? Unfortunately, though, our weather is much crueler than that. After all, if it rained all the time you could plan for that and get used to it. In Seattle, though, we tend to have three or four absolutely gorgeous days: sunshine, blue skies, highs in the 80s. It\u2019s only then, just about the time you think that summer has arrived, that it rains. And rains. And, well, rains.<\/P>\n<P>And then, of course, it gets nice for a couple of days, we start to get our hopes up, and then the same vicious cycle repeats itself.<\/P>\n<P>Of course, there are two things you can do when the weather acts up like this. One thing you can do is sit around and mope, bemoaning the fate that has befallen you and doing as little work as possible. On the other hand, you can always take advantage of the opportunity and &#8211; with nothing to distract you &#8211; tackle one of those challenging problems that you\u2019ve been meaning to tackle for a long, long time. <\/P>\n<P>We\u2019ve chosen to mope.<\/P><PRE class=\"codeSample\">Set objDomain = GetObject(&#8220;WinNT:\/\/fabrikam&#8221;) \nSet objUser = GetObject(&#8220;&#8221;WinNT:\/\/fabrikam\/kmyer&#8221;) \nobjDomain.MoveHere objUser.AdsPath, &#8220;kenmyer&#8221;\n<\/PRE>\n<P>You can see why we chose to answer this question: all we had to do was write three lines of code and then we could go back to feeling sorry for ourselves. We start off by creating a pair of object references, one to the domain (objDomain) and one to the user account that we want to rename (objUser). That\u2019s what we do here:<\/P><PRE class=\"codeSample\">Set objDomain = GetObject(&#8220;WinNT:\/\/fabrikam&#8221;) \nSet objUser = GetObject(&#8220;&#8221;WinNT:\/\/fabrikam\/kmyer&#8221;)\n<\/PRE>\n<P>And here\u2019s the best part. After we\u2019ve connected to the domain and to the user account it takes just one line of code to rename that account:<\/P><PRE class=\"codeSample\">objDomain.MoveHere objUser.AdsPath, &#8220;kenmyer&#8221;\n<\/PRE>\n<P>As you can see, all we do is call the <B>MoveHere<\/B> method and specify two parameters:<\/P>\n<TABLE border=\"0\" cellSpacing=\"0\" cellPadding=\"0\">\n<TBODY>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P>The <B>AdsPath<\/B> to the user account. The AdsPath uniquely identifies a user account in much the same way a UNC path uniquely identifies a file. For example, the UNC path \\\\atl-fs-01\\public\\test.txt can refer to only one file: a file named Test.txt found in the Public folder on the computer atl-ws-01. Likewise the AdsPath WinNT:\/\/fabrikam\/kmyer can refer to only one user account: an account named kmyer located in the Fabrikam domain.<\/P><\/TD><\/TR>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P>The new name (<B>kenmyer<\/B>) to be given to the user account.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<P>And that\u2019s it: call the method, and the kmyer user account will immediately be renamed kenmyer. <\/P>\n<P>A few things to keep in mind here. First, neither Windows Script Host nor ADSI were available when Windows NT 4.0 first shipped. If you haven\u2019t already done so this script won\u2019t work unless you install both technologies on your domain controller. For more information, check out the <A href=\"http:\/\/null\/technet\/scriptcenter\/scrptfaq.mspx\"><B>Script Center FAQ<\/B><\/A>.<\/P>\n<P>Second, this script <I>will<\/I> work with Active Directory user accounts; it\u2019s not limited to just NT 4.0 domains. We don\u2019t really recommend you use this with Active Directory; with a few rare exceptions you should always use the LDAP provider (as opposed to the WinNT provider) when working with Active Directory. If you have no idea what we\u2019re talking about, don\u2019t feel bad: nobody <I>ever<\/I> has any idea what we\u2019re talking about! But you can find a reasonably good explanation of ADSI providers (as well as which one to use, and when) in the <A href=\"http:\/\/null\/technet\/scriptcenter\/guide\/sas_ads_llyj.mspx\" target=\"_blank\"><B>Microsoft Windows 2000 Scripting Guide<\/B><\/A>.<\/P>\n<P>Finally, this script will <I>not<\/I> enable you to rename a local user account; instead it will fail with an \u201cunspecified error\u201d error message. So what do you do if you have the urge to rename local user accounts, at least on a Windows XP or a Windows Server 2003 computer? This <A href=\"http:\/\/null\/technet\/scriptcenter\/resources\/qanda\/may06\/hey0517.mspx\"><B>Hey, Scripting Guy!<\/B><\/A> column should help.<\/P>\n<P>We should also mention that we agree with you: it <I>is<\/I> a bit odd that you use a method named MoveHere to rename a user account. Why don\u2019t you just use something like, oh, say, Rename? That\u2019s a question we can\u2019t answer. The best we can do is tell you not to worry about it. The syntax might seem a little strange, but it works. And that\u2019s all we really care about anyway.<\/P>\n<P>In the meantime, let\u2019s check tomorrow\u2019s forecast:<\/P><PRE class=\"codeSample\">Cloudy with showers. High 62F. Winds S at 10 to 15 mph. Chance of rain 60%.\n<\/PRE>\n<P>Wonderful. Word of warning: if you thought today\u2019s column was filled with self-pity just wait until you see <I>tomorrow\u2019s<\/I>. We had a little bit of rain on Saturday, a lot of rain on Sunday, rain today, and a 60% chance of rain tomorrow. There\u2019s just nothing like Seattle in the summertime, is there?<I> (Editor\u2019s Note: It\u2019s actually still spring, which might explain this if it weren\u2019t for the fact that summer works pretty much the same way.)<\/I><\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I rename a user account in a Windows NT 4.0 domain?&#8212; JK Hey, JK. You know, as this column is being written it\u2019s a Monday here in Seattle, and it\u2019s raining. And yes, we know what you\u2019re thinking: when isn\u2019t it raining in Seattle? Unfortunately, though, our weather is much [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[23,24,3,5],"class_list":["post-67263","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-local-accounts-and-windows-nt-4-0-accounts","tag-other-directory-services","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I rename a user account in a Windows NT 4.0 domain?&#8212; JK Hey, JK. You know, as this column is being written it\u2019s a Monday here in Seattle, and it\u2019s raining. And yes, we know what you\u2019re thinking: when isn\u2019t it raining in Seattle? Unfortunately, though, our weather is much [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/67263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=67263"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/67263\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=67263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=67263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=67263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}