[实战二]vbs script export user information to access database

简介:

vbs script export user information to access database,

vbs operate accdb

source code is below

=====================================

'********************************************************
'*         Windows Script Source Code                   *
'*Used for Collect PPG China Users PC infromation       *
'*Author: Fu Eric      eric.fu@hm.com                              *
'*HM Senior IT                           *                    
'*Date: 28 Nov 2013                                  *
'*Any Site can change infor depend on your request      * 
'********************************************************
On error resume Next

strldap = "LDAP://OU=CN,OU=Users,OU=CN,OU=HM,dc=HM, dc=com"

Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
Const ADS_UF_ACCOUNTDISABLE = 2
Const ADS_ACETYPE_ACCESS_DENIED_OBJECT = &H6
Const CHANGE_PASSWORD_GUID  = _
   "{ab721a53-1e2f-11d0-9819-00aa0040529b}"
   
Set usr=GetObject(strldap)

For each member in usr

strutype = member.class

If strutype = "user" Then

strid= member.get("samaccountname")

strdisplayname = member.displayname

stroffice = member.physicalDeliveryOfficeName

strtel = member.Get("telephoneNumber")

strothermobile = member.GetEx ("otherMobile")

For Each Item in strothermobile

strkeynum1 = Item

strleftstr = Left (strkeynum1,2)

If strleftstr = "AI" Then

strkeynum = strkeynum1

Exit For

End If 
 
Next

Item = Null

strothermobile = Null

strkeynum1 = Null


'==============================
strbus = member.otherTelephone

intuac = member.Get("userAccountControl")
 If intuac AND ADS_UF_ACCOUNTDISABLE Then
    
 straccountstate = "Disable"
  Else  
  straccountstate= "Enable"
   
  End If 
  
strdes = member.description

strTitle = member.get("title")

striphone = member.ipPhone

'=====get lastlogin time=====


Set objLastLogon = member.Get("lastLogonTimestamp")
      
      
     strlastlogontimestamp = objLastLogon.HighPart * (2^32) + objLastLogon.LowPart
     strlastlogontimestamp = strlastlogontimestamp / (60 * 10000000)
     strlastlogontimestamp = strlastlogontimestamp / 1440
     strlastlogontimestamp = strlastlogontimestamp + #1/1/1601#
 
     Set objlastlogon = Nothing    
     
     Set objlastlogon1 = member.Get("lastlogon")   
     strLastLogonTime1 = objLastLogon1.HighPart * (2^32) + objLastLogon1.LowPart
     strLastLogonTime1 = strLastLogonTime1 / (60 * 10000000)
     strLastLogonTime1 = strLastLogonTime1 / 1440
     strLastLogonTime1 = strLastLogonTime1 + #1/1/1601#  
     Set objlastlogon1 = Nothing
     
     strvalue1 = VarType (strlastlogontimestamp) 
     strvalue2 = VarType (strLastLogonTime1) 
     strstring =  strvalue1 &"+" & strvalue2
     
     strlocallt = DateValue(strLastLogonTime1)
     strremotelt = DateValue(strlastlogontimestamp)
     
     Select Case strstring
     Case "1+7"  strllt = strLastLogonTime1
     Case "7+1"  strllt = strlastlogontimestamp
     Case "1+1"  strllt = Null 
     Case Else   If DateDiff ("d",strlocallt,strremotelt) >=0 Then 
                 strllt = strlastlogontimestamp
                 Else 
                 strllt = strLastLogonTime1
                End If 
     End Select   
     
     
              

 If member.mDBUseDefaults = False Then
     
     strStoQuota = member.mDBStorageQuota
     strOveQuota = member.mDBOverQuotaLimit
     strHarQuotalim= member.mDBOverHardQuotaLimit
     
     strquotamailbox =  strStoQuota  & "MB/" & strOveQuota & "MB/" & strHarQuotalim &"MB"
     
     Else 
 
 strquotamailbox = "Default Settings"
     
     End If 
 
