locked
Convert .vbs to .exe

    Question

  • I make a vbs to exe compiler,but i dont know how to do that.Help pleaze.
    Sorry for my bad english.
    Monday, April 13, 2009 6:16 PM

Answers

  • Hi,

    No your right, thought the idea was to stop users from modifying it. People who need to run it can open and read it. It's a trust thing if you can execute it you have to read it.

    I think honestly now your best bet is to use the earlier recommendation by Deborahk. Everything else has been exhausted, writing something yourself really isn't as simple as you may think otherwise everyone here would have told you how to go about it. 

    Here is one last idea, just came to me actually as I wrote the above. If this isn't good enough then I don't know what is.

    May I recommend something, hope you don't mind, but when you post try not define the solution. In other words post what you want to do and not necessary how you want to do it. When you make a suggestion on a potential solution (write a compiler) the focus becomes the solution and not the problem, when you state the problem (protecting VBScripts from reading and writing but still executing) then you'll get a variety of solutions.

    Just a posting tip for the future.

    Ok try this, create a new project and double click MyProject in the solution explorer. Goto the resources tab and along the top select the small down arrow next to the Add Resource button. Select Add Existing File. Select a VBS file. This will embed the script into the application as a text file but thats fine. Then you can use this code to save and run the script....

            'get a temp file name and directory
    
            Dim tempScript As String = Path.GetTempFileName
    
            'replace tmp extension with vbs extension
    
            tempScript = tempScript.Replace(".tmp", ".vbs")
    
    
    
            'save the embedded script to the file
    
            File.WriteAllText(tempScript, My.Resources.VBScriptSample)
    
    
    
            'run the script
    
            Dim script As Process = Process.Start(tempScript)
    
            script.WaitForExit() 'wait for it to finish
    
    
    
            'delete the script
    
            File.Delete(tempScript)
    
    
    My.Resources.VBScriptSample is the name of the resource that was added. This embeds the script and then extracts it out, runs it, and deletes it.

    That was actually really easy!!

    I think many of posters, myself included, where thrown by the talk of writing a compiler. Also the problem wasn't fully stated; *shrugs*; don't worry about that; got there in the end; please if you use the forums again then try and state the problem as best you can (do not worry about bad english).


    www.dsmyth.net | www.dsmyth.net/wiki
    Sunday, April 19, 2009 4:26 PM

