有区别,区别在于:
[SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode), SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)] public static void Restart() { if (Assembly.GetEntryAssembly() == null) { throw new NotSupportedException(SR.GetString("RestartNotSupported")); } bool flag = false; Process currentProcess = Process.GetCurrentProcess(); if (string.Equals(currentProcess.MainModule.ModuleName, "ieexec.exe", StringComparison.OrdinalIgnoreCase)) { string str = string.Empty; new FileIOPermission(PermissionState.Unrestricted).Assert(); try { str = Path.GetDirectoryName(typeof(object).Module.FullyQualifiedName); } finally { CodeAccessPermission.RevertAssert(); } if (string.Equals(str + "\\ieexec.exe", currentProcess.MainModule.FileName, StringComparison.OrdinalIgnoreCase)) { flag = true; Application.ExitInternal(); string text = AppDomain.CurrentDomain.GetData("APP_LAUNCH_URL") as string; if (text != null) { Process.Start(currentProcess.MainModule.FileName, text); } } } if (!flag) { if (ApplicationDeployment.IsNetworkDeployed) { string updatedApplicationFullName = ApplicationDeployment.CurrentDeployment.UpdatedApplicationFullName; uint hostTypeFromMetaData = (uint)Application.ClickOnceUtility.GetHostTypeFromMetaData(updatedApplicationFullName); Application.ExitInternal(); UnsafeNativeMethods.CorLaunchApplication(hostTypeFromMetaData, updatedApplicationFullName, 0, null, 0, null, new UnsafeNativeMethods.PROCESS_INFORMATION()); return; } string[] commandLineArgs = Environment.GetCommandLineArgs(); StringBuilder stringBuilder = new StringBuilder((commandLineArgs.Length - 1) * 16); for (int i = 1; i < commandLineArgs.Length - 1; i++) { stringBuilder.Append('"'); stringBuilder.Append(commandLineArgs[i]); stringBuilder.Append("\" "); } if (commandLineArgs.Length > 1) { stringBuilder.Append('"'); stringBuilder.Append(commandLineArgs[commandLineArgs.Length - 1]); stringBuilder.Append('"'); } ProcessStartInfo startInfo = Process.GetCurrentProcess().StartInfo; startInfo.FileName = Application.ExecutablePath; if (stringBuilder.Length > 0) { startInfo.Arguments = stringBuilder.ToString(); } Application.ExitInternal(); Process.Start(startInfo); } }
好森奥的赶脚,能否汉字解释一下
俺是菜鸟,有些不懂
@你好,再见: 那没办法了,你去找本教程读读吧。
if (text != null)
{
Process.Start(currentProcess.MainModule.FileName, text);
}
看楼上的代码 restart里面也调用了这个Start方法 没什么区别吧
你需要仔细读代码,这段代码中有很多坑,对运行环境考虑不周全时就会写出没有这些坑的代码。
带参数的怎么办?
比如:
myapp.exe -s -t -url http://www.google.com/ -test -other -all
额外补充:刚查了下, .net framework 1.1里面是不包括这个方法的. 所以很有可能那是一段老代码.