'====mailbox store is strmstore1======     
strmstore = member.homemdb

Myarray1 = Split (strmstore,",",-1,1)

strmstore1 = Myarray1(0)

strmstore = Null


'====check whether have webmail======
strmemberOf = member.GetEx("memberOf")

strcheck = IsObject(strmemberOf)

'WScript.Echo strcheck

If strcheck = 0 Then

For Each Item1 in strmemberOf

Myarray = Split (Item1,",",-1,1)

Myarray2 = Split (Myarray(0),"=",-1,1)

'WScript.Echo Myarray2(1)

If Myarray2(1) = "CNSH Webmail Users" Or Myarray2(1) = "Webmail Users" Then

 strwebmail = "Enable" 
 
   Exit For
 Else 
 strwebmail = "Disable"
End If

Next

Else

strwebmail = "Disable"

End If

Set myarray = Nothing 

Set Myarray2 = Nothing

Set Myarray1 = Nothing

'=========
'strid = CStr (strid)
'strdisplayname = CStr (strdisplayname)
'stroffice = CStr (stroffice)
'straccountstate = CStr (straccountstate)
'strdes = CStr (strdes)
'strllt = CStr (strllt)
'strtel = CStr (strtel)
'strbus = CStr (strbus)
'striphone = CStr (striphone)
'strtitle = CStr (strtitle)
'strmstore1 = CStr (strmstore1)
'strkeynum = CStr (strkeynum)
'strwebmail = CStr (strwebmail)
'strquotamailbox = CStr (strquotamailbox)

'WScript.Echo (strid &  strdisplayname  & stroffice & straccountstate & strdes _
'          & strllt & strtel & strbus & striphone & strtitle &  strmstore1 _
'         & strkeynum & strwebmail & strquotamailbox )


Call Wsql (strid)

WScript.Sleep (1000)

strid = Null  
strdisplayname = Null  
stroffice = Null  
straccountstate = Null  
strdes = Null 
strllt = Null 
strtel = Null 
strbus = Null 
striphone = Null 
strtitle = Null 
strmstore1 = Null 
strkeynum = Null 
strwebmail = Null  
strquotamailbox = Null

Myarray1 = Null

Myarray = Null

Myarray2 = Null

Set intuac = Nothing

Set strmemberOf = Nothing

strmstore1 = Null

strvalue1 = Null 
strvalue2 = Null 
strstring = Null


End If

Next


'======SQL Table List====
'UserName   strid 
'DisplayName  strdisplayname
'OfficeName  stroffice
'AccountStatus straccountstate
'Description   strdes 
'LastLogonTime  strllt
'Telephone  strtel 
'Business2  strbus
'IPphone  striphone
'Title  strtitle
'MailStore  strmstore1
'RASKeyNumber  strkeynum
'WebmailCheck  strwebmail
'MailboxQuota strquotamailbox

Sub Wsql (strtemp)

Dim TempValue

On error resume Next

Const adOpenStatic = 3
Const adLockOptimistic = 3

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")

objConnection.Open _
"Provider = Microsoft.ACE.OLEDB.12.0; " & _
"Data Source = C:\inetpub\wwwroot\AccountList\Account.accdb"

objRecordSet.Open "SELECT * FROM AccountList where UserName = '"& strtemp&"'", _
  objConnection, adOpenStatic, adLockOptimistic

objRecordSet.MoveFirst

Do Until objRecordset.EOF

    TempValue = objRecordset.Fields.Item("UserName")

    objRecordset.MoveNext
Loop


objRecordSet.Close
objConnection.Close

Set objConnection = nothing
Set objRecordSet = nothing


If TempValue = strtemp then

'wscript.echo "Find it"

Set objConnection1 = CreateObject("ADODB.Connection")
Set objRecordSet1 = CreateObject("ADODB.Recordset")

