当前位置:网站首页>Vbs script COM object extension and use (3)
Vbs script COM object extension and use (3)
2022-07-25 06:06:00 【N-order magic cube】
CreateObject, This command can access windows All installed in the system com object , And you can call the commands stored in these parts .
WSH It is used to parse Vbs Host of , It contains several common objects :
1、Scripting.FileSystemObject —> Provide a complete set of file system operation functions
2、Scripting.Dictionary —> The dictionary object used to return the key value pair
3、Wscript.Shell —> Provide a set of functions to read system information
( Such as reading and writing registry 、 Find the path to the specified file 、 Read DOS environment variable , Read the settings in the link )
4、Wscript.NetWork —> Provides functions for network connection and remote printer management .
notes : all Scripting Objects are stored in SCRRUN.DLL In file , be-all Wscript Objects are stored in WSHOM.ocx In file .
routine :
option Explicit ‘ All variables are executed before using options
dim objShell
' Object values must use SET Keyword assignment
set objShell = CreateObject("WScript.Shell")
' Nonblocking call , Sequential execution
objShell.Run "notepad"
' Blocking call ,APP Execute one after closing
objShell.Run "notepad" ,,true
' Nonblocking call , Turn on the calculator
objShell.Run "calc"
' notes : Avoid the problems caused by spaces , Use quotation marks ""
'Run " The program path ", Window style (0 Background operation ;1 The normal operation ;2 Activate minimize ;3 Activate maximize ;.....), Operation waiting (True)
objshell.Run """C:\Program Files\QQ2006\QQ.exe"""Two 、 Error handling
When the script does not work properly , Will cause runtime errors , ... will be displayed on the screen MsgBox.
On Error Resume Next
This line tells vbs Skip the statement with error at run time , Then execute the statement following it .
When something goes wrong , This statement will put the relevant error number 、 The error description and related source code are pushed into the error stack .
vbscript Provides a err object
Two methods clear,raise,
5 Attributes :description,helpcontext,helpfile,number,source
err Objects do not reference instances , You can use it directly , for example :
on error resume next
a=11
b=0
c=a/b
if err.number<>0 then
wscript.echo err.number & err.description & err.source
end if
3、 ... and 、 Registry operation
1、 Read registry Wscript.Shell.Regread
set ws = wscript.createobject("Wscript.Shell")
value = ws.regread("HKLM\Software\7-Zip\Path ")
wscript.echo value
2、 Write registry Wscript.Shell.Regwrit
path="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\"set ws=wscript.createobject("wscript.shell")
t=ws.regwrite(path & "jj","hello")
' Create a new value
val=ws.regwrite(path,"newboy")
notes : Run\jj This key value is changed to hello.( The key value must exist in advance )
3、 Delete keywords and values Wscript.Shell.Regdelete
val=ws.Regdelete(path)
Four 、 File system operations ( important )
SET FSOobj = Wscript.createobject("Scripting.FileSystemObject")
1、FSO Common objects included are :
Drive object : Contains information about storage devices , Including hard disk 、 CD drive 、ram disc 、 Network drive
Drives aggregate : Provide a list of physical and logical drives
File object : Check and process documents
Files aggregate : Provide a list of files in the folder
Folder object : Check and handle folders
Folders aggregate : Provide a list of subfolders in the folder
Textstream object : Read write text file
FSO The common methods are :
BulidPath: Add the file path information to the existing file path
CopyFile: Copy file
CopyFolder: Copy folder
CreateFolder: Create folder
CreateTextFile: Create text and return a TextStream object
DeleteFile: Delete file
DeleteFolder: Delete the folder and all its contents
DriveExits: Determine whether the drive exists
FileExits: Determine whether a file exists
FolderExists: Determine whether a folder exists
GetAbsolutePathName: Return the absolute path of a folder or file
GetBaseName: Return the basic path of a file or folder
GetDrive: Return to one dreve object
GetDriveName: Returns the name of a drive
GetExtensionName: Return extension
GetFile: Return to one file object
GetFileName: Return the file name in the folder
GetFolder: Return a folder object
GetParentFolderName: Return to the parent folder of a folder
GetSpecialFolder: Returns an object pointer to a special folder
GetTempName: Returns one that can be createtextfile The name of the randomly generated file or folder used
MoveFile: Moving files
MoveFolder: Move folder
OpenTextFile: Open an existing file and return a TextStream object
2、 Folder operation, etc
' Creating models
DIM objFS
SET objFS = Wscript.createobject(“Scripting.FileSystemobject”)
' Release model
'SET objFS = nothing
if ( objFS.FolderExists("c:\temp") ) ' Check whether the folder is large
objFS.Deletefolder("c:\temp") ' Delete folder
objFS.CopyFolder "c:\data" "d:\data",'True ' Copy folder , Overlay options
objFS.movefolder "c:\data\te*" "d:\data\" '\ Automatically create d:\data Folder
objFS.getspecialfolder(0) ' return windows Catalog
objFSgetspecialfolder(1) ' return system32\
objFSgetspecialfolder(2) ' Return to the temporary directory 3、 File operation, etc. stay windows in , The attributes of files are generally expressed in numbers :
0 representative normal, That is, ordinary files do not set any properties . 1 Represents a read-only file .
2 Represents hidden files . 4 Represents system files . 16 Represents a folder or directory .
32 On behalf of archived documents . 1024 Represents a link or shortcut .
Column attribute ( The column number of the current character position ) and line attribute ( Current line number of the file ): After opening a file , Both row and column pointers are set to 1.
' Check the creation file
set fso = wscript.createobject(“scripting.filesystemobject”)
if fso.fileexists(“c:\kk.txt”) then
msgbox " file already exist "
else
set f = fso.createtextfile("c:\kk.txt" ', true ' ) 'true Parameters : Overwrite existing files
end if
fso.copyfile "c:\kk.txt","d:\1\kk.txt", true 'rue Represents mandatory override
fso.movefile "c:\kk.txt", "d:\" ' Moving files
fso.deletefile "c:\kk.txt" ' Delete file
set ts = fso.opentextfile(“c:\kk.txt”,1,true) ' Open file :1 As read-only 、2 write in 、8 To add
set ffile=fso.opentextfile(“c:\kk.txt”,1,true)
value=ffile.read(20) 'read(x) read x Characters
line=ffile.readline 'readline Read a line
contents=ffile.readall 'readall Read all
do while ffile.atendofstream<>true ' At the end of the line , This property returns true.
ffile.read(10)
loop skip(x) skip x Characters ;skipline Skip a line
write(x) write in x character string ;
writeline(x) write in x The line represented
writeblanklines(n) write in n Empty rows
lose Method to close the file , Be sure to close after reading the file , Can be opened in writing .
边栏推荐
- Detailed explanation of stepn chain game system development mode (Sports money making mode)
- 同条网线电脑正常上网,手机连接wifi成功,但是无法访问互联网
- UML modeling tools Visio, rational rose, powerdesign
- Binary search tree (day 75)
- Productivity tool in the new era -- flowus information flow comprehensive evaluation
- Promise implementation
- 有什么能在网上挣钱的项目啊?做自媒体靠谱吗?
- Detailed annotation and analysis of start.s of uboot
- 新时代生产力工具——FlowUs 息流全方位评测
- U-boot-1.1.6 transplant notes (beginner)
猜你喜欢