All replies

  • Reference Windows Script Host to start.
    Monday, April 13, 2009 9:47 PM
  • I would suggest that we couldn't make it clearer - this is a .net forum and is meant to be .net.

    -Renee
    Monday, April 13, 2009 10:26 PM
  • you dont understand!I make a VB.NET Application to conver .vbs to .exe.
    Tuesday, April 14, 2009 12:13 AM
  • Hi,

    You could write a VBS to .NET exe compiler but it would be a lot of work. Would require quite a bit of knowledge of .NET executables (IL / metadata).

    What you could do instead is embed the script in a generated exe using the compiler of CodeDOM. Each exe produced would be the same code, extract the script, run with the Windows Script Host, and delete the script when finished. Thats the template application that would need to be compiled and created, only the script would change.


    www.dsmyth.net | www.dsmyth.net/wiki
    Tuesday, April 14, 2009 7:57 AM
  • Hi,how do i use CodeDOM?A step by step tutorial wold be nice.Im new in VB.NET .
    Thanks for fast help!
    Tuesday, April 14, 2009 9:44 PM
  • Is this close to what you are looking for?

    http://69.10.233.10/KB/dotnet/VBRunNET.aspx

    Here is a product:

    http://www.hide-folder.com/overview/hf_7.html
    • Proposed as answer by Derek Smyth Tuesday, April 21, 2009 7:10 PM
    Tuesday, April 14, 2009 9:54 PM
  • Sorry,but its not wath i am looking for. I want to make a VBS to EXE compiler,there will be a textbox,you enter the .VBS sript in there and you click on a button to convert it in .EXE file. thanks.
    Tuesday, April 14, 2009 11:24 PM
  • VBS to exe compiler and the .exe is .net?
    -Renee
    Wednesday, April 15, 2009 2:00 AM
  • Here is a product:

    http://www.hide-folder.com/overview/hf_7.html

    "ExeScript is fast, simple and compiles any .bat, .vbs, .js, .wsf, .wsh and .hta file to .exe format files."

    Your comment to this post:

    "Sorry,but its not wath i am looking for. I want to make a VBS to EXE compiler,there will be a textbox,you enter the .VBS sript in there and you click on a button to convert it in .EXE file. thanks."

    HUH?
    • Proposed as answer by Derek Smyth Tuesday, April 21, 2009 7:10 PM
    Wednesday, April 15, 2009 5:37 AM
  • Hi FFA702,

    Take the advice from JohnWein and Derek Smyth. Making such compiler is hard to implement. It needs much work.

    Just read Scripting .NET applications with VBScript about the use of user supplied or other external VBScript in an application.

    mScript is a .NET class that allows you to dynamically script portions of your code using VBScript. You can pass multiple variables to your script, do any necessary processing, and return multiple variables from the script.

    mScriptable relies on the Windows Scripting Host for its VBScript functionality. As such, with each call to runScript(), you incur the overhead of starting a Windows Scripting Host process. The communication between the .NET component and the scripting host is fairly crude, but workable. For each run, a new file (called [timestamp].vbs) is created. This file includes your provided code as well as some header code that provides the basic variable value retrieval and value return functionality as well as file I/O. Each call your script makes to the return subroutine spools a tab delimited name/value pair out to another file called [timestamp].txt. When the script exits, the .NET module reads the values from this file and makes them available in a Hashtable. After the script completes and the values are retrieved, both the .vbs and .txt files are removed.

    Riquel

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.




    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, April 15, 2009 7:07 AM
  • Hi,

    CodeDom is a way to write code that a) generates code or b) compiles code (VB.NET or C# only though). I gave it a go but it's not going to be any use to you, why? well here is the thing.....

    What advantage is there in making a VBS script into an EXE (a .NET EXE)?

    There is only one I can see, cross platform execution, but that would be touch and go and would depend completely on what the VBS code did.

    You can double click a VBS script to run it; you can double click an EXE to run it. Where's the difference?

    OK maybe you don't want the VBS code to change...

    Tell us why you want to convert VBS code to EXE and maybe we can come up with a different approach.
    www.dsmyth.net | www.dsmyth.net/wiki
    Wednesday, April 15, 2009 11:00 AM
  • Because you can edit vbs file.?
    I just wanth to make a program that covert .vbs file in regular exe file.Wath so hard in that?

    -ps-If you dont understand wath i mean by VBS ,a vbs script file is a file that you can edit with notepad,not a .net project.

    Again,sorry for my bad english.
    Wednesday, April 15, 2009 1:04 PM
  • By that definition a c++ source is a good candidate. I'd vote along with Riquel, Mike and Derek. You'll not really get started, much less finished.

    If you have to ask...you don't know/

    -Renee

    Wednesday, April 15, 2009 1:18 PM
  • Because you can edit vbs file.?
    I just wanth to make a program that covert .vbs file in regular exe file.Wath so hard in that?

    -ps-If you dont understand wath i mean by VBS ,a vbs script file is a file that you can edit with notepad,not a .net project.

    Again,sorry for my bad english.
    Deborahk has supplied you an answer to do exactly that and you rejected her answer.  What more do you want? 
    Wednesday, April 15, 2009 1:31 PM
  • If you want to prevent the VBS from being editable you could protect it using ACL permissions.


    www.dsmyth.net | www.dsmyth.net/wiki
    Saturday, April 18, 2009 9:22 PM
  • you canopen vbs with notepad with ALC permissions?wath is ALC permission?
    Saturday, April 18, 2009 9:47 PM
  • ACL permissions are the security settings you place on folders and files to prevent users from reading and writing to the files.

    Access Control Lists
    http://en.wikipedia.org/wiki/Access_control_list

    Right click a file (if your right handed) and select properties, you should see a security tab. In here you can control who can read / write / execute a file. Folders have the same so if you want to prevent anyone getting to the script you can prevent people going into the folder.
    www.dsmyth.net | www.dsmyth.net/wiki
    Sunday, April 19, 2009 12:09 AM
  • Ok,thanks,can i apply tose setting via visual basic?

    Sunday, April 19, 2009 12:28 AM
  • Yes you can :) if the code is ran under a user that has permission to change permissions. An administrator for example.

    However!! and this is important....

    Get used to setting permissions through Windows (File/Directory -> Properties -> Security) before doing it through code. Learn about Access Control Lists and how to do it manually first because there are inheritance rules to consider.

    http://msdn.microsoft.com/en-us/library/system.io.directory.setaccesscontrol.aspx


    www.dsmyth.net | www.dsmyth.net/wiki
    Sunday, April 19, 2009 1:51 AM
  • I cant block the user to see wath inside the file if i dont block the user to execute it.Did i miss someting?

    Sunday, April 19, 2009 3:48 PM
  • Hi,

    No your right, thought the idea was to stop users from modifying it. People who need to run it can open and read it. It's a trust thing if you can execute it you have to read it.

    I think honestly now your best bet is to use the earlier recommendation by Deborahk. Everything else has been exhausted, writing something yourself really isn't as simple as you may think otherwise everyone here would have told you how to go about it. 

    Here is one last idea, just came to me actually as I wrote the above. If this isn't good enough then I don't know what is.

    May I recommend something, hope you don't mind, but when you post try not define the solution. In other words post what you want to do and not necessary how you want to do it. When you make a suggestion on a potential solution (write a compiler) the focus becomes the solution and not the problem, when you state the problem (protecting VBScripts from reading and writing but still executing) then you'll get a variety of solutions.

    Just a posting tip for the future.

    Ok try this, create a new project and double click MyProject in the solution explorer. Goto the resources tab and along the top select the small down arrow next to the Add Resource button. Select Add Existing File. Select a VBS file. This will embed the script into the application as a text file but thats fine. Then you can use this code to save and run the script....

            'get a temp file name and directory
    
            Dim tempScript As String = Path.GetTempFileName
    
            'replace tmp extension with vbs extension
    
            tempScript = tempScript.Replace(".tmp", ".vbs")
    
    
    
            'save the embedded script to the file
    
            File.WriteAllText(tempScript, My.Resources.VBScriptSample)
    
    
    
            'run the script
    
            Dim script As Process = Process.Start(tempScript)
    
            script.WaitForExit() 'wait for it to finish
    
    
    
            'delete the script
    
            File.Delete(tempScript)
    
    
    My.Resources.VBScriptSample is the name of the resource that was added. This embeds the script and then extracts it out, runs it, and deletes it.

    That was actually really easy!!

    I think many of posters, myself included, where thrown by the talk of writing a compiler. Also the problem wasn't fully stated; *shrugs*; don't worry about that; got there in the end; please if you use the forums again then try and state the problem as best you can (do not worry about bad english).


    www.dsmyth.net | www.dsmyth.net/wiki
    Sunday, April 19, 2009 4:26 PM
  • Ok,Thanks man!
    Sunday, April 19, 2009 5:23 PM
  • You didn't say that. By the time you done that, you've done enough work to have rewritten the VBA scripts.
    Renee
    Monday, January 18, 2010 3:14 PM
  • "May I recommend something, hope you don't mind, but when you post try not define the solution. In other words post what you want to do and not necessary how you want to do it."

    An excellent suggestion......
    Renee
    Monday, January 18, 2010 3:24 PM
  • Try IEXPRESS technology tool that came with windows that was located in system32 directory (IEXPRESS.EXE). You can do this manually using wizard to convert your script into executable file or from command line prompt with available options. There a lot of articles or step by step tutorials on how to use the wizard.

    http://www.petri.co.il/create_executable_with_iexpress.htm    http://renegadetech.blogspot.com/2006/07/how-to-convert-bat-file-or-vbs-file.html  http://www.ehow.com/how_5918622_convert-vbs-exe.html                                               

    If you want to do this directly from your VB program, then you have to use process to launch the IEXPRESS.EXE and pass the options and the vbs file name.  below are links for commad line options. You can also search the web for command line usage of iexpress

    http://technet.microsoft.com/en-us/library/bb496369.aspx         http://support.microsoft.com/kb/197147

    kaymaf

     


    CODE CONVERTER SITE

    http://www.carlosag.net/Tools/CodeTranslator/.

    http://www.developerfusion.com/tools/convert/csharp-to-vb/.

    Saturday, April 03, 2010 5:10 PM