WSF VBS 腳本編寫

WSH – Windows Script Host (Windows腳本宿主)  是一個基於COM的腳本宿,它可以在Windows中執行腳本。它同時支持JscriptVBScript.

.WSC - windows 腳本組件。例如VBS本身沒有提供訪問文件系統的方法,但是可以使用Scripting.FileSystemObject  COM組件來打開文件。 WSC文件是一個XML格式的文本文件,它提供一系列的元素的屬性來定義一個對象的接口(例如用於腳本調用的屬性和方法),同時它本身也是用腳本語言實現。WSC文件有自己的XML元素列表:

<component>元素封裝一個腳本組件的整個定義。其他屬性如:description =”description”, progid=”progid”, classid=”GUID”, version=”vesrion”

 

.WSF – Windows腳本文件採用XML文件。他能包含獨立代碼,不像獨立腳本,wsf腳本可以包含其他文件的VBSJS代碼。

Sample:讀取一個文件,替換裏邊的內容然後在寫回去

<job id="main">

<scriptlanguage="VBScript"

SetFSO=CreateObject("scripting.filesystemobject")

Set objFile=FSO.OpenTextFile("D:\package\Builds\ePrint\Win32\Release\hpbje1101.inf",1,false)

objContents = objFile.ReadAll

BeginStr =InStr(1,objContents,"DriverVer = ")

EndStr =InStr(BeginStr,objContents,"CatalogFile")

DriverRevision =Mid(objContents,BeginStr+30,EndStr-BeginStr-32)

objFile.Close

SetobjFile=FSO.OpenTextFile("D:\automation\ComponentTests\PrintDriver\ePrint\1.0\config\FileVersionsConfigePrint.tcc",1,false,-1)

objContentsConfigTCC =Replace(objFile.ReadAll,"DriverRevisonFromVBs",DriverRevision)

objFile.Close

SetobjFile=FSO.OpenTextFile("D:\automation\ComponentTests\PrintDriver\ePrint\1.0\config\FileVersionsConfigePrint.tcc",2,false,-1)

objFile.Write objContentsConfigTCC1

objFile.Close

                </script>

</job>

 

.VBS 普通的VBS腳本

Sameple1:讀取一個文件裏面的內容,讓後返回給cmd腳本

.vbs 文件中的內容

dim return

SetFSO=CreateObject("scripting.filesystemobject")

SetobjFile=FSO.OpenTextFile("D:\package\spo\UPD\pcl6\win_xp_vista\hpcu118c.inf",1,false)

objContents = objFile.ReadAll

BeginStr =InStr(1,objContents,"DriverVer=")

EndStr =InStr(BeginStr,objContents,"DriverIsolation")

DriverRevision =Mid(objContents,BeginStr+31,EndStr-BeginStr-33)

objFile.Close

return = DriverRevision

wscript.echo return

 

.cmd 文件中的內容

for /f "tokens=*" %%iin ('cscript /nologo"D:\automation\ComponentTests\PrintDriver\Evo\config\GetEvoDriverRevision.vbs"')do (

Set Revision=%%i)

 

Sample2:獲取一個路徑下的所有文件列表

Set fso =CreateObject("Scripting.FileSystemObject")

Set f = fso.GetFolder("c:/")   

Set fs = f.Files

i = 0  

For Each f1 in fs

fn = f1.name        

i=i+1

msgbox fn

Next

發佈了38 篇原創文章 · 獲贊 3 · 訪問量 18萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章