[实战三]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]                             *                   
‘*Date: 29 NOV 2013                                      *
‘*Any Site can change infor depend on your request        *
‘**********************************************************
On error resume Next

Const ADS_NAME_INITTYPE_GC = 3

Const ADS_NAME_TYPE_NT4 = 3

Const ADS_NAME_TYPE_1779 = 1

Const ADS_SCOPE_SUBTREE = 2

Dim StrComputer

Set fso1=CreateObject("Scripting.FileSystemObject")

If (fso1.folderexists("C:\Disk2")) = False then

Set foldr=fso1.createfolder("C:\Disk2")

End if
  
const thefile2 = "C:\Disk2\computerlist.txt"

Set theFile = fso1.OpenTextFile(thefile2,1)

Do While theFile.AtEndOfStream <> True

StrComputer = theFile.ReadLine

‘StrComputer ="wks06225"

Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
      ("select * from Win32_PingStatus where address = ‘" & strComputer & "‘")
     
For each objRetStatus in objPing
 
If IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
   
   strping = "False"
  
   stripadd = Null
  
   colusername = Null
  
   colmodel = Null  
  
   colsn = Null
  
   collastbootup = "1901/1/11 12:00:00"
  
   coldisplayN  = Null
  
   coluserlimit = Null
  
   Call WsqlF (StrComputer)
 
Else

strping = "True"
  
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
  
    Set ColComputerSystem = objWMIService.ExecQuery( _
    "SELECT UserName,Model FROM Win32_ComputerSystem",,48)
   
    ‘WScript.Echo Err.Number
   
    If Err.Number = 0 Then
   
     For Each objItem In ColComputerSystem
   
     strcolun = objItem.UserName
  
     ColModel = objItem.Model
   
     Next
    
     Set colipadd = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_NetworkAdapterConfiguration",,48) 
   
     For Each objItem in colipadd 
   
     If isNull(objitem.IPAddress) Then
    
     ‘MsgBox " "&vbCrLf & "No IP enable on this computer"& vbCrLf & vbCrLf &"",64,"**Computer Error**"
    
     Else
        
        stripadd = Join(objItem.IPAddress, ",")
       
     End If
    
     Next
   
     Set ColBios = objWMIService.ExecQuery("SELECT SerialNumber FROM Win32_BIOS",,48)
   
     For Each objItem In ColBios

colSN= objItem.SerialNumber

Next
    
     Set ColOperSystem = objWMIService.ExecQuery("SELECT LastBootUpTime FROM Win32_OperatingSystem")

For Each objItem In ColOperSystem

dtmBootup = objItem.LastBootUpTime

