1
2
3
|
Assembly thisAssem = Assembly.GetExecutingAssembly();
AssemblyName thisAssemName = thisAssem.GetName();
Version ver = thisAssemName.Version;
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
Uri uri =
new
Uri(downFileUrl + localFileName);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Credentials = CredentialCache.DefaultCredentials;
request.MaximumAutomaticRedirections = 4;
localFileName = Path.GetFileName(localFileName);
using
(HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
Stream receiveStream = response.GetResponseStream();
string
newPath = Path.Combine(tempFold, localFileName);
using
(FileStream fs =
new
FileStream(newPath, FileMode.Create))
{
Byte[] buffer =
new
Byte[4096];
int
bytesRead = receiveStream.Read(buffer, 0, buffer.Length);
while
(bytesRead > 0){
fs.Write(buffer, 0, bytesRead);
bytesRead = receiveStream.Read(buffer, 0, buffer.Length);
}
}
receiveStream.Close();
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
private
static
void
RunFile(
string
dir,
string
localFileName){
string
info =
"运行程序"
+ localFileName;
try
{
if
(File.Exists(Path.Combine(dir, localFileName))){
Process myProcess =
new
Process();
ProcessStartInfo psi =
new
ProcessStartInfo();
psi.FileName = localFileName;
psi.WorkingDirectory = dir;
psi.UseShellExecute =
false
;
psi.RedirectStandardError =
true
;
psi.CreateNoWindow =
true
;
psi.RedirectStandardOutput =
true
;
psi.WindowStyle = ProcessWindowStyle.Hidden;
myProcess.StartInfo = psi;
myProcess.Start();
string
error = myProcess.StandardError.ReadToEnd();
string
output = myProcess.StandardOutput.ReadToEnd();
myProcess.WaitForExit();
myProcess.Close();
if
(error !=
string
.Empty){
Log.Write(
"StandardError:"
+ error);
}
if
(output !=
string
.Empty){
Log.Write(
"StandardOutput:"
+ output);
}
Log.LogProcessEnd(info);
}
}
catch
(Exception ex){
Log.Write(info +
"出错"
);
Log.LogException(ex);
throw
ex;
}
}
}
|