try to figure what the error is first:Process p = new Process("...", "..."); p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.Start(); string output = p.StandardOutput.ReadToEnd(); p.WaitForExit(); Response.Write(String.Format("{0}<BR>{1}<BR>", p.ExitCode, output));
改问题已解决,权限问题, 直接System.Diagnostics.Process.Start(@"F:\Program Files\WinZip\wzzip.exe",@"F:\ocustomwFP0.zip F:\connent.xls");不能创建但不报错,用 saucer(思归) 的方法就可以找到原因,把压缩文件生成到到站点下就可以了 Process p = new Process(); p.StartInfo.FileName=@"F:\Program Files\WinZip\wzzip"; p.StartInfo.Arguments=@"F:\wyf2\WebApplication7\WebForm3.zip F:\connent.xls"; //Process p = new Process(@"F:\Program Files\WinZip\wzzip.exe",@"F:\wyf2\WebApplication7\WebForm3.zip F:\connent.xls"); p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.Start(); string output = p.StandardOutput.ReadToEnd(); p.WaitForExit(); Response.Write(String.Format("{0}<BR>{1}<BR>", p.ExitCode, output));
<identity impersonate="true" userName="Administrator" password="123" ></identity>
建议:你也可试试将ASPNET用户加到Administrator组来测试一下是不是这个原因。
http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q306158
试试这个:
右键点WinRar.exe -> Properties -> Compatibility -> Allow non-administrators to run this program
我把Web.config改后仍没反应
根据http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q306158我的代码修改如下,报异常详细信息: System.ComponentModel.Win32Exception: 没有应用程序与此操作的指定文件有关联。
public const int LOGON32_PROVIDER_DEFAULT = 0;
protected WindowsImpersonationContext impersonationContext;
public void Page_Load(Object s, EventArgs e)
{
if(impersonateValidUser( "Administrator", "wu", "wu"))
{
System.Diagnostics.Process.Start(@"F:\Program Files\WinZip\wzzip.exe",@"F:\ocustomwFP0.zip F:\connent.xls");
undoImpersonation();
}
//else
//{
//Your impersonation failed. Therefore, include a fail-safe mechanism here.
//}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
[DllImport("advapi32.dll", CharSet=CharSet.Auto)]
public static extern int LogonUser(String lpszUserName,
String lpszDomain,
String lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken);
[DllImport("advapi32.dll", CharSet=System.Runtime.InteropServices.CharSet.Auto,
SetLastError=true)]
public extern static int DuplicateToken(IntPtr hToken,
int impersonationLevel,
ref IntPtr hNewToken); private bool impersonateValidUser(String userName, String domain, String password)
{
WindowsIdentity tempWindowsIdentity;
IntPtr token = IntPtr.Zero;
IntPtr tokenDuplicate = IntPtr.Zero; if(LogonUser(userName, domain, password, LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT, ref token) != 0)
{
if(DuplicateToken(token, 2, ref tokenDuplicate) != 0)
{
tempWindowsIdentity = new WindowsIdentity(tokenDuplicate);
impersonationContext = tempWindowsIdentity.Impersonate();
if (impersonationContext != null)
return true;
else
return false;
}
else
return false;
}
else
return false;
}
private void undoImpersonation()
{
impersonationContext.Undo();
}
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Response.Write(String.Format("{0}<BR>{1}<BR>", p.ExitCode, output));
直接System.Diagnostics.Process.Start(@"F:\Program Files\WinZip\wzzip.exe",@"F:\ocustomwFP0.zip F:\connent.xls");不能创建但不报错,用 saucer(思归) 的方法就可以找到原因,把压缩文件生成到到站点下就可以了
Process p = new Process();
p.StartInfo.FileName=@"F:\Program Files\WinZip\wzzip";
p.StartInfo.Arguments=@"F:\wyf2\WebApplication7\WebForm3.zip F:\connent.xls";
//Process p = new Process(@"F:\Program Files\WinZip\wzzip.exe",@"F:\wyf2\WebApplication7\WebForm3.zip F:\connent.xls");
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Response.Write(String.Format("{0}<BR>{1}<BR>", p.ExitCode, output));