strComputer = "."
Set objWMIService = GetObject("winmgmts://" & strComputer & "/root/wmi")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("Select * from MSNdis_StatusMediaDisconnect")
Do While True
Set strLatestEvent = colMonitoredEvents.NextEvent
Wscript.Echo "A network connection has been lost:"
WScript.Echo strLatestEvent.InstanceName, Now
Wscript.Echo
Loop
调用方法示例:cscript 网络断开.vbs >> F:/test/微软脚本/log.txt
二、在网络硬件连接成功或网络故障恢复连接时发送警告
strComputer = "."
Set objWMIService = GetObject("winmgmts://" & strComputer & "/root/wmi")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("Select * from MSNdis_StatusMediaConnect")
Do While True
Set strLatestEvent = colMonitoredEvents.NextEvent
Wscript.Echo "A network connection has been made:"
WScript.Echo strLatestEvent.InstanceName, Now
Wscript.Echo
Loop
调用方法示例:cscript 网络连接.vbs >> F:/test/微软脚本/log.txt
三、获取所有域用户信息
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
"Select Name, Location from 'LDAP://DC=DomainName,DC=com' " _
& "Where objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value
Wscript.Echo "Location: " & objRecordSet.Fields("Location").Value
objRecordSet.MoveNext
Loop
调用方法示例:cscript 域用户信息.vbs >> F:/test/微软脚本/域用户信息.txt
四、修改文本文件内容
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("sample.ini", ForReading)
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
intLineFinder = InStr(strNextLine, "UserName")
If intLineFinder <> 0 Then
strNextLine = "UserName=邀月工作室"
End If
strNewFile = strNewFile & strNextLine & vbCrLf
Loop
objTextFile.Close
Set objTextFile = objFSO.OpenTextFile("sample.ini", ForWriting)
objTextFile.WriteLine strNewFile
objTextFile.Close
调用方法示例:ModifyFile.vbs
附件:
Sample.ini:
[OEM Install]
ProgGroupName=
DefaultDestDir=
UserName=
UserCompanyName=
UserSerialNumber=
五、通过脚本发送电子邮件
从安装了 SMTP Service 的计算机中发送电子邮件的脚本。
脚本代码
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "monitor1@fabrikam.com"
objEmail.To = "admin1@fabrikam.com"
objEmail.Subject = "Atl-dc-01 down"
objEmail.Textbody = "Atl-dc-01 is no longer accessible over the network."
objEmail.Send
调用方法示例:SendMail.vbs
六、在没有 SMTP Service 的条件下发送电子邮件
脚本设计用来在 Microsoft 的公司网络上进行工作。
Set objEmail = CreateObject("CDO.Message")
objEmail.From = "admin1@fabrikam.com"
objEmail.To = "admin2@fabrikam.com"
objEmail.Subject = "Server down"
objEmail.Textbody = "Server1 is no longer accessible over the network."
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
"smarthost"
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
调用方法示例:SendMailNoSMTP.vbs
七、将新的记录添加到数据库中
通过脚本检索计算机声卡的信息,然后将这些信息保存到带有 DSN Inventory 的 ADO 数据库中。
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
objConnection.Open "DSN=Inventory;"
objRecordset.CursorLocation = adUseClient
objRecordset.Open "SELECT * FROM Hardware" , objConnection, _
adOpenStatic, adLockOptimistic
Set colSoundCards = GetObject("winmgmts:").ExecQuery _
("Select * from Win32_SoundDevice")
For Each objSoundCard in colSoundCards
objRecordset.AddNew
objRecordset("ComputerName") = objSoundCard.SystemName
objRecordset("Manufacturer") = objSoundCard.Manufacturer
objRecordset("ProductName") = objSoundCard.ProductName
objRecordset.Update
Next
objRecordset.Close
objConnection.Close
调用方法示例:AddOneRecord.vbs
相关推荐
提高计算机性能的 4 种方法(摘自微软) ....
从微软技术资源库中搜集整理的部分内容。主要是一些与性能相关的系统视图,含有对每个字段最准确和详细的说明。。
TI电源管理方案,摘自TI官方网站,可以通过学习提高自己电源知识
行测资料分析技巧-摘自学宝公务员网站.doc
个世界顶级摄影及相关网站-摘自《影像视觉》杂志(完整版).doc
Pass4side 微软认证 70-284 最近才更新的考题,摘自:www.pass4side.com 网站
湖南大学ACM网站试题分类(摘自湖南大学ACM论坛)... 希望对大家有所帮助.....
微软Malmo项目是一个人工智能系统,用Minecraft World来测试人工智能算法。Malmo项目以前被称为AIX项目,该平台研发目的是为初创公司提供便宜,有效的方法,来测试人工智能程序,而无需建立机器人使用物理物体进行...
Windows server 2012下powershell的使用说明,摘自微软网站
缠师心法荟萃(摘自悟多整理的缠中说禅博客回复).doc
proe工程图培训 简单明了的培训内容 摘自互联网 共享于此 感谢作者
Stellarium脚本和资源 该存储库包含用于Stellarium天文软件的脚本和资源。 脚本以Typescript编写。 有关如何设置与Stellarium一起使用的Visual Studio Code和Typescript的说明,请转到: ... (摘自AutumnSky脚本)
数据结构快速自学教材,摘自数据结构自考网站,http://student.zjzk.cn/course_ware/data_structure/web/main.htm。 CSDN以前也有别人发的相同资料,但它是用离线浏览工具自动下载的,由于网站不支持拷贝图片,所以...
从IBM中文网站上下的资料,整理成CHM格式 摘自红皮书《IBM eserver pSeries HACMP V5.x Certification Study Guide Update》
C语言读取汉字字模 摘自网络
摘自linuxForum 经典帖子
对软件可维护性的说明,摘自软件工程书籍。希望对大家有用。
wireshare使用文档摘自“小坦克”
0535、运放的应用(摘自OHM丛书).rar 目前广泛应用的电压型集成运算放大器是一种高放大倍数的直接耦合放大器。在该集成电路的输入与输出之间接入不同的反馈网络,可实现不同用途的电路,例如利用集成运算放大器可非常...