secure my vbscript (convert vbs to exe)

Hi,

I want secure my vbscript.

Convert vbs to exe, avantages : change icone, cannot edit script,...

Have you a solution to free convert and execute quickely script exe.

Best regards.

May 12th, 2010 3:08pm

Turn it into a visual basic.net program with the free Visual Basic 2010 Express:

http://www.microsoft.com/express/Downloads/#2010-Visual-Basic

Karl

Free Windows Admin Tool Kit Click here and download it now
May 12th, 2010 4:54pm

See if this will fit your needs.

http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/c0e7575a-6983-453b-8959-c6d889ccc01f

May 12th, 2010 4:59pm

Hi,

Thank LikeToCode.You solution not convenance me.

1.Scriptcryptor can convert and crypt code.But no free and for ex: vbscript 3 KB, exe 182 KB.Amount file.

scripte encoder to microsoft, .vbe file but easy to decode.

DoNetWrapper.vbs, shoulbe to souscribe :

http://windowsitpro.itpro.fr/Dossiers-par-Theme/suivante/3/2/050513096-Protegez-vos-scripts.htm#R5

Regards.

Free Windows Admin Tool Kit Click here and download it now
May 12th, 2010 5:54pm

Microsoft have a encoder available as well http://msdn.microsoft.com/en-us/library/d14c8zsc.aspx However it still only prevents a people from looking at your code, if they really want to see they can find a way.

 

May 27th, 2010 3:08am

Another option is to convert your vbs to a Windows Script Host file (.wsf) and then you are able to digitally sign the script, more information can be found here:

http://www.jensign.com/JavaScience/www/wsh/signascript/WshSign/index.html

http://msdn.microsoft.com/en-us/library/70c6wkt2%28VS.85%29.aspx

You'll need to have a valid certificate on the computer you're signing the script on as well as the computers you're running it on.

converting vbs to wsf is simple:

e.g.

script.wsf

<job id="main">
  <script language="JScript">
    WScript.Echo("JScript");
  </script>
  
  <script language="VBScript">
    WScript.Echo "VBScript"
    'Your vbscript code in here...
</script> </job>

 

 

 

Free Windows Admin Tool Kit Click here and download it now
May 28th, 2010 10:02am

How to turn vbs and js files into exe files from the command line

Any COM Automation programming language (that's all of them but especially VB6 which is what this object was designed for - it also applies to vbscript too).

Use the MS Script Control.

For those that don't have the great VB6 (a member of the same family as vbscript) here's how to make an exe with a script from the command line and notepad.
 
Create text file on desktop and name it VB2Exe.vb

The Scrpt string variable contains your script.

<code>
Public Module MyApplication 
Public Sub Main() 
Dim sc as object
Dim Scrpt as string
sc = createObject("MSScriptControl.ScriptControl")
Scrpt = "msgbox " & chr(34) & "Hi there" & chr(34)
     With SC
        .Language = "VBScript"
        .UseSafeSubset = False
        .AllowUI = True
 End With

sc.addcode(Scrpt)

End Sub
End Module

</code>

Looks fairly familar.

The .NET framework comes with compilers.


You need to make sure the path to the compiler is correct on your windows install.
 
In an elevated command prompt type

<code>
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /t:exe "%userprofile%\desktop\VB2Exe.vb"
</code>


Your first VBScript in an exe.

 

Here's sample vbs code that syntax checks scripts. But the global code does run in the script control. (even though I'm using executeglobal to run it for real).

It runs the vbs script specified against every line in a textstream (Inp) writing it to another textstream (Outp).

Ag(1) is the script to be added. I add extra script to the users script.

You need to define Inp, Outp, and Ag(1).

Note the syntax error checking and messages to the user.

