VBS中inlcude另一个vbs脚本的方法

VBS中inlcude另一个vbs脚本的方法
54powerman
' Test program for the IncludeFile and ReadConfigFile functions.
' Author: Christian d'Heureuse (www.source-code.biz)
' License: GNU/LGPL (http://www.gnu.org/licenses/lgpl.html)

Option Explicit

Dim fso: set fso = CreateObject("Scripting.FileSystemObject")

' Includes a file in the global namespace of the current script.
' The file can contain any VBScript source code.
' The path of the file name must be specified relative to the
' directory of the main script file.
Private Sub IncludeFile (ByVal RelativeFileName)
   Dim ScriptDir: ScriptDir = fso.GetParentFolderName(WScript.ScriptFullName)
   Dim FileName: FileName = fso.BuildPath(ScriptDir,RelativeFileName)
   IncludeFileAbs FileName
   End Sub

' Includes a file in the global namespace of the current script.
' The file can contain any VBScript source code.
' The path of the file name must be specified absolute (or
' relative to the current directory).
Private Sub IncludeFileAbs (ByVal FileName)
   Const ForReading = 1
   Dim f: set f = fso.OpenTextFile(FileName,ForReading)
   Dim s: s = f.ReadAll()
   ExecuteGlobal s
   End Sub

IncludeFile "MyClass.vbs"
Dim test
Set test = new MyClass
test.MyFunc

 

VBS中inlcude另一个vbs脚本的方法
54powerman
' Test program for the IncludeFile and ReadConfigFile functions.
' Author: Christian d'Heureuse (www.source-code.biz)
' License: GNU/LGPL (http://www.gnu.org/licenses/lgpl.html)

Option Explicit

Dim fso: set fso = CreateObject("Scripting.FileSystemObject")

' Includes a file in the global namespace of the current script.
' The file can contain any VBScript source code.
' The path of the file name must be specified relative to the
' directory of the main script file.
Private Sub IncludeFile (ByVal RelativeFileName)
   Dim ScriptDir: ScriptDir = fso.GetParentFolderName(WScript.ScriptFullName)
   Dim FileName: FileName = fso.BuildPath(ScriptDir,RelativeFileName)
   IncludeFileAbs FileName
   End Sub

' Includes a file in the global namespace of the current script.
' The file can contain any VBScript source code.
' The path of the file name must be specified absolute (or
' relative to the current directory).
Private Sub IncludeFileAbs (ByVal FileName)
   Const ForReading = 1
   Dim f: set f = fso.OpenTextFile(FileName,ForReading)
   Dim s: s = f.ReadAll()
   ExecuteGlobal s
   End Sub

IncludeFile "MyClass.vbs"
Dim test
Set test = new MyClass
test.MyFunc

MyClass.vbs代码

Class MyClass
   Public Function MyFunc
   MsgBox "测试VBS调用VBS类"
  End Function
End Class

时间: 2024-09-19 20:44:12

VBS中inlcude另一个vbs脚本的方法的相关文章

对一个vbs脚本病毒的病毒原理分析_vbs

一.前言 病毒课老师丢给我们一份加密过的vbs脚本病毒的代码去尝试分析,这里把分析过程发出来,供大家参考,如果发现文中有什么错误或者是有啥建议,可以直接留言给我,谢谢! 二.目录 整个分析过程可以分为以下几个部分: 0x00 准备工作 0x01 解密部分 0x02 功能分析 三.分析过程 0x00 准备工作 windows xp的虚拟机(在自己的windows下也可以做) vbs的一些基本语法 0x01 解密部分 右击病毒文件然后编辑打开或者是直接把其后缀修改成txt直接打开都行,可以看到一大段

用vbs 实现从剪贴板中抓取一个 URL 然后在浏览器中打开该 Web 站点_vbs

