WindowsScript

本文介绍了Windows脚本编程,包括Windows Script Host、VBScript和JScript。内容涵盖对象、属性和方法、常用组件如HTTP、图像处理和文件操作,以及Shell的使用,如模拟按键、执行命令和操作环境变量。此外,还涉及WMI和如何利用它们进行系统管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

WindowsScript

更多请见个人主页https://www.bajins.com

flag

  • JScriptVBScript同属于官方支持的Windows Script,这俩脚本都需要依赖于特定的宿主(Host)才能执行,
    JavaScript浏览器环境之外,还可以运行在Windows Script Host中。
  • Windows Script Host是一个language-independent的脚本宿主环境,主要用于执行Windows管理任务
  • Windows脚本宿主有两个版本:
    • 一个基于Windows的版本(WScript.exe
      ,它提供用于设置脚本属性的属性表;运行以vbs为后缀的文件
    • 一个基于命令提示符的版本(CScript.exe
      直接执行可查看帮助),它提供命令行。用于设置脚本属性的开关。
      • //E:engine 使用执行脚本的引擎有:VBScriptJScript

WScript对象

所有的Wscript对象都存放在WSHOM.ocx文件中

WScript对象的属性

属性 返回值类型 说明
Application Object 返回 IHost_Class 对象(Wscript 对象)。
Arguments IArguments_Class 返回 WshArguments 对象(参数集)。
BuildVersion Long 返回 Windows 脚本宿主的内部版本。
FullName String 返回宿主可执行文件(CScript.exe 或 WScript.exe)的全路径。
Interactive Boolean 设置或确定脚本模式。
Name String WScript 对象(宿主可执行文件)的名称。
Path String 返回包含宿主可执行文件(CScript.exe 或 WScript.exe)的路径名称。
ScriptFullName String 返回当前运行脚本的完整路径。
ScriptName String 返回当前运行脚本的文件名。
StdIn TextStream 显示当前脚本的输入流。
StdErr TextStream 显示当前脚本的错误输出流。Write输出,WriteLine换行输出
StdOut TextStream 显示当前脚本的输出流。Write输出,WriteLine换行输出
Timeout Long 超时设定秒:允许脚本运行的最长时间。
Version String 返回 Windows 脚本宿主的版本。

WScript对象的方法

方法 参数 返回值 说明
ConnectObject (Object As Object, Prefix As String) 将对象的事件源连接到具有给定前缀的函数。
CreateObject (ProgID As String, [Prefix As String]) Object 创建对象。
DisconnectObject (Object As Object) 断开已连接对象的事件源的连接。
Echo (ParamArray pArgs() As Variant) 将文本输出到消息框中或命令控制台窗口。
GetObject (Pathname As String, [ProgID As String], [Prefix As String]) Object 检索现有的对象或从文件中创建新对象。
Quit ([ExitCode As Long]) 强制脚本停止执行。
Sleep (Time As Long) 在指定的时间长度内将脚本执行挂起,然后继续执行。

常用组件对象

所有对象都可通过Power Shell命令查看属性和方法New-Object -ComObject "对象名称" | Get-Member
获取本机所有COM组件对象脚本 Get-COM-Objects.bat

都在注册表HKEY_CLASSES_ROOT注册表项中,正常情况下项中带有CLSID键的是脚本可创建的

对象 说明
WScript.Shell 脚本外壳
Wscript.NetWork 提供网络连接和远程打印机管理的函数。
ADODB对象 说明
ADODB.Command
ADODB.Connection 提供数据库连接对象
ADODB.Error
ADODB.Parameter
ADODB.Record
ADODB.Recordset 提供数据库返回结果集对象
ADODB.Stream
ADOMD.Catalog
ADOMD.Cellset
ADOX.Catalog 包含描述数据源模式目录的集合
ADOX.Column 表示表、索引或关键字的列
ADOX.Group 表示在安全数据库内有访问权限的组帐号
ADOX.Index 表示数据库表中的索引
ADOX.Key 表示数据库表中的主关键字、外部关键字或唯一关键字
ADOX.Procedure 表示存储的过程
ADOX.Table 表示数据库表,包括列、索引和关键字
ADOX.User 表示在安全数据库内具有访问权限的用户帐号
ADOX.View 表示记录或虚拟表的过滤集
office对象 说明
Word.Application office
Word.Document
Excel.Application 提供EXCEL操作对象
Excel.Chart
Excel.Sheet
Outlook.Application office
PowerPoint.Application office
MSGraph.Application office
WIA对象 说明
WIA.ImageFile
System Administration Scripting Guide Script Repository Version 1.0, May 2002 The scripts included in this help file are likely to appear in the forthcoming System Administration Scripting Guide, which will ship as part of the Windows .NET Server Resource Kit. In the Scripting Guide itself, each script will be explained in step-by-step fashion, and instructional material will help you learn how to modify these scripts to suit your unique individual needs. In addition, the book will also teach you how to write your own scripts using VBScript, WMI, ADSI, and other Microsoft Scripting technologies. Most of the scripts are designed to run with either Windows 2000, Windows XP, or Windows .NET Server. Scripts that are not designed to run on all these platforms include a brief note indicating which versions of Windows are required. To use the scripts, copy the appropriate script code, paste it into Notepad or another text editor, and save the file with a .vbs file extension. For more information about these scripts or about the book, contact the Scripting Guide team at scripter@microsoft.com A Note About the WMI Scripts Most of the WMI scripts in this repository create a variable named strComputer, and then set the value of that variable to "." Thus, the scripts generally include this line: strComputer = "." This causes the script to run against the local computer. This is due to the way that the script has been composed, and the fact that WMI views a computer named "." as being the local computer. If you want to run the script against a remote computer, simply replace the "." with the name of the remote computer, surrounded by double quotation marks. For example, this line of code runs the script against a remote computer named PrintServer1: strComputer = "PrintServer1" This is the only change you need to make in order to run the WMI scripts against a remote computer. Bear in mind, however, that you will need to have administrative rights on the remote computer in order for the script to succeed. In addition, WMI must be installed both on the local computer and on the remote computer.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值