Productivity tool in the new era -- flowus information flow comprehensive evaluation
![(16) [system call] track system call (3 rings)](/img/b0/011351361135fd9f8e2d0d31749f73.png)
(16) [system call] track system call (3 rings)

(Niuke multi School II) G-LINK with monotonic subsequence (construction question)

Data too long for column ‘data‘ at row 1以及设置成longblob造成的乱码解决。node-mysql

Pdf snapshot artifact

Prometheus operator configures promethesrule alarm rules

(牛客多校二)G-Link with Monotonic Subsequence(构造题)

Design of automatic machine dot drawing script based on C language

HTB-Devel

深度解析:2022年最火的商业模式链动2+1,是合法模式吗?
随机推荐
剖析kubernetes集群内部DNS解析原理
Leetcode/ integer division
[daily practice] day (14)
(2022 Niuke multi School II) l-link with level editor I (dynamic planning)
New developments in Data Governance: what is the impact of the EU's Data Governance Research Report on China
In depth analysis: is the hottest business model in 2022 linked by 2+1 a legal model?
What projects can make money online? Is it reliable to be we media?
(16) [system call] track system call (3 rings)
(牛客多校二)J-Link with Arithmetic Progression(最小二乘法/三分)
Ceres solver version 1.14 and eigen3.2.9
Qunhui NPV Suite (NPV server) Download
出于数据安全考虑,荷兰教育部要求学校暂停使用 Chrome 浏览器
(16)[系统调用]追踪系统调用(3环)
二叉搜索树(DAY 75)
Ffmpeg notes (I) fundamentals of audio and video
【C语言】指针和数组的深入理解(第一期)
R language uses rowmedians function to calculate the row data median value of all data rows in dataframe
Xiaomi 12s UTRA Leica watermark generation online tool
R language ggpubr package ggarrange function combines multiple images and annotates_ Figure add annotation, annotation, annotation information for the combined image, and use the right parameter to ad
Detailed explanation of arm instruction CMP