问: 嗨,Scripting Guy!我如何从剪贴板中抓取一个 URL 然后在浏览器中打开该 Web 站点? -- CL 答: 您好,CL.这是很有趣的问题,或者我们应当说,这是两个很有趣的问题.因为您实际上问了两个问题.第一个问题很简单:我可以使用脚本打开特定的 Web 站点吗?您大概已经知道答案了,我可以大声地回答您,可以!下面是一个示例脚本,它将"脚本中心"的 URL 存储在一个名为 strURL 的变量中.然后,此脚本会创建 WSH Shell 对象的一个实例,并使用 Run 

windows-关于VBS中调用MSWINsock.Winsock

问题描述 关于VBS中调用MSWINsock.Winsock 目前在编写一个通过TCP协议给server发送特定消息的小程序. 发送代码如下: msglog=vbslogFile.ReadLine dim sock '赋值sock变量为WINSOCK的对象 set sock=Wscript.createobject("MSWINsock.Winsock") '设置SOCK的连接方式为 TCP 'WINSOCK的Protocol属性中 0 表示TCP,1 表示 UDP sock.Prot

VBS中CreateObject和WScript.CreateObject的区别

多VBS新手都很困惑CreateObject和WScript.CreateObject有什么区别,为什么一些代码中用CreateObject,而另一些却用WScript.CreateObject? CreateObject和WScript.CreateObject的区别一: CreateObject是VBS的内置函数,属于语言的一部分:而WScript.CreateObject是Windows脚本宿主(wscript.exe和cscript.exe)提供的WScript对象的方法.类似于批处理中

VBS中InStrRev函数的第三个参数(Start)使用注意事项_vbs

VBS中InStrRev函数使用过不少,但是几乎没有用过第三个参数,今天才发现第三个参数的用法跟我想的不太一样. 文档中是这么描述InStrRev函数的: 复制代码 代码如下: 返回某字符串在另一个字符串中出现的从结尾计起的位置. InStrRev(string1, string2[, start[, compare]]) 参数 string1 必选项.接受搜索的字符串表达式. string2 必选项.被搜索的字符串表达式. Start 可选项.数值表达式,用于设置每次搜索的开始位置.如果省略,

VBS中CreateObject和WScript.CreateObject的区别介绍_vbs

CreateObject和WScript.CreateObject的区别一: CreateObject是VBS的内置函数,属于语言的一部分:而WScript.CreateObject是Windows脚本宿主(wscript.exe和cscript.exe)提供的WScript对象的方法.类似于批处理中内部命令和外部命令的关系.在VBS中,CreateObject总是可用的,而WScript.CreateObject只有在宿主为wscript.exe和cscript.exe的情况下才可以使用,在W

VBS中Run和Exec的区别_vbs

Set ws = CreateObject("WScript.Shell") '这里创建一个对象引用,以便在以下示例代码中使用. 'Demon注:这个变量名怎么这么猥琐(WS) 语法:(常识(Demon注:常识这个词我喜欢):作为过程使用时,不要加括号,否则出现编译器错误(参数唯一或没有时加括号不会出错,但建议不要加)) 复制代码 代码如下: ws.Run(strCommand, [intWindowStyle], [bWaitOnReturn]) [Set objExec =] ws

在VBS中定义字节数组Byte()介绍_vbs

晚上在 QQ 上看到昵称为"乱码"的好友回答了搜搜问问里一个问题: 在VBS中有办法定义字节数组么? 在VBS中有办法定义字节数组么?就是字节子类型数组(VarType是8209的那种)注意不是VB! 但是回答实在是不堪入目,连别人问什么都没搞懂,而且那人居然还满意,真不知道他在想什么. 闲来没事,我来简单回答一下.首先要搞清楚别人在问什么,VBS 是弱类型脚本语言,只有一种数据类型,称为 Variant,但是 Variant 可以进一步分为几种子类型,这里不展开,详见<VBSc

VBS中的正则表达式的用法大全[原创]_正则表达式

VBS正则表达式函数 主要用在asp中效果明显 1.表单验证功能 复制代码 代码如下: Function Validate(strng,patrn)   Dim regEx   Set regEx = New RegExp   regEx.Pattern = patrn   regEx.IgnoreCase = True   regEx.Global = True   Validate = regEx.test(strng)   Set regEx = Nothing  End Function