2

I have been reading online for days and I am unable to find a solution for this that I can get working.

I would like a single exe file that unpacks to temporary location when you run the file which can be shared and sent to people. Ideally I would like to hide my JavaScript files.

I just need 1 file that can be sent easily.

-Fasani

Fasani
  • 5,141
  • 1
  • 23
  • 24

1 Answers1

0

i don't know of any simple way to do this

but i had a similar problem a while ago and i created a VB.Net program to do this for me

First download portable 32bit version of node here : Node.exe

if you have visual studio installed create a new project then from the solution explorer go to your projects properties and add node.exe and your .js file as Resources.

then in the formload (if you don't want your program to have a ui) or in a buttons click event place these code:

Try
    Dim tmpp = System.IO.Path.GetTempPath & "NodeTmp"
    If (Not System.IO.Directory.Exists(tmpp)) Then System.IO.Directory.CreateDirectory(tmpp)
    If Not System.IO.File.Exists(tmpp & "\tmp_node.exe") Then _
        My.Computer.FileSystem.WriteAllBytes(tmpp & "\node.exe", My.Resources.node, False)
    System.IO.File.WriteAllText(tmpp & "\jsfile.js", My.Resources.jsfile)
    System.IO.File.WriteAllText(tmpp & "\batfile.bat", """" & tmpp & "\tmp_node.exe"" """ & tmpp & "\jsfile.js""")
    Dim p As New Process()
    p.StartInfo.FileName = "cmd.exe"
    p.StartInfo.Arguments = "/C """ & tmpp & "\pz.bat"""
    p.StartInfo.CreateNoWindow = True
    p.StartInfo.UseShellExecute = False
    p.Start()
    'Timer1.start()
Catch ex As Exception
    MsgBox("Error")
End Try

the above code creates a folder called NodeTmp in the C:\user{name}\appdata\local\Temp and extracts node.exe (from a file resorce called "node") in that folder then extracts jsfile.js (from a file resource called "jsfile") in the same folder then creates a .bat file and runs it

to Delete .js file after it is run (it is created and deleted in less then 1sec so it is kind of hidden from user): create a timer called Timer1 and set its interval to something like 150ms and uncomment the line Timer1.start() from above code and put the following sub somewhere in code

Sub pz_cleanup() Handles Timer1.tick
    Try
        Dim tmpp = System.IO.Path.GetTempPath & "PZT"
        System.IO.File.Delete(tmpp & "\pz.bat")
        System.IO.File.Delete(tmpp & "\pz.js")
        Timer1.stop()
    Catch ex As Exception

    End Try
End Sub

This is definitely not the best way to do this , but it worked for me , the only downside it had for me so far was its need for .net framework to be installed on other users computer which not all of them had it

if you want a cmd to open and show nodes output comment the line that sets CreateNoWindow to true

----- not part of answer but if you want to have a UI and put a close button there to so users don't have to end task node from taskmanager use this code:

Try
        Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("tmp_node")
        For Each p As Process In pProcess
            p.Kill()
            p.WaitForExit()
        Next
    Catch ex As Exception
        MsgBox("Error")
        Return True
    End Try

hope this helps , you can do similar thing in other languages too if you are more comfortable with them then VB.Net

Bor691
  • 606
  • 1
  • 11
  • 21