1. 程式人生 > >強悍!winrar妙用-將bat指令碼打包成exe可執行檔案並實現自動執行

強悍!winrar妙用-將bat指令碼打包成exe可執行檔案並實現自動執行

轉自:https://blog.csdn.net/qq_35440678/article/details/53264410

 

一、背景介紹

最近有個這樣的需求,為了網頁解決IE相容問題,需實現自動檢測到使用IE開啟時下載一個離線chrome安裝包,用一個bat指令碼啟動離線的chrome開啟目標首頁,並在桌面生成一個快捷方式,後面都從桌面偽裝的首頁快捷方式進入。

二、bat指令碼具體實現
因為沒有辦法設定chrome的預設主頁,於是先寫個bat指令碼來指定chrome開啟某個網址的,a.bat指令碼如下:

@echo off
start "" "%windir%\chrome.exe"  http://www.baidu.com
另外建立一個bat指令碼,自動copy離線chrome資料夾到系統目錄,然後建立上述a.bat一個快捷方式到桌面,雙擊安裝.bat

@echo off
:: %cd%當前目錄 %windir% 是C:\Windows
:: 這一行執行效果是把 當前目錄 所有檔案拷貝到C:\Windows
xcopy %cd% %windir%\ /s /e /Y 
 
 
echo set WshShell = WScript.CreateObject("WScript.Shell")>tmp.vbs
echo strDesktop = WshShell.SpecialFolders("Desktop")>>tmp.vbs
echo set oShellLink = WshShell.CreateShortcut(strDesktop ^& "\百度首頁.lnk")>>tmp.vbs
echo oShellLink.TargetPath ="%windir%\a.bat">>tmp.vbs
echo oShellLink.WindowStyle ="1">>tmp.vbs
echo oShellLink.Hotkey = "CTRL+SHIFT+Q">>tmp.vbs
:: 設定快捷方式的icon
echo oShellLink.IconLocation = "%windir%\icon1.ico">>tmp.vbs
echo oShellLink.Description = "百度一下,你就知道">>tmp.vbs
echo oShellLink.WorkingDirectory = strDesktop>>tmp.vbs
echo oShellLink.Save>>tmp.vbs
:: 回到桌面
echo Set shell = CreateObject("Shell.Application")>>tmp.vbs
echo shell.ToggleDesktop>>tmp.vbs
call tmp.vbs
del /f /q tmp.vbs
上述指令碼實現以下幾個邏輯:

把當前目錄的所有檔案(chrome檔案)拷貝到C:\Windows
建立a.bat一個快捷方式到桌面
設定快捷方式的icon
回到桌面,告訴使用者桌面生成了新的應用
三、winrar打包過程
1、右鍵-Add to arhive,勾選建立自解壓格式壓縮檔案:


2、自動解壓到臨時資料夾


3、設定解壓後自動執行雙擊安裝.bat:


4、更改exe的圖示icon


5、點選確認,壓縮後大功告成!!!


6、執行
雙擊執行baidu.exe會看到自動解壓資料夾到臨時資料夾,然後自動執行雙擊安裝.bat,桌面也生成了快捷方式。

四、總結
真沒想到可以使用winrar將bat指令碼打包成exe可執行檔案,把bat偽裝成exe看著就高大上很多,還可以設定exe的圖示,可以設定解壓縮自動執行程式。一個字,爽!
--------------------- 
作者:yinnnnnnn 
來源:CSDN 
原文:https://blog.csdn.net/qq_35440678/article/details/53264410 
版權宣告:本文為博主原創文章,轉載請附上博文連結!