{"id":65503,"date":"2007-02-16T00:51:00","date_gmt":"2007-02-16T00:51:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2007\/02\/16\/how-can-i-get-the-full-name-of-a-windows-nt-4-0-user-when-all-i-have-is-their-logon-name\/"},"modified":"2007-02-16T00:51:00","modified_gmt":"2007-02-16T00:51:00","slug":"how-can-i-get-the-full-name-of-a-windows-nt-4-0-user-when-all-i-have-is-their-logon-name","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-get-the-full-name-of-a-windows-nt-4-0-user-when-all-i-have-is-their-logon-name\/","title":{"rendered":"How Can I Get the Full Name of a Windows NT 4.0 User When All I Have is Their Logon Name?"},"content":{"rendered":"<p><H2><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" height=\"34\" alt=\"Hey, Scripting Guy! Question\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"> <\/H2>\n<P>Hey, Scripting Guy! How can I determine the full name of a user in a Windows NT 4.0 domain when all I have is the user\u2019s logon name?<BR><BR>&#8212; NH<\/P><IMG height=\"5\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" border=\"0\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" height=\"34\" alt=\"Hey, Scripting Guy! Answer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" height=\"288\" alt=\"Script Center\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" align=\"right\" border=\"0\"><\/A> \n<P>Hey, NH. In case you\u2019re wondering, after a less-than-auspicious beginning the Scripting Guy who writes this column started to get used to <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/resources\/qanda\/feb07\/hey0207.mspx\"><B>swimming laps<\/B><\/A> every night; in fact, he even started to enjoy the experience a little. Of course, no sooner did he do so than the Scripting Son came up with a new idea: core training. \u201cThat\u2019s what everyone does,\u201d remarked the Scripting Son. \u201cDon\u2019t you want to have a strong core?\u201d<\/P>\n<P>Well, to be perfectly honest: no. After all, the Scripting Dad has survived this long without having a strong core; surely he could get by for at least a <I>little<\/I> while longer with a weak core.<\/P>\n<P>He became even <I>more<\/I> convinced of this after he found out what it actually meant to do core training. As near as he can tell, core training primarily involves contorting your body into an unnatural position, having someone stick a 25-pound weight on you, and then holding that position until you pass out or until time is up. For example, in one exercise you get down into a sort of pushup-like position, balancing on your toes and forearms. The Scripting Son then plops a 25-pound weight on your back and tells you to hold yourself up for 1 minute.<\/P>\n<P>Admittedly, that doesn\u2019t <I>sound<\/I> too bad, although it is. But it\u2019s still something even the Scripting Guy who writes this column can handle. It only starts to get bad when the Scripting Son says, \u201cYou know, I can do 2 minutes.\u201d And then the Scripting Dad says, \u201cWhat, just 2? I can do 3 \u2013 no, wait: I can do <I>4<\/I>!\u201d <\/P>\n<P>We don\u2019t know if any of you have ever had the desire to see a Scripting Guy cry, but, if you do, just swing by the gym some night when he\u2019s trying to do 4 minutes.<\/P>\n<P>Or, if you prefer, swing by his office on the day he gets his performance review. Either way he\u2019s bound to be crying.<\/P>\n<P>Of course, we\u2019d hate to see <I>you<\/I> cry, NH. So here\u2019s a script that reports back the full name of a user (<I>Ken Myer<\/I>) when all you have is the user\u2019s logon name (<I>kenmyer<\/I>):<\/P><PRE class=\"codeSample\">strDomain = &#8220;fabrikam&#8221;\nstrUserName = &#8220;kenmyer&#8221;<\/p>\n<p>Set objUser = GetObject(&#8220;WinNT:\/\/&#8221; &amp; strDomain &amp; &#8220;\/&#8221; &amp; strUserName)\nWscript.Echo objUser.FullName\n<\/PRE>\n<P>Yes, it <I>is<\/I> a very simple little script. (And not by coincidence: thanks to the <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/funzone\/games\/default.mspx\"><B>Scripting Games<\/B><\/A> we were looking for something we could answer quickly and easily.) To start off with we simply assign values to a pair of variables: strDomain gets the name of our domain and strUserName gets the logon name of our user. We then use this line of code to bind directly to the user account in the NT 4.0 domain:<\/P><PRE class=\"codeSample\">Set objUser = GetObject(&#8220;WinNT:\/\/&#8221; &amp; strDomain &amp; &#8220;\/&#8221; &amp; strUserName)\n<\/PRE>\n<P>Once we\u2019ve made the connection we need just one more line of code to report back the user\u2019s <B>FullName<\/B>:<\/P><PRE class=\"codeSample\">Wscript.Echo objUser.FullName\n<\/PRE>\n<P>And that\u2019s it; that\u2019s all we have to do.<\/P>\n<P>Of course, we should note that, as an added bonus, this very same script can be used to retrieve the full name of a local user; in that case, you simply bind to the SAM (security account manager) on a computer as opposed to a domain. Here\u2019s pretty much the same script we just showed you, slightly revised to work with local user accounts:<\/P><PRE class=\"codeSample\">strComputer = &#8220;fabrikam&#8221;\nstrUserName = &#8220;kenmyer&#8221;<\/p>\n<p>Set objUser = GetObject(&#8220;WinNT:\/\/&#8221; &amp; strComputer &amp; &#8220;\/&#8221; &amp; strUserName)\nWscript.Echo objUser.FullName\n<\/PRE>\n<P>If that looks vaguely familiar, well, it should: all we did was change the name of the variable strDomain to strComputer. Other than that \u2026.<\/P>\n<P>While we\u2019re on the subject, the flip side to this question is this: if all I have is the user\u2019s full name how can I get his or her logon name? <\/P>\n<TABLE class=\"dataTable\" id=\"EZE\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD class=\"\">\n<P><B>Note<\/B>. In this era of CDs and DVDs does anyone even know what we\u2019re talking about when we say \u201cflip side?\u201d<\/P>\n<P>That\u2019s a good point: nobody <I>ever<\/I> knows what we\u2019re talking about when it comes to this column, do they?<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>OK, so how <I>do<\/I> you get the logon name if all you have is the full name? Well, with an Active Directory domain the answer would be obvious: you\u2019d do an ADO search on the domain. Unfortunately, you can\u2019t search for user accounts in an NT 4.0 domain or a local SAM. Fortunately, though, that doesn\u2019t mean you can\u2019t locate a particular user, it just means you have to go about it like this:<\/P><PRE class=\"codeSample\">strDomain = &#8220;fabrikam&#8221;<\/p>\n<p>Set colAccounts = GetObject(&#8220;WinNT:\/\/&#8221; &amp; strDomain &amp; &#8220;&#8221;)\ncolAccounts.Filter = Array(&#8220;user&#8221;)<\/p>\n<p>For Each objUser In colAccounts\n    If objUser.FullName = &#8220;Ken Myer&#8221; Then\n        Wscript.Echo objUser.Name \n        Exit For\n    End If  \nNext\n<\/PRE>\n<P>What we\u2019re doing with this script is, first of all, binding to the domain itself; notice that we don\u2019t specify a user account in our binding string:<\/P><PRE class=\"codeSample\">Set colAccounts = GetObject(&#8220;WinNT:\/\/&#8221; &amp; strDomain &amp; &#8220;&#8221;)\n<\/PRE>\n<P>After making the connection we then set the <B>Filter<\/B> property to <I>user<\/I>; this ensures that our collection will contain only user accounts, weeding out groups, printers, services, and other entities that might otherwise be there. That\u2019s what we do here (and, yes, values to the Filter property must be passed as an array, even if we\u2019re filtering on only one object type):<\/P><PRE class=\"codeSample\">colAccounts.Filter = Array(&#8220;user&#8221;)\n<\/PRE>\n<P>We then set up a For Each loop to walk through the entire collection. Inside that loop we check each individual user account to see if the FullName property is equal <I>Ken Myer<\/I>. If it is, then we echo back the value of the <B>Name<\/B> property and then exit the loop. If it isn\u2019t, then we loop around and try again with the next account. That\u2019s what this block of code does:<\/P><PRE class=\"codeSample\">If objUser.FullName = &#8220;Ken Myer&#8221; Then\n    Wscript.Echo objUser.Name \n    Exit For\nEnd If\n<\/PRE>\n<P>Admittedly, it\u2019s not as cool as doing an ADO search, but it\u2019s the best we <I>can<\/I> do. And it will work, both with NT 4.0 domains and with local users.<\/P>\n<P>We see you have another question. The answer to that one is no: you do <I>not<\/I> need to have a strong core in order to enter the <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/funzone\/games\/default.mspx\"><B>2007 Winter Scripting Games<\/B><\/A>, and have a shot at winning a <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/funzone\/games\/games07\/bobble.mspx\"><B>Dr. Scripto Bobblehead doll<\/B><\/A> or a copy of the book <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/topics\/msh\/payette1.mspx\"><B>Windows PowerShell in Action<\/B><\/A>. (Well, not unless you usually write scripts with 25-pound weights strapped to your back.) Just enter an event (any event) and you\u2019ll automatically be entered in the drawing for one of those prizes. Score 60 points in any one division and you\u2019ll earn a Certificate of Excellence signed by the Scripting Guys. Pretty cool, huh?<\/P>\n<TABLE class=\"dataTable\" id=\"E6G\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD class=\"\">\n<P class=\"lastInCell\"><B>Note<\/B>. Why are we giving away Certificates of Excellence? Well, as it turned out, awhile back we bought a whole bunch of these awards, the idea being that we would hand them out to each other every time we did something really good. Let\u2019s just say that we have plenty of certificates left over \u2026.<\/P><\/TD><\/TR><\/TBODY><\/TABLE><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I determine the full name of a user in a Windows NT 4.0 domain when all I have is the user\u2019s logon name?&#8212; NH Hey, NH. In case you\u2019re wondering, after a less-than-auspicious beginning the Scripting Guy who writes this column started to get used to swimming laps every night; [&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-65503","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 determine the full name of a user in a Windows NT 4.0 domain when all I have is the user\u2019s logon name?&#8212; NH Hey, NH. In case you\u2019re wondering, after a less-than-auspicious beginning the Scripting Guy who writes this column started to get used to swimming laps every night; [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/65503","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=65503"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/65503\/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=65503"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=65503"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=65503"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}