Using System;
Using System. Collections. Generic;
Using System. componentmodel;
Using System. Data;
Using System. drawing;
Using System. text;
Using System. Windows. forms;
Using System. IO;
Using System. net;
Using System. diagnostics;
Namespace Update
{
Public Partial Class Form1: Form
{
Private WebClient update = New WebClient ();
Public Form1 ()
{
Initializecomponent ();
}
Private Void Form1_load ( Object Sender, eventargs E)
{
String URL = @" Http://files.cnblogs.com/mossan/Zhongwen.rar " ;
Int N = URL. lastindexof ( ' / ' );
String Filename = URL. substring (n + 1 , URL. Length - N - 1 );
If ( ! (Directory. exists (application. startuppath + " \ Update " )))
{
Directory. createdirectory (application. startuppath+ "\ Update");
}
Try {Update. downloadfile (URL, application. startuppath+ "\ Update \\" +Filename );}
Catch (Webexception ex) {MessageBox. Show (ex. Message,"Error");}
Try
{
Process unwinrar = New Process ();
Unwinrar. startinfo. filename = " Winrar.exe " ;
Unwinrar. startinfo. Arguments = " E-O ++ \ "" + Application. startuppath + " \ Update \\ " + Filename + " \ "" + " \ "" + Application. startuppath + " \ Update " + " \ "" ;
Unwinrar. Start ();
MessageBox. Show ( " Decompressed! " );
File. Copy (application. startuppath + " \ Update \\ " + " Zhongwen.exe " , Application. startuppath + " \ Zhongwen.exe " , True );
Process prozhongwen = New Process ();
Prozhongwen. startinfo. filename = Application. startuppath + " \ Zhongwen.exe " ;
Prozhongwen. Start ();
}
Catch (Exception ex) {MessageBox. Show (ex. Message );}
This . Close ();
}
}
}