/// <summary>
/// 自動更新(從網(wǎng)絡(luò)共享路徑),程序刪除,從網(wǎng)絡(luò)復(fù)制,系統(tǒng)啟動
/// </summary>
private void UpdateFromShare()
{
string strXCopyFiles = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "XCopyFiles.bat");
string tempUpdatePath = "\\\\192.168.1.100\\AutoUpdate\\AutomatedOrdering"; //自動更新路徑
string netUser = "autoupdate"; //網(wǎng)絡(luò)用戶名
string netPassword = "autoupdate"; //網(wǎng)絡(luò)密碼
//生成更新BAT(NET USE 獲取網(wǎng)絡(luò)讀取權(quán)限,復(fù)制文件)
using (StreamWriter swXcopy = new StreamWriter(strXCopyFiles,false,Encoding.Default))
{
swXcopy.WriteLine(
string.Format(
@"@echo off"+Environment.NewLine
+"net use {0} {2} /user:{1}"+Environment.NewLine
+ "xcopy /y/s/e/v \"" + tempUpdatePath + "\" \"" + Directory.GetCurrentDirectory() + "\\\"",
tempUpdatePath,
netUser,
netPassword
));
}
//生成BAT(刪除舊版本,刪除BAT,啟動更新后的程序)
string filename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "KillApp.bat");
using (StreamWriter bat = new StreamWriter(filename, false, Encoding.Default))
{
// 自刪除,自啟動
bat.WriteLine(string.Format(@"
@echo off
:selfkill
attrib -a -r -s -h {0}
del {0}
if exist {0} goto selfkill
call XCopyFiles.bat
del XCopyFiles.bat "+ Environment.NewLine
+ "\"" + Application.ExecutablePath + "\"" + Environment.NewLine
+ " del %0 ",
AppDomain.CurrentDomain.FriendlyName
));
}
// 啟動自刪除批處理文件
ProcessStartInfo info = new ProcessStartInfo(filename);
info.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(info);
// 強制關(guān)閉當(dāng)前進程
Environment.Exit(0);
}
C#:自動更新(從網(wǎng)絡(luò)共享路徑),程序刪除,從網(wǎng)絡(luò)復(fù)制,系統(tǒng)啟動
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 一、學(xué)習(xí)類 1-筆譯學(xué)習(xí)持續(xù)每日一更周六日除外 2-新概念朗讀每日一更 3-每周三篇背誦新概念 二、工作類 1-每...