VB6写WMI查询网路域內电脑并自动生成清单的问题
1.最快的方法是上AD将电脑清单汇出,但是问题是AD上的电脑清单不完全〜因为用了2012的一个BUG快速转移AD控制站〜这问题日后会慢慢解决〜
不知道有没有方法是能查询到同域名的全部主机〜不透过查询AD内资料?
当然扫指定段落的全部IP地址再反查主机名称和域名是最后手段~
希望有更好的使用WMI的解决方法~
-------------------------------------------------------------------
2.网路上找到一段代码可以停用太久没使用的使用者帐户〜
不知怎麼改成停用太久没使用的使用者电脑〜
程序代码:
on error resume next Set objRootDSE = GetObject("LDAP://rootDSE") Domain=objRootDSE.Get("defaultNamingContext") Const ADS_SCOPE_SUBTREE = 2 Const adOpenStatic = 3 Const adLockOptimistic = 3 Const adUseClient = 3 Set AD_Connection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("") AD_Connection.Provider = "ADsDSOObject" AD_Connection.Open "Active Directory Provider" Set objCommand.ActiveConnection = AD_Connection objCommand.Properties("Page Size") = 10000 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE = _ "SELECT sAMAccountName,cn,department,adspath FROM 'LDAP://""' WHERE objectCategory='computer'" Set ADRecordSet = objCommand.Execute ADRecordSet.MoveFirst Do Until ADRecordSet.EOF strPath = ADRecordSet.Fields("AdsPath").Value ComputerCN = ADRecordSet.Fields("CN").Value If InStr(strPath,"Domain Controllers")=0 Then Set objPC = GetObject(strPath) Set objLastLogon = objPC.Get("lastLogon") intLastLogonTime = objLastLogon.HighPart * (2^32) + objLastLogon.LowPart intLastLogonTime = intLastLogonTime / (60 * 10000000) intLastLogonTime = intLastLogonTime / 1440 StrTime = intLastLogonTime + #1/1/1601# dtmEndingDate = strTime intDays = DateDiff("d", dtmEndingDate, Now) If (intDays > 60) Then ' 停用 60 天以上未登入的电脑帐户 WScript.Echo "停用 " & ComputerCN & " " & strTime & " " & Intdays objPC.AccountDisabled = True objPC.SetInfo End If end If ADRecordSet.MoveNext Loop AMS_cpf_cpyRecordset.Close ADRecordSet.close
试过能用〜