Results 1 to 39 of 39

Thread: Start embedded Exe from tempfolder

Threaded View

  1. #15

    Thread Starter
    Member
    Join Date
    Jun 2011
    Posts
    60

    Re: Add dll files to embedded resources

    is there a way i can make the two files that gets copy , so they copy to the temp folder in C drive which everyone has ? thsi is basically what i need
    But if you do it as a temp file in the temp folder


    will this work for what im trying to do ?

    Private Sub installFiles()

    Dim resFiles() As String = Application.ResourceAssembly.GetManifestResourceNames

    For Each resFile As String In resFiles
    If resFile.EndsWith("7za.exe") Then
    Dim tmpFile As String = IO.Path.Combine(IO.Path.GetTempPath, IO.Path.GetTempFileName)
    if ExtractEmbeddedResourcefile then(Application.ResourceAssembly.GetManifestResourceStream(resFile), tmpFile)
    debug.writeline(tmpFile) 'do something with the file name here (like start your process)
    end if
    'delete file when done
    IO.File.Delete(tmpFile)


    End If
    Next

    End Sub

    Private Function ExtractEmbeddedResourcefile(ByVal resStream As IO.Stream, ByVal OutFilename As String) As Boolean

    Try

    If IO.File.Exists(OutFilename) Then
    IO.File.Delete(OutFilename)
    End If

    Dim count As Integer = CType(resStream.Length, Integer) - 1
    Dim buffer(count) As Byte
    resStream.Read(buffer, 0, count + 1)

    Using fs As New FileStream(OutFilename, FileMode.Create)
    With fs
    .Write(buffer, 0, count + 1)
    .Flush()
    .Close()
    End With
    End Using

    Return CBool(IO.File.Exists(OutFilename))
    Catch ex As Exception
    Return False
    End Try
    Return False
    End Function

    or can this be applied to exes

    ake a look at this if you want to extract and run a .msi file:

    1
    Private Shared Function Extract(ByVal Path As String, ByVal RunIn As String) As Process
    2
    My.Computer.FileSystem.WriteAllBytes(My.Resources.Installer)
    3
    Dim Inf As New ProcessStartInfo
    4
    Inf.FileName = Path
    5
    Inf.WorkingDirectory = RunIn
    6
    Dim Prc As Process = Process.Start(Inf)
    7
    Return Prc
    8
    End Function


    And to use it:

    1
    Dim InstPrc As Process = Extract(My.Computer.FileSystem.CurrentDirectory & "\Installer.msi", My.Computer.FileSystem.SpecialDirectories.MyDocuments)


    Finally to delete the temporary file:

    1
    My.Computer.FileSystem.DeleteFile(My.Computer.FileSystem.CurrentDirectory & "\Installer.msi")
    Last edited by fokeiro; Jul 1st, 2011 at 07:26 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width