从资源启动可执行应用程序而不将其保存在某处 [英] start an executable application from resources without saving it somewhere

查看:17
本文介绍了从资源启动可执行应用程序而不将其保存在某处的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的 VB 2008 应用程序 (myVbApp.exe) 的资源中有一个文件 (appres.exe),我该如何从那里开始?我不想在开始之前将它 (appres.exe) 保存在其他地方,我只想要 myVbApp.exe,没有更多文件.

If i have a file ( appres.exe ) in the resources of my VB 2008 Application (myVbApp.exe), how can I start from there? I don't want to save it (appres.exe) somewhere else before start, i want only myVbApp.exe, no more files.

推荐答案

从资源中检索 EXE:

Retrieve the EXE from the resources:

   Dim l as System.IO.Stream = Reflection.Assembly.GetEntryAssembly.GetManifestResourceStream(String.Format("{0}.{1}", "ApplicationProjectName", "YourExeName"))

然后将其保存到临时文件夹 - 示例方法:

Then save it to temp folder - example method:

Private Sub SaveStreamToFile(ByVal p_stream As Stream, ByVal p_fileName As String)
    Dim l_streamWriter As System.IO.FileStream = System.IO.File.Create(p_fileName)

    Try
        Dim l_bytes(65536) As Byte
        Dim l_offset As Integer = 0
        Dim l_readBytes As Integer

        Do
            l_readBytes = p_stream.Read(l_bytes, 0, 65536)
            l_streamWriter.Write(l_bytes, 0, l_readBytes)

            l_offset += l_readBytes

        Loop While (l_readBytes > 0)
        Debug.WriteLine("Num Of bytes Read: " + l_offset.ToString)

    Catch ex As Exception
       'log error
    Finally
        p_stream.Close()
        l_streamWriter.Close()
    End Try
End Sub

现在您在临时文件夹中获得了 EXE,您可以定期使用:

Now that you got the EXE in a temp folder, you can regulary lunch it using:

Process.Start("EXE_PATH")

并在该过程完成后将其删除.

And delete it once the process is done.

这篇关于从资源启动可执行应用程序而不将其保存在某处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