[实战二]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      [email protected]                              *
‘*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

时间: 2024-07-29 23:22:08

[实战二]vbs script export user information to access database的相关文章

[实战三]script export computer information into accdb

'**********************************************************'*         Windows Script Source Code                     *'*Used for Change Tel number that shown in GAL based site *'*HM Senior IT: Eric Fu [email protected]                             *  

Python爬虫实战二之爬取百度贴吧帖子

大家好,上次我们实验了爬取了糗事百科的段子,那么这次我们来尝试一下爬取百度贴吧的帖子.与上一篇不同的是,这次我们需要用到文件的相关操作. 前言 亲爱的们,教程比较旧了,百度贴吧页面可能改版,可能代码不好使,八成是正则表达式那儿匹配不到了,请更改一下正则,当然最主要的还是帮助大家理解思路. 2016/12/2 本篇目标 1.对百度贴吧的任意帖子进行抓取 2.指定是否只抓取楼主发帖内容 3.将抓取到的内容分析并保存到文件 1.URL格式的确定 首先,我们先观察一下百度贴吧的任意一个帖子. 比如:ht

FastDFS安装使用实战二(配置篇)

FastDFS安装使用实战二(配置篇) Keywords:FastDFS.分布式文件系统.Ubuntu Author:soartju 转载请注明出处:http://soartju.iteye.com/blog/803524 FastDFS的配置文件在%FastDFS%/conf目录下,其中包括 Client.conf    客户端上传配置文件 Storage.conf    文件存储服务器配置文件 Tracker.conf    负责均衡调度服务器配置文件 http.conf        ht

Python机器学习实战<二>:机器学习概述

1.机器学习的真实含义是利用数据来彰显数据背后的真实含义. 2.机器学习的一般用例:人脸识别.手写数字识别.垃圾邮件过滤.产品推荐等等. 3.机器学习的主要任务是分类,即将实例数据划分到合适的分类中.另一项任务是回归,主要用于预测数值型数据.分类和回归属于监督学习,之所以称为监督学习,是因为这类算法必须知道预测什么,即目标的分类信息.另一种机器学习方式是无监督学习,此时数据没有类别信息,也没有给定的目标.在无监督学习中,将数据集合分成由类似对象组成的多个类成为聚类,将寻找数据统计值的过程称为密度

windos server nagios 增加vbs script

在windows server 服务器nsclient++ 增加外部scripts的方法: 在nscline.ini 配置文件中增加: [/settings/external scripts/wrappings]vbs=cscript.exe //T:30 //NoLogo scripts\lib\wrapper.vbs %SCRIPT% %ARGS% [/settings/external scripts/wrapped scripts]check_disk_io=scripts\check_

转 Python爬虫实战二之爬取百度贴吧帖子

静觅 » Python爬虫实战二之爬取百度贴吧帖子 大家好,上次我们实验了爬取了糗事百科的段子,那么这次我们来尝试一下爬取百度贴吧的帖子.与上一篇不同的是,这次我们需要用到文件的相关操作. 本篇目标 1.对百度贴吧的任意帖子进行抓取 2.指定是否只抓取楼主发帖内容 3.将抓取到的内容分析并保存到文件

二 Flask Project 实战 二

5 templates {{ and }} is an expression{% and %} denotes a control flow statement like if and for blocks defined here that will be overridden in the other templates{% extends 'base.html' %} tells Jinja that this template should replace the blocks from

Docker最全教程之Python爬网实战(二十一)

原文:Docker最全教程之Python爬网实战(二十一) Python目前是流行度增长最快的主流编程语言,也是第二大最受开发者喜爱的语言(参考Stack Overflow 2019开发者调查报告发布).笔者建议.NET.Java开发人员可以将Python发展为第二语言,一方面Python在某些领域确实非常犀利(爬虫.算法.人工智能等等),另一方面,相信我,Python上手完全没有门槛,你甚至无需购买任何书籍! 由于近期在筹备4.21的长沙开发者大会,耽误了不少时间.不过这次邀请到了腾讯资深技术

数据-第16课-栈的应用实战二

第16课-栈的应用实战二 1. 问题的提出 计算机的本质工作就是数学运算,那计算机可以读入字符串”9 + (3 - 1) *5 +8/2”并且计算值吗? 2. 后缀表达式 波兰科学家在20世纪50年代提出了一种将运算符放在数字后面的后缀表达式. 对应的,我们平时用的数学表达式叫做中缀表达式. 实例 5 + 3 => 5 3 + 1 + 2 * 3 => 1 2 3 * + 9 + ( 3–1 ) * 5 => 9 3 1–5 * + 中缀表达式符合人类的阅读和思维习惯:后缀表达式符合计算