Sub VBSCmd
 RawScript = Arg(1)
 'Remove ^ from quoting command line and replace : with vbcrlf so get line number if error
 Script = Replace(RawScript, "^", "")
 Script = Replace(Script, "'", chr(34))
 Script = Replace(Script, ":", vbcrlf)
 'Building the script with predefined statements and the user's code
 Script = "Dim gU" & vbcrlf & "Dim gdU" & vbcrlf & "Set gdU = CreateObject(" & chr(34) & "Scripting.Dictionary" & chr(34) & ")" & vbcrlf & "Function UF(L, LC)" & vbcrlf & "Set greU = New RegExp" & vbcrlf & "On Error Resume Next" & vbcrlf & Script & vbcrlf & "End Function" & vbcrlf
 'Testing the script for syntax errors
 On Error Resume Next
 set ScriptControl1 = wscript.createObject("MSScriptControl.ScriptControl",SC)
     With ScriptControl1
        .Language = "VBScript"
        .UseSafeSubset = False
        .AllowUI = True
  .AddCode Script
 End With
 With ScriptControl1.Error
  If .number <> 0 then
   Outp.WriteBlankLines(1)
   Outp.WriteLine "User function syntax error"
   Outp.WriteLine "=========================="
   Outp.WriteBlankLines(1)
   Outp.Write NumberScript(Script)
   Outp.WriteBlankLines(2)
   Outp.WriteLine "Error " & .number & " " & .description
   Outp.WriteLine "Line " & .line & " " & "Col " & .column
   Exit Sub
  End If
 End With
 ExecuteGlobal(Script)
 'Remove the first line as the parameters are the first line
 'Line=Inp.readline 
 Do Until Inp.AtEndOfStream
  Line=Inp.readline
  LineCount = Inp.Line
  
  temp = UF(Line, LineCount)
  If err.number <> 0 then
   outp.writeline ""
   outp.writeline ""
   outp.writeline "User function runtime error"
   outp.writeline "==========================="
   Outp.WriteBlankLines(1)
   Outp.Write NumberScript(Script)
   Outp.WriteBlankLines(2)
   Outp.WriteLine "Error " & err.number & " " & err.description
   Outp.WriteLine "Source " & err.source
   Outp.WriteLine "Line number and column not available for runtime errors"
   wscript.quit
  End If
  outp.writeline temp
 Loop
End Sub

Function NumberScript(Text)
 Text = Replace(Text, vbcr, "")
 LineArray=Split(Text,vblf)
 For i = 0 to UBound(LineArray, 1) - 1

  Count = Count + 1
  Temp = Temp & vbcrlf & Count & " " & LineArray(i)
 Next
 NumberScript = Temp
End Function

For a Windows Forms version (no console window and we don't get around to actually creating any forms - though you can if you want).
 
Compile line in a command prompt.
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /t:winexe "%userprofile%\desktop\VBS2Exe.vb"
Text for VBS2EXE.vb
Imports System.Windows.Forms 
Partial Class MyForm : Inherits Form 
Private Sub InitializeComponent() 
 
End Sub
Public Sub New() 
 InitializeComponent() 
End Sub
Public Shared Sub Main() 
Dim sc as object 
Dim Scrpt as string
sc = createObject("MSScriptControl.ScriptControl")
Scrpt = "msgbox " & chr(34) & "Hi there I'm a form" & chr(34)
     With SC 
        .Language = "VBScript"
        .UseSafeSubset = False
        .AllowUI = True
 End With
 
sc.addcode(Scrpt)
 
End Sub
End Class
Using these optional parameters gives you an icon and manifest. A manifest allows you to specify run as normal, run elevated if admin, only run elevated.
 
/win32icon:<file> Specifies a Win32 icon file (.ico) for the default Win32 resources.
 
/win32manifest:<file> The provided file is embedded in the manifest section of the output PE.
 
In theory, I have UAC off so can't test, but put this text file on the desktop and call it vbs2exe.manifest, save as UTF-8.   The command line  
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /t:winexe /win32manifest:"%userprofile%\desktop\VBS2Exe.manifest" "%userprofile%\desktop\VBS2Exe.vb"
 
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
    version="1.0.0.0"
    processorArchitecture="*"
    name="VBS2EXE"
    type="win32"
/>
<description>Script to Exe</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> 
    <security>
        <requestedPrivileges>
            <requestedExecutionLevel
                level="requireAdministrator"
                uiAccess="false"
            />
        </requestedPrivileges>
    </security>
</trustInfo>
</assembly>
 
 Hopefully it will now ONLY run as admin.     Give Access To a Host's Objects    Here's an example giving the vbscript access to a .NET object.  
Imports System.Windows.Forms    Partial Class MyForm : Inherits Form    Private Sub InitializeComponent()   
End Sub   Public Sub New()     InitializeComponent()    End Sub   Public Shared Sub Main()    Dim sc as object
Dim Scrpt as string
  sc = createObject("MSScriptControl.ScriptControl")   Scrpt = "msgbox " & chr(34) & "Hi there I'm a form" & chr(34) & ":msgbox meScript.state"        With SC
        .Language = "VBScript"
        .UseSafeSubset = False
        .AllowUI = True
        .addobject("meScript", SC, true)
 End With
 
sc.addcode(Scrpt)  
End Sub   End Class
 

To Embed version info

Download vbs2exe.res file from https://skydrive.live.com/redir?resid=E2F0CE17A268A4FA!121 and put on desktop.

Download ResHacker from http://www.angusj.com/resourcehacker/

Open vbs2exe.res file in ResHacker. Edit away. Click Compile button. Click File menu - Save.

Type

"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /t:winexe /win32manifest:"%userprofile%\desktop\VBS2Exe.manifest" /win32resource:"%userprofile%\desktop\VBS2Exe.res" "%userprofile%\desktop\VBS2Exe.vb"

October 5th, 2013 7:14am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics