<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Hey, Scripting Guy! How Can I Get the Name of the Last User to Log on to a Computer?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2007/01/24/how-can-i-get-the-name-of-the-last-user-to-log-on-to-a-computer.aspx</link><description>Hey, Scripting Guy! How can I get the name of the last user to log on to a computer? -- SV 
 
 Hey, SV. You know, the Scripting Guy who writes this column never watches the news on TV. (OK, sports news being the one exception.) That&amp;rsquo;s not because</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Hey, Scripting Guy! How Can I Get the Name of the Last User to Log on to a Computer?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2007/01/24/how-can-i-get-the-name-of-the-last-user-to-log-on-to-a-computer.aspx#3561646</link><pubDate>Thu, 28 Mar 2013 19:57:25 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3561646</guid><dc:creator>Al Rawlins</dc:creator><description>&lt;p&gt;Pre Windows 7, I used to use the DefaultUserName to determine who was logged on. &amp;nbsp;If explorer.exe was running, then the DefaultUserName would tell you who was currently logged on. &amp;nbsp;Then I tried this on Windows 7 and only sometimes is this value populated. &amp;nbsp;It also did not tell you if there was more than one user logged on. &amp;nbsp;Instead, I use the owner of the Explorer.exe process. &amp;nbsp;There is always at least one explorer.exe process for every usesr that logs on. &amp;nbsp;Here is the code I use:&lt;/p&gt;
&lt;p&gt;Function WhosLoggedOnTS(strComputer)&lt;/p&gt;
&lt;p&gt;	on error resume next&lt;/p&gt;
&lt;p&gt;	dim strUsers&lt;/p&gt;
&lt;p&gt;	dim objWMIService&lt;/p&gt;
&lt;p&gt;	dim colProcessList&lt;/p&gt;
&lt;p&gt;	dim objProcess&lt;/p&gt;
&lt;p&gt;	dim strNameOfUser&lt;/p&gt;
&lt;p&gt;	dim strUserDomain&lt;/p&gt;
&lt;p&gt;	dim colProperties&lt;/p&gt;
&lt;p&gt;	strUsers=&amp;quot;&amp;quot;&lt;/p&gt;
&lt;p&gt;	Set objWMIService = GetObject(&amp;quot;winmgmts:&amp;quot; &amp;amp; &amp;quot;{impersonationLevel=impersonate}!\\&amp;quot; &amp;amp; strComputer &amp;amp; &amp;quot;\root\cimv2&amp;quot;)&lt;/p&gt;
&lt;p&gt;	Set colProcessList = objWMIService.ExecQuery(&amp;quot;Select * from Win32_Process&amp;quot;)&lt;/p&gt;
&lt;p&gt;	For Each objProcess in colProcessList&lt;/p&gt;
&lt;p&gt;	 &amp;nbsp; &amp;nbsp;colProperties = objProcess.GetOwner(strNameOfUser,strUserDomain)&lt;/p&gt;
&lt;p&gt;	 &amp;nbsp; &amp;nbsp;If objProcess.Name = &amp;quot;explorer.exe&amp;quot; then&lt;/p&gt;
&lt;p&gt;	 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;strUsers = strUsers &amp;amp; strNameOfUser &amp;amp; &amp;quot;,&amp;quot; &amp;amp; GetFullName(strNameOfUser)&lt;/p&gt;
&lt;p&gt;	 &amp;nbsp; &amp;nbsp;End If&lt;/p&gt;
&lt;p&gt;	Next&lt;/p&gt;
&lt;p&gt;	If strUsers=&amp;quot;&amp;quot; then&lt;/p&gt;
&lt;p&gt;		strUsers=&amp;quot;Logged Off&amp;quot;&lt;/p&gt;
&lt;p&gt;	End If&lt;/p&gt;
&lt;p&gt;	Set objWMIService=Nothing&lt;/p&gt;
&lt;p&gt;	Set colProcessList=Nothing&lt;/p&gt;
&lt;p&gt;	Set objProcess=Nothing&lt;/p&gt;
&lt;p&gt;	WhosLoggedOnTS=strUsers&lt;/p&gt;
&lt;p&gt;End Function&lt;/p&gt;
&lt;p&gt;Now I&amp;#39;ve been asked to find a way to determine who was last logged on......&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3561646" width="1" height="1"&gt;</description></item><item><title>re: Hey, Scripting Guy! How Can I Get the Name of the Last User to Log on to a Computer?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2007/01/24/how-can-i-get-the-name-of-the-last-user-to-log-on-to-a-computer.aspx#3543959</link><pubDate>Thu, 03 Jan 2013 21:57:27 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3543959</guid><dc:creator>SimonTan</dc:creator><description>&lt;p&gt;You can also sort the user profiles by modifed date and get the last logged on user that way.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3543959" width="1" height="1"&gt;</description></item><item><title>re: Hey, Scripting Guy! How Can I Get the Name of the Last User to Log on to a Computer?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2007/01/24/how-can-i-get-the-name-of-the-last-user-to-log-on-to-a-computer.aspx#3432422</link><pubDate>Mon, 30 May 2011 19:21:54 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3432422</guid><dc:creator>jv</dc:creator><description>&lt;p&gt;Note that this: &amp;#39;(get-wmiobject win32_computersystem).UserName&amp;#39; only works for logons at teh console. &amp;nbsp;It will not tell you about someone logged on remotely via RDP. &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3432422" width="1" height="1"&gt;</description></item><item><title>re: Hey, Scripting Guy! How Can I Get the Name of the Last User to Log on to a Computer?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2007/01/24/how-can-i-get-the-name-of-the-last-user-to-log-on-to-a-computer.aspx#3432418</link><pubDate>Mon, 30 May 2011 17:52:57 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3432418</guid><dc:creator>Thank You Emil Rakoczy</dc:creator><description>&lt;p&gt;Emil Rakoczy....I&amp;#39;ve been trying to find this forever. &amp;nbsp;THANK YOU!&lt;/p&gt;
&lt;p&gt;(get-wmiobject win32_computersystem).UserName&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3432418" width="1" height="1"&gt;</description></item><item><title>re: Hey, Scripting Guy! How Can I Get the Name of the Last User to Log on to a Computer?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2007/01/24/how-can-i-get-the-name-of-the-last-user-to-log-on-to-a-computer.aspx#3387688</link><pubDate>Wed, 16 Feb 2011 12:56:53 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3387688</guid><dc:creator>Emil Rakoczy</dc:creator><description>&lt;p&gt;If you use powershell:&lt;/p&gt;
&lt;p&gt;(get-wmiobject win32_computersystem).UserName&lt;/p&gt;
&lt;p&gt;... will give you the currently logged on user.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3387688" width="1" height="1"&gt;</description></item><item><title>re: Hey, Scripting Guy! How Can I Get the Name of the Last User to Log on to a Computer?</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2007/01/24/how-can-i-get-the-name-of-the-last-user-to-log-on-to-a-computer.aspx#3348560</link><pubDate>Thu, 05 Aug 2010 08:26:50 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3348560</guid><dc:creator>Dave Hope</dc:creator><description>&lt;p&gt;Dear Scripting Guy,&lt;/p&gt;
&lt;p&gt;The DefaultUserName and DefaultDomainName values don&amp;#39;t get populated in Windows 7. They&amp;#39;re under Wow6432Node, but their values are blank.&lt;/p&gt;
&lt;p&gt;Any thoughts on an alternative with support for 2000 - 2008R2/7 ?&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3348560" width="1" height="1"&gt;</description></item></channel></rss>