Next
    
     collastbootup = CDate(Mid(dtmBootup, 5, 2) & "/" & _
         Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) _
         & " " & Mid (dtmBootup, 9, 2) & ":" & _
         Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup, _
         13, 2))
        
     strun = VarType (strcolun)
 
     If strun = 0 Or strun = 1 Then
   
       colusername = "NoID"
    
       ColDisplayN = "NOID"
      
       coluserlimit = "NOID "
    
     Else
  
      ComArray = Split (strcolun,"\",-1,1)

colusername = ComArray(1)

Set objTrans = CreateObject("NameTranslate")
   ‘ Initialize NameTranslate by locating the Global Catalog.
      objTrans.Init ADS_NAME_INITTYPE_GC, ""
 
   ‘ Use the Set method to specify the NT format of the object name.
     objTrans.Set ADS_NAME_TYPE_NT4, "HM\"& colusername
 
   ‘ Use the Get method to retrieve the RFC 1779 Distinguished Name.
     strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
 
   ‘ Escape any "/" characters with backslash escape character.
   ‘ All other characters that need to be escaped will be escaped.
     strUserDN = Replace(strUserDN, "/", "\/")
 
     Set objUser = GetObject("LDAP://" & strUserDN)
 
     ColDisplayN = objUser.Get("displayName")
    
     ‘=======check local admin========
    
     coluserlimit = "No"
    
     Strgroupname = StrComputer & " Administrators"
    
     Set objConnection = CreateObject("ADODB.Connection")

Set objCommand = CreateObject("ADODB.Command")

objConnection.Provider = "ADsDSOObject"

objConnection.Open "Active Directory Provider"

Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000

objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

objCommand.CommandText = _
       "SELECT ADsPath FROM ‘LDAP://OU=HMGroup,dc=hm,dc=com‘ WHERE "_
         & "objectCategory=‘group‘AND sAMAccountName =" & Chr(39) & Strgroupname & Chr(39)

Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst

Do Until objRecordSet.EOF

strPath = objRecordSet.Fields("ADsPath").Value  ‘wscript.echo strpath
  
     Set objgroup = GetObject (strPath)

objgroupmem = objgroup.GetEx("member")

for each ii in objgroupmem

‘wscript.echo ii

set objuser = Getobject ("LDAP://" & ii)

objusername = objuser.Get("sAMAccountName")
     
      ‘WScript.Echo objusername
        
       If LCase (objusername) = LCase (colusername) Then

coluserlimit = "Yes"
   
       Exit For
  
       End If 
     
     Next

objRecordSet.MoveNext
  
     Loop
    
 ‘判断是否为空用户名 
  End If
 
  Call Wsql (StrComputer)
 
‘判断error是否为0
End If

‘WScript.Echo StrComputer & stripadd & colusername & coldisplayN & colmodel & colsn & collastbootup & coluserlimit & strping

‘判断是否PING ACCESS
End If

Next

StrComputer = Null

stripadd = Null

colusername = Null

coldisplayN = Null

colmodel = Null

colsn = Null

collastbootup = Null

coluserlimit = Null

strping = Null

Loop

theFile.Close

Err.Clear

‘=======SQL Table======
‘ComputerName:   StrComputer
‘IPAddress:      stripadd
‘UserName:       colusername
‘DisplayName:    coldisplayN
‘ComputerModel:  colmodel
‘ComputerSN:     colsn
‘LastBootUpTime: collastbootup
‘LocalAdmin:     coluserlimit
‘PingStatus:     strping

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\ComputerList\Computer.accdb"

objRecordSet.Open "SELECT * FROM ComputerList where ComputerName = ‘"& strtemp &"‘", _
  objConnection, adOpenStatic, adLockOptimistic

objRecordSet.MoveFirst

Do Until objRecordset.EOF

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

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\ComputerList\Computer.accdb"

objRecordSet1.Open "UPDATE ComputerList Set IPAddress = ‘" & stripadd & "‘, UserName = ‘" & colusername &"‘, DisplayName = ‘"& coldisplayN &"‘, ComputerModel = ‘"& colmodel &"‘, ComputerSN = ‘"& colsn &"‘, LastBootUpTime = ‘" & collastbootup & "‘, LocalAdmin = ‘" & coluserlimit & "‘, PingStatus = ‘" & strping &"‘" & _
    "Where ComputerName = ‘"& 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\ComputerList\Computer.accdb"

objRecordSet1.Open "INSERT INTO ComputerList (ComputerName, IPAddress, UserName, DisplayName, ComputerModel, ComputerSN, LastBootUpTime, LocalAdmin, PingStatus)" &  _
    "VALUES (‘" & StrComputer & "‘,‘ " & stripadd & "‘,‘" & colusername & "‘,‘" & coldisplayN & "‘,‘ " & colmodel & "‘,‘ " & colsn & "‘,‘ " & collastbootup & "‘,‘ " & coluserlimit & "‘,‘ " & strping & "‘)", _
        objConnection1, adOpenStatic, adLockOptimistic
       
‘objRecordSet1.Close
‘objConnection1.Close

Set objConnection1 = nothing
Set objRecordSet1 = nothing

End if

TempValue = Null

Err.clear

End Sub

‘========Failed Action========

Sub WsqlF (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\ComputerList\Computer.accdb"

objRecordSet.Open "SELECT * FROM ComputerList where ComputerName = ‘"& strtemp &"‘", _
  objConnection, adOpenStatic, adLockOptimistic

‘objRecordSet.MoveFirst

Do Until objRecordset.EOF

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

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\ComputerList\Computer.accdb"

objRecordSet1.Open "UPDATE ComputerList Set PingStatus = ‘" & strping &"‘" & _
    "Where ComputerName = ‘"& 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\ComputerList\Computer.accdb"

objRecordSet1.Open "INSERT INTO ComputerList (ComputerName, IPAddress, UserName, DisplayName, ComputerModel, ComputerSN, LastBootUpTime, LocalAdmin, PingStatus)" &  _
    "VALUES (‘" & StrComputer & "‘,‘ " & stripadd & "‘,‘" & colusername & "‘,‘" & coldisplayN & "‘,‘ " & colmodel & "‘,‘ " & colsn & "‘,‘ " & collastbootup & "‘,‘ " & coluserlimit & "‘,‘ " & strping & "‘)", _
        objConnection1, adOpenStatic, adLockOptimistic
       
‘objRecordSet1.Close
‘objConnection1.Close

Set objConnection1 = nothing
Set objRecordSet1 = nothing

End if

TempValue = Null

Err.clear

End Sub

时间: 2024-09-29 05:38:57

[实战三]script export computer information into accdb的相关文章

[实战二]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                   *'*Us

Python机器学习实战&lt;三&gt;:k-邻近算法

安装说明参考openssl源码文件夹下INSTALL.W32 step1 环境搭建 安装perl,Visual Studio 2008 下载Openssl最新版源码.我下的版本为OpenSSL-1.0.0g. step2 启动Visual Studio 2008 Command Prompt 运行bin\vcvars32 设置 环境变量 注意: 如遇反馈"此处不应该有/Microsoft",参考错误1. step3 VS命令行窗口cd至openssl源码文件夹 执行以下命令 $perl

机器学习实战三(Naive Bayes)

机器学习实战三(Naive Bayes) 前两章的两种分类算法,是确定的分类器,但是有时会产生一些错误的分类结果,这时可以要求分类器给出一个最优的猜测结果,估计概率.朴素贝叶斯就是其中一种. 学过概率论的人对于贝叶斯这个名字应该是相当的熟悉,在学条件概率的时候,贝叶斯公式可谓是一针见血.这里的"朴素贝叶斯",是因为在计算贝叶斯概率的时候只考虑最原始.最简单的假设. Naive Bayes(朴素贝叶斯) 优点:在数据较少的情况下依然有效,可处理多类别问题. 缺点:对于输入数据的格式要求严

Thrift RPC实战(三) thrift序列化揭秘

本文主要讲解Thrift的序列化机制, 看看thrift作为数据交换格式是如何工作的? 1.构造应用场景: 1). 首先我们先来定义下thrift的简单结构. 1 2 3 4 5 namespace java com.yangyang.thrift.api struct Pair { ? ? 1: required string key ? ? 2: required string value } required修饰符你肯定能猜测到它的意义, 但是你是否有没有这样的疑惑, "1",

C# Redis实战(三)

三.程序配置 在C# Redis实战(二)中我们安装好了Redis的系统服务,此时Redis服务已经运行. 现在我们需要让我们的程序能正确读取到Redis服务地址等一系列的配置信息,首先,需要在Web.config文件中添加如下信息: [html] view plain copy <?xml version="1.0" encoding="utf-8"?> <!-- 有关如何配置 ASP.NET 应用程序的详细信息,请访问 http://go.mi

通过代码审计找出网站中的XSS漏洞实战(三)

一.背景 笔者此前录制了一套XSS的视频教程,在漏洞案例一节中讲解手工挖掘.工具挖掘.代码审计三部分内容,准备将内容用文章的形式再次写一此,前两篇已经写完,内容有一些关联性,其中手工XSS挖掘篇地址为快速找出网站中可能存在的XSS漏洞实践(一)https://segmentfault.com/a/1190000016095198 本文主要记录通过代码审计的方式进行XSS漏洞挖掘,分为了找出关键位置,正向审计,反向审计三个部分,审计的系统为permeate渗透测试系统,测试系统的搭建可以参考笔者的

python 协程库gevent学习--gevent数据结构及实战(三)

gevent学习系列第三章,前面两章分析了大量常用几个函数的源码以及实现原理.这一章重点偏向实战了,按照官方给出的gevent学习指南,我将依次分析官方给出的7个数据结构.以及给出几个相应使用他们的例子. 1.事件: 事件是一个可以让我们在Greenlet之间异步通信的形式贴上一个gevent指南上面的例子: import gevent from gevent.event import Event ''' Illustrates the use of events ''' evt = Event

应用程序框架实战三十六:CRUD实战演练介绍

从本篇开始,本系列将进入实战演练阶段. 前面主要介绍了一些应用程序框架的概念和基类,本来想把所有概念介绍完,再把框架内部实现都讲完了,再进入实战,这样可以让初学者基础牢靠.不过我的精力很有限,文章进度越来越慢,所以准备切换一下介绍顺序,把实战演练提前,以方便你阅读代码. 实战演练介绍 本系列实战演练共分两个部分. 实战演练第一部分介绍如何快速解决CRUD机械操作,这一部分我将手把手带领各位同学从搭建VS环境开始,创建程序集及各程序集间的依赖关系,以及引入依赖的外部DLL,并手工完成代码示例中Ap

应用程序框架实战三十八:项目示例VS解决方案的创建(一)

进行项目开发的第一步,是创建出适合自己团队习惯的VS解决方案,虽然我已经提供了项目示例,但毕竟是我创建的,你直接使用可能并不合适,另外你如果尝试模仿重新创建该示例,中间可能碰到各种障碍,特别是项目间的依赖关系. 本文的目的是帮助.Net架构初学者能顺利搭建起适合自己的VS解决方案,我会在本文演示曾经用过的几种不同风格的目录结构,你可以根据自己的习惯选择一种并自行修改. 本系列假定你已经熟悉如何创建.NET类库等基础知识,并具有.Net开发经验,我不会详细到每一个细节.如果你是.Net初学者,尚未