Hướng dẫn đóng gói phần mềm sử dụng powershell biên dịch script thành file exe

  -  

Xin kính chào chúng ta, bài viết bây giờ mình đang giải đáp chúng ta gói gọn phần mềm thành file thiết đặt installer thực hiện script PowerShell.Quý khách hàng vẫn xem: Đóng gói ứng dụng thành file exe

Sau Lúc chúng ta viết ngừng phần mềm bên trên Winkhung, các bạn phải đóng gói phần mềm thành tệp tin thiết đặt.

Bạn đang xem: Hướng dẫn đóng gói phần mềm sử dụng powershell biên dịch script thành file exe

Bình hay, những bạn sẽ thực hiện phần mềm: Advance Installer, One Click Install giỏi Installshield...

Trong bài viết này mình sẽ trả lời các bạn gói gọn ứng dụng tool nhỏ dại thiết đặt sử dụng script PowerShell.

Lợi ích của Việc đóng gói này là tệp tin cài đặt của doanh nghiệp khoảng 300MB (nếu như khách hàng như thế nào code bằng Devexpress thì đang thấy dung tích siêu nhiều).

Nhược điểm: Muốn thiết đặt bắt buộc gồm mạng mạng internet.

Xem thêm: Gấp 1000 Hạc Giấy Có Ý Nghĩa Gì ? 1000 Con Hạc Giấy

Các chúng ta cũng có thể msinh hoạt công tác Powershell ISE, nhằm code script


*

Các bước gói gọn ứng dụng SVG Collection của bản thân mình.

Cách 1: Nén File áp dụng ngơi nghỉ tlỗi mục Release lên hosting web của các bạn

Và khi chạy Script thiết đặt bọn họ vẫn tiến hành công việc các bước sau:

Cách 2: Download file tự hosting name VD: https://kinhnghiemdanhbac.com/svg_csharp.rar 

Bước 3: Giải nén tệp tin rar vào thỏng mục chúng ta chỉ định

Cách 4: Xóa File rar họ đang tải về

Bước 5: Chạy mở áp dụng lên

Bước 6: Tạo shortcut phần mềm trước Desktop.

Script bản thân viết cũng đơn giản và dễ dàng chúng ta chỉ cần vào chỉnh sửa những thông số lại là dứt nhé.

Xem thêm: Game Đá Gà Online Cực Kì Hấp Dẫn Cùng Những Tuyệt Chiêu Hay, Đá Gà Online✔️✔️

Sau lúc Viết Script PowerShell xong, bọn họ đã sử dụng PS2EXE => đưa tệp tin script thành file EXE

Video test vận dụng sản xuất sau thời điểm tạo file thiết đặt thành công:

Source code full script PowerShell setup:

