这个问题可能有点愚蠢,但我很好奇是否有可能。 我有一个名为library.xxx(包含vbscript代码)的文件,其中包含预定义的函数。我有一个其他文件test.vbs(也包含vbscript代码,在这里我使用的函数,在library.xxx中定义)。在test.vbs中,库是“包含”的,这意味着,我可以使用library.xxx中的函数。例如,有一个名为ProgramFiles的函数,如果我在test.vbs中调用它,我将收到Program Files文件夹位置。
问题是,library.xxx以这种方式可见。有一个名为ScriptCryptor的应用程序。有了这个应用程序,我可以打开我的library.xxx并制作它的.exe,这对我来说会更好,因为它不是明文。
我现在的问题是,如何执行test.vbs中调用的命令?我想我应该逐行读取test.vbs文件,并以某种方式处理它。但是怎么样?我怎么知道我读的线是函数还是变量?或两者?以及如何处理它们?
有没有办法做到这一点?
希望我想要的是可以理解的。
谢谢!
答案 0 :(得分:0)
到目前为止,最简单的方法是将“library.vbs”包含在“test.vbs”文件中。
例如:
Library.vbs:
Function ProgramFiles()
ProgramFiles = "C:\Foo"
End Function
test.vbs:
sub includeFile (fSpec)
dim fileSys, file, fileData
set fileSys = createObject ("Scripting.FileSystemObject")
set file = fileSys.openTextFile (fSpec)
fileData = file.readAll ()
file.close
executeGlobal fileData
set file = nothing
set fileSys = nothing
end sub
includeFile "library3.vbs"
wscript.echo ProgramFiles
你的问题似乎表明你可能已经这样做,所以如果你那么我道歉。
= - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - =
如果明文确实困扰你,那么从我看到的情况来看,没有办法让ScryptCryptor的可执行文件可用于你的vbscript。
相反,您可以创建一个COM库DLL,用作test.vbs文件中的对象。
这样做的缺点是有必要学习一门新语言。 Visual Studio Visual Basic肯定与Windows Shell脚本Visual Basic不同,但它可以满足你的需要。
采取的步骤:
复制并粘贴以下代码
<ComClass(OurLibrary.ClassId, OurLibrary.InterfaceId, OurLibrary.EventsId)>
Public Class OurLibrary
Private userNameValue As String
Public Const ClassId As String = "40491A82-D53A-46A6-B7E0-1CDF78A33AB6"
Public Const InterfaceId As String = "B49C996C-B039-471D-BF17-0DDA5B3CF517"
Public Const EventsId As String = "6245E3DD-DEB5-4B75-AC03-F4430BC18FDE"
Public Sub New()
MyBase.New()
End Sub
Public Sub mycopy(mySource As String, myDest As String)
My.Computer.FileSystem.CopyFile(mySource, myDest, True)
End Sub
End Class
点击项目 - &gt; ClassLibrary1属性
您现在有一个test.vbs可以使用的库:
Set myLib = CreateObject("ClassLibrary1.OurLibrary")
mySource = "C:\mytextfile1.txt"
myDest = "C:\mytextfile2.txt"
myLib.mycopy mySource, myDest
如果你喜欢我test.vbs需要被称为C:\Windows\SysWOW64\cscript.exe test.vbs
有关在Visual Basic中创建COM类的详细信息,请参阅此处:Walkthrough: Creating COM Objects with Visual Basic