System.Diagnostics.Process熟的请进来,版主帮忙

wyfwyf2000 2003-12-31 03:18:28
在cs结构中
System.Diagnostics.Process.Start(@"F:\Program Files\WinZip\wzzip.exe",@"F:\ocustomwFP0.zip F:\connent.xls");
可以生成压缩文件
而在asp.net(bs)结构中,则服务器端不生成压缩文件,但也不报错?如何解决???
...全文
104 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
saucer 2004-01-04
  • 打赏
  • 举报
回复
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));
wyfwyf2000 2004-01-04
  • 打赏
  • 举报
回复
public const int LOGON32_LOGON_INTERACTIVE = 2;
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();
}
wyfwyf2000 2004-01-04
  • 打赏
  • 举报
回复
to acewang(大灰很)
我把Web.config改后仍没反应
根据http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q306158我的代码修改如下,报异常详细信息: System.ComponentModel.Win32Exception: 没有应用程序与此操作的指定文件有关联。
wyfwyf2000 2004-01-04
  • 打赏
  • 举报
回复
改问题已解决,权限问题,
直接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));
速马 2003-12-31
  • 打赏
  • 举报
回复
提升权限比较危险...
试试这个:
右键点WinRar.exe -> Properties -> Compatibility -> Allow non-administrators to run this program
acewang 2003-12-31
  • 打赏
  • 举报
回复
Implementing Impersonation in an ASP.NET Application
http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q306158
jenyfloat 2003-12-31
  • 打赏
  • 举报
回复
同意楼上的说法。
建议:你也可试试将ASPNET用户加到Administrator组来测试一下是不是这个原因。
acewang 2003-12-31
  • 打赏
  • 举报
回复
修改web.config是用来模拟成Administrator
wyfwyf2000 2003-12-31
  • 打赏
  • 举报
回复
我的ASPNET以加到Administrator组里了,应该不存在权限问题
wyfwyf2000 2003-12-31
  • 打赏
  • 举报
回复
有变通的方法吗
acewang 2003-12-31
  • 打赏
  • 举报
回复
你试试修改Web.config:
<identity impersonate="true" userName="Administrator" password="123" ></identity>
acewang 2003-12-31
  • 打赏
  • 举报
回复
因为运行的用户是ASPNET,没有足够的权限,

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