objConnection1.Open _
"Provider = Microsoft.ACE.OLEDB.12.0; " & _
"Data Source = C:\inetpub\wwwroot\AccountList\Account.accdb"

objRecordSet1.Open "UPDATE AccountList Set DisplayName = '" & strdisplayname & "', OfficeName = '" & stroffice &"', AccountStatus = '"& straccountstate &"', Description = '"& strdes &"', LastLogonTime = '"& strllt &"', Telephone = '" & strtel & "', Business2 = '" & strbus & "', IPphone = '" & striphone &"', Title = '" & strtitle &"', MailStore = '" &  strmstore1  &"', RASKeyNumber = '" & strkeynum  &"',WebmailCheck = '"&  strwebmail &"', MailboxQuota = '"& strquotamailbox &"'" & _
    "Where UserName = '"& strtemp &"'", _
    objConnection1, adOpenStatic, adLockOptimistic

objRecordSet1.Close
objConnection1.Close

Set objConnection1 = nothing
Set objRecordSet1 = nothing


Else

'wscript.echo "can't find it"

Set objConnection1 = CreateObject("ADODB.Connection")
Set objRecordSet1 = CreateObject("ADODB.Recordset")

objConnection1.Open _
"Provider = Microsoft.ACE.OLEDB.12.0; " & _
"Data Source = C:\inetpub\wwwroot\AccountList\Account.accdb"

objRecordSet1.Open "INSERT INTO AccountList (UserName, DisplayName, OfficeName, AccountStatus, Description, LastLogonTime, Telephone, Business2, IPphone, Title, MailStore, RASKeyNumber,WebmailCheck, MailboxQuota)" &  _
    "VALUES ('" & strid & "',' " & strdisplayname & "','" & stroffice & "','" & straccountstate & "',' " & strdes & "',' " & strllt & "',' " & strtel & "',' " & strbus & "',' " & striphone & "',' " & strtitle & "',' " & strmstore1 & " ',' " & strkeynum & "','" & strwebmail &"',' " & strquotamailbox &"')", _
        objConnection1, adOpenStatic, adLockOptimistic
        
objRecordSet1.Close
objConnection1.Close

Set objConnection1 = nothing
Set objRecordSet1 = nothing


End if

TempValue = Null


Err.clear

End Sub


本文转自 bilinyee博客,原文链接:   http://blog.51cto.com/ericfu/1636465     如需转载请自行联系原作者


相关文章
|
4月前
|
SQL 关系型数据库 MySQL
云服务器 ECS产品使用问题之出现“1044 - Access denied for user ‘root‘@‘%‘ to database ‘数据库名称‘”这样的错误,该怎么办
云服务器ECS(Elastic Compute Service)是各大云服务商阿里云提供的一种基础云计算服务,它允许用户租用云端计算资源来部署和运行各种应用程序。以下是一个关于如何使用ECS产品的综合指南。
|
关系型数据库 MySQL SQL
[解决] Error Code: 1044. Access denied for user 'root'@'%' to database
今天在测试集群用的mysql上,遇到个权限的问题: SQLException : SQL state: 42000 com.mysql.jdbc.exceptions.
5442 0
|
SQL Java 关系型数据库
spring boot集成mybatis只剩两个sql 并提示 Cannot obtain primary key information from the database, generated objects may be incomplete
spring boot集成mybatis只剩两个sql 并提示 Cannot obtain primary key information from the database, generated objects may be incomplete
153 0
spring boot集成mybatis只剩两个sql 并提示 Cannot obtain primary key information from the database, generated objects may be incomplete
|
SQL 监控 数据库
IO is frozen on database xxx, No user action is required
最近遇到一起关于"I/O is frozen on database xxx. No user action is required. However, if I/O is not resumed promptly, you could cancel the backup."的案例。
1946 0
|
JavaScript 关系型数据库 MySQL