<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; VBA: Время последнего логина пользователя]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=6032&amp;type=atom" />
	<updated>2011-07-21T09:08:56Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=6032</id>
		<entry>
			<title type="html"><![CDATA[Re: VBA: Время последнего логина пользователя]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=50048#p50048" />
			<content type="html"><![CDATA[<p>подскажите , где и что нужно поменять?</p>]]></content>
			<author>
				<name><![CDATA[Павел123312]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=25870</uri>
			</author>
			<updated>2011-07-21T09:08:56Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=50048#p50048</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBA: Время последнего логина пользователя]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=50047#p50047" />
			<content type="html"><![CDATA[<p>Помочь — да, переделать — нет.</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2011-07-21T08:53:14Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=50047#p50047</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBA: Время последнего логина пользователя]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=50045#p50045" />
			<content type="html"><![CDATA[<p>Нашел вот такой скрипт, не могли бы помочь переделать его , что бы информация выводилась для конкретного пользователя, а не для всех.</p><br /><div class="codebox"><pre><code>&#039; LastLogon.vbs

Option Explicit

Dim objRootDSE, strConfig, adoConnection, adoCommand, strQuery
Dim adoRecordset, objDC
Dim strDNSDomain, objShell, lngBiasKey, lngBias, k, arrstrDCs()
Dim strDN, dtmDate, objDate, objList, strUser
Dim strBase, strFilter, strAttributes, lngHigh, lngLow

&#039; Use a dictionary object to track latest lastLogon for each user.
Set objList = CreateObject(&quot;Scripting.Dictionary&quot;)
objList.CompareMode = vbTextCompare

&#039; Obtain local Time Zone bias from machine registry.
&#039; This bias changes with Daylight Savings Time.
Set objShell = CreateObject(&quot;Wscript.Shell&quot;)
lngBiasKey = objShell.RegRead(&quot;HKLM\System\CurrentControlSet\Control\&quot; _
    &amp; &quot;TimeZoneInformation\ActiveTimeBias&quot;)
If (UCase(TypeName(lngBiasKey)) = &quot;LONG&quot;) Then
    lngBias = lngBiasKey
ElseIf (UCase(TypeName(lngBiasKey)) = &quot;VARIANT()&quot;) Then
    lngBias = 0
    For k = 0 To UBound(lngBiasKey)
        lngBias = lngBias + (lngBiasKey(k) * 256^k)
    Next
End If

&#039; Determine configuration context and DNS domain from RootDSE object.
Set objRootDSE = GetObject(&quot;LDAP://RootDSE&quot;)
strConfig = objRootDSE.Get(&quot;configurationNamingContext&quot;)
strDNSDomain = objRootDSE.Get(&quot;defaultNamingContext&quot;)

&#039; Use ADO to search Active Directory for ObjectClass nTDSDSA.
&#039; This will identify all Domain Controllers.
Set adoCommand = CreateObject(&quot;ADODB.Command&quot;)
Set adoConnection = CreateObject(&quot;ADODB.Connection&quot;)
adoConnection.Provider = &quot;ADsDSOObject&quot;
adoConnection.Open &quot;Active Directory Provider&quot;
adoCommand.ActiveConnection = adoConnection

strBase = &quot;&lt;LDAP://&quot; &amp; strConfig &amp; &quot;&gt;&quot;
strFilter = &quot;(objectClass=nTDSDSA)&quot;
strAttributes = &quot;AdsPath&quot;
strQuery = strBase &amp; &quot;;&quot; &amp; strFilter &amp; &quot;;&quot; &amp; strAttributes &amp; &quot;;subtree&quot;

adoCommand.CommandText = strQuery
adoCommand.Properties(&quot;Page Size&quot;) = 100
adoCommand.Properties(&quot;Timeout&quot;) = 60
adoCommand.Properties(&quot;Cache Results&quot;) = False

Set adoRecordset = adoCommand.Execute

&#039; Enumerate parent objects of class nTDSDSA. Save Domain Controller
&#039; AdsPaths in dynamic array arrstrDCs.
k = 0
Do Until adoRecordset.EOF
    Set objDC = _
        GetObject(GetObject(adoRecordset.Fields(&quot;AdsPath&quot;).Value).Parent)
    ReDim Preserve arrstrDCs(k)
    arrstrDCs(k) = objDC.DNSHostName
    k = k + 1
    adoRecordset.MoveNext
Loop
adoRecordset.Close


&#039; Retrieve lastLogon attribute for each user on each Domain Controller.
For k = 0 To Ubound(arrstrDCs)
    strBase = &quot;&lt;LDAP://&quot; &amp; arrstrDCs(k) &amp; &quot;/&quot; &amp; strDNSDomain &amp; &quot;&gt;&quot;
    strFilter = &quot;(&amp;(objectCategory=person)(objectClass=user))&quot;
    strAttributes = &quot;distinguishedName,lastLogon&quot;
    strQuery = strBase &amp; &quot;;&quot; &amp; strFilter &amp; &quot;;&quot; &amp; strAttributes _
        &amp; &quot;;subtree&quot;
    adoCommand.CommandText = strQuery
    On Error Resume Next
    Set adoRecordset = adoCommand.Execute
    If (Err.Number &lt;&gt; 0) Then
        On Error GoTo 0
        Wscript.Echo &quot;Domain Controller not available: &quot; &amp; arrstrDCs(k)
    Else
        On Error GoTo 0
        Do Until adoRecordset.EOF
            strDN = adoRecordset.Fields(&quot;distinguishedName&quot;).Value
            On Error Resume Next
            Set objDate = adoRecordset.Fields(&quot;lastLogon&quot;).Value
            If (Err.Number &lt;&gt; 0) Then
                On Error GoTo 0
                dtmDate = #1/1/1601#
            Else
                On Error GoTo 0
                lngHigh = objDate.HighPart
                lngLow = objDate.LowPart
                If (lngLow &lt; 0) Then
                    lngHigh = lngHigh + 1
                End If
                If (lngHigh = 0) And (lngLow = 0) Then
                    dtmDate = #1/1/1601#
                Else
                    dtmDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) _
                        + lngLow)/600000000 - lngBias)/1440
                End If
            End If
            If (objList.Exists(strDN) = True) Then
                If (dtmDate &gt; objList(strDN)) Then
                    objList.Item(strDN) = dtmDate
                End If
            Else
                objList.Add strDN, dtmDate
            End If
            adoRecordset.MoveNext
        Loop
        adoRecordset.Close
    End If
Next

strUser=inputbox(&quot;Enter username:&quot;)




&#039; Output latest lastLogon date for each user.
    If (objList.Item(strUser) = #1/1/1601#) Then
        Wscript.Echo strUser &amp; &quot;;Never&quot;
    Else
        Wscript.Echo strUser &amp; &quot;;&quot; &amp; objList.Item(strUser)
    End If


&#039; Clean up.
adoConnection.Close</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Павел123312]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=25870</uri>
			</author>
			<updated>2011-07-21T08:47:32Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=50045#p50045</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBA: Время последнего логина пользователя]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=50042#p50042" />
			<content type="html"><![CDATA[<p>Поищите по форуму по словосочетанию: «LastLogon».</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2011-07-21T07:57:32Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=50042#p50042</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBA: Время последнего логина пользователя]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=50041#p50041" />
			<content type="html"><![CDATA[<p>да из AD.<br />Тоесть нужно по имени пользователя определить на какой компьютер и когда он последний раз логинился.</p>]]></content>
			<author>
				<name><![CDATA[Павел123312]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=25870</uri>
			</author>
			<updated>2011-07-21T06:07:19Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=50041#p50041</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBA: Время последнего логина пользователя]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=50021#p50021" />
			<content type="html"><![CDATA[<div class="quotebox"><blockquote><p>имя компьютера</p></blockquote></div><p>Например:<br /></p><div class="codebox"><pre><code>CreateObject(&quot;WScript.Network&quot;).ComputerName</code></pre></div><div class="quotebox"><blockquote><p>и время последнего логина пользователя</p></blockquote></div><p>Откуда? Из AD?</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2011-07-20T13:51:11Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=50021#p50021</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[VBA: Время последнего логина пользователя]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=50020#p50020" />
			<content type="html"><![CDATA[<p>Нужен скрипт определяющий имя компьютера и время последнего логина пользователя.<br />помоги хотябы с чего начать</p>]]></content>
			<author>
				<name><![CDATA[Павел123312]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=25870</uri>
			</author>
			<updated>2011-07-20T13:33:59Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=50020#p50020</id>
		</entry>
</feed>
