0

This question may be a little stupid, but i'm curious if it is possible or not. I have a file named library.xxx(contains vbscript code), which contains predefined functions. And i have an other file test.vbs(also contains vbscript code, just here i use the functions, which are defined in library.xxx). In test.vbs the library is "included", which means, i can use the functions from library.xxx. For example, there is a function called ProgramFiles, and if i call it in test.vbs, i will receive the Program Files folder location.

The problem is, that library.xxx is visible in this way. There is an application called ScriptCryptor. With this application, i can open my library.xxx and make an .exe of it, which would be better for me, since it is not clear text.

My problem is now, how could i execute the command which are called in test.vbs? I think i should read line by line the test.vbs file, and process it somehow. But how? How do i know if the line i read is a function or just a variable? Or both? And how to process them?

Is there some way to do that?

Hopefully it is understandable what i want.

Thanks!

1 Answer 1

1

By far the easiest way to accomplish this is to include "library.vbs" in to your "test.vbs" file.

For example:

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

Your question seems to indicate that you may already be doing this so if you are then I apologize.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

If clear text truly is bothering you then from what I have seen there is no way to make the executable from ScryptCryptor to be made available to your vbscript.

Instead you could create a COM Library DLL to be used as an object in your test.vbs file.

The downside to this is that it will be necessary to learn a new language. Visual Studio Visual Basic certainly is different from Windows Shell Script Visual Basic but it would work for what you want.

Steps to take:

  1. Download Visual Studio 2013 Express for Windows Desktop (or trial version of Ultimate or whatever you feel is appropriate for you)
  2. Open Visual Studio as an Administrator
  3. Create a new Project. Select a "Class Library" under the "Visual Basic" templates
  4. Copy and paste the code below

    <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

  5. Click on Project -> ClassLibrary1 Properties

  6. Click on "Compile" and check the box for "Register for COM interop"
  7. Click on Build -> Build Solution

You now have a library that your test.vbs can use:

Set myLib = CreateObject("ClassLibrary1.OurLibrary")

mySource = "C:\mytextfile1.txt"
myDest = "C:\mytextfile2.txt"

myLib.mycopy mySource, myDest

If your like me test.vbs needed to be called as C:\Windows\SysWOW64\cscript.exe test.vbs

For more information about creating COM classes in Visual Basic see here: Walkthrough: Creating COM Objects with Visual Basic

Sign up to request clarification or add additional context in comments.

3 Comments

Yes, you are right. That's what i do now, but the clear text is big problem. With the ScriptCryptor generated .exe the teest.vbs, what was given as a parameter to the exe i was able to use the functions. That worked fine. The problem was "only" with the complicated statements. If i read a line, i can use Execute or ExecuteGlobal, to execute the current line, but if the line is a complex statement in a syntax that stays from more line, than i will get a syntax error. Example ´If Architecture = "x86" Then a=10 b=4 Else a=0 b=0 End If´ In this case if i read a line and execute it, i get a ...
...syntax error, because there is no else nor End If. I thought on the hard way to. Maybe it is possible to write a small function which read the line, and if there is no End If, then read it until it is found, store the lines in a variable, and then execute it. This could theoratically work. But it is not that simple to handle every possible syntax. This would theoratically do what i want. But who knows which case did i forget? :) I have to give it a try
in the first comment the example i wanted to write it in seperate rows.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.