::InputEncoding = ::OutputEncoding = New-Object System.Text.UTF8Encoding$host.UI.RawUI.WindowTitle = "Cài đặt phần mềm Powershell - https://kinhnghiemdanhbac.com"Add-Type -AssemblyName System.Windows.Forms$browser = New-Object System.Windows.Forms.FolderBrowserDialog$browser.Description = "quý khách hàng Hãy lựa chọn thỏng mục cài đặt phần mềm"$null = $browser.ShowDialog()$temp = $browser.SelectedPathWrite-Output $temp$url = "https://kinhnghiemdanhbac.com/svg_csharp.rar"$output = $temp + "svg_csharp.rar"$start_time = Get-Date#Import-Module BitsTransfer#Start-BitsTransfer -Source $url -Destination $output#OR#Start-BitsTransfer -Source $url -Destination $output -AsynchronousFunction Get-Webfile ($url) $dest = $output Write-Host "Đang cài $url`n" -ForegroundColor DarkGreen; $uri=New-Object "System.Uri" "$url" $request=::Create($uri) $request.set_Timeout(5000) $response=$request.GetResponse() $totalLength=::Floor($response.get_ContentLength()/1024) $length=$response.get_ContentLength() $responseStream=$response.GetResponseStream() $destStream=New-Object -TypeName System.IO.FileStream -ArgumentList $dest, Create $buffer=New-Object byte 10KB $count=$responseStream.Read($buffer,0,$buffer.length) $downloadedBytes=$count while ($count -gt 0) ::CursorLeft = 0 ::Write("Đang download phần mềm 0K of 1K (2%)", ::Floor($downloadedBytes/1024), $totalLength, ::Round(($downloadedBytes / $length) * 100,0)) $destStream.Write($buffer, 0, $count) $count=$responseStream.Read($buffer,0,$buffer.length) $downloadedBytes+=$count Write-Host "" Write-Host "`nDownload of `"$dest`" finished." -Foregroundmàu sắc DarkGreen; $destStream.Flush() $destStream.Close() $destStream.Dispose() $responseStream.Dispose()Get-Webfile $urlWrite-đầu ra "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"Set-Location $tempFunction Extract-WinRarFiles Param ( $UnRarExePath = "$env:ProgramFilesWinRARUnRAR.exe", $UnRarSourcePath, $UnRarTargetPath, $OpenTargetLocation, $DeleteSourceRarFiles ) Begin Where-Object -FilterScript $_.extension -eq '.rar' ).FullName $RarFileSourceCount = $RarFilePaths.Count Process $NewLine Write-đầu ra -Verbose "Total RAR File Count: $RarFileSourceCount" $NewLine Write-đầu ra -Verbose "Beginning extraction, please wait..." Start-Sleep -Seconds 2 Foreach ($FilePath in $RarFilePaths) &$UnRarExePath x -y $FilePath $UnRarTargetPath $RarFileTargetCount = (Get-ChildItem -Path $UnRarTargetPath).Count If ($RarFileTargetCount -eq $RarFileSourceCount) Clear-Host $NewLine Write-Output -Verbose "$RarFileTargetCount RAR files have been extracted" $NewLine Else $NewLine Write-Warning -Message "$RarFileTargetCount out of $RarFileSourceCount have sầu been extracted" $NewLine End Switch ($PSBoundParameters.Keys) $_ -contains 'OpenTargetLocation' $NewLine Write-Output đầu ra -Verbose 'Opening RAR target location...' Start-Sleep -Seconds 5 Invoke-Item -Path $UnRarTargetPath $_ -contains 'DeleteSourceRarFiles' $NewLine Write-Output đầu ra -Verbose 'Deleting source RAR files & the directory...' Start-Sleep -Seconds 5 Remove-Item -Path $UnRarSourcePath -Recurse -Force Set-Location $temp$appPath = $temp + "SGV Collection.exe" Extract-WinRarFiles -UnRarSourcePath $output -UnRarTargetPath $temp -DeleteSourceRarFiles Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)" Remove-Item *.tmp -recurse -force Start-Process -FilePath $appPath $WshShell = New-Object -comObject WScript.Shell$Shortcut = $WshShell.CreateShortcut("$HomeDesktopSGV Collection.lnk")$Shortcut.TargetPath = $appPath$Shortcut.Save()write-host "Setup finish..."write-host "Press any key to exist..."#::ReadKey($true)Sau khi chế tạo script kết thúc để biên dịch File script thành File EXE chúng ta vào đường truyền github PS2EXE sau để thấy chi tiết chế tạo file cài đặt.

https://github.com/MScholtes/PS2EXE

Cách 1: Các chúng ta mnghỉ ngơi chương trình PowerShell lên

Cách 2: Gõ lệnh cài PS2EXE về

PS C:> Install-Module ps2exeBước 3: Lệnh đóng gói, các bạn chỉ lựa chọn đường truyền file script với tệp tin xuất exe

Invoke-ps2exe cộ .source.ps1 .arget.exekhi build File Exe cộ, giả dụ các bạn muốn sửa đổi các tđắm say số Assembly xuất xắc inhỏ của áp dụng, Khi build các bạn làm theo cú pháp bên dưới: