asp.net通过web在服务器端建立bat,并在服务器端执行,模拟权限怎么设置?

beauhan 2006-10-23 11:52:04
想通过web方式在服务器端执行bat,主要涉及到模拟权限问题.搞了2天,没搞清楚模拟权限怎么搞.哪位可以指点2句~~~~
...全文
228 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
beauhan 2006-11-13
  • 打赏
  • 举报
回复
写了个组件,单个执行时,调用组件执行。
下面是主要代码:
Param类是参数类
public string flvstr;
public string flvmdi;
Param P = new Param();

public Flv()
{
this.flvstr = ConfigurationSettings.AppSettings["flv"];
this.flvmdi = ConfigurationSettings.AppSettings["mdi"];
}

public void VideoConvertFlv(string VideoName,string FormPath,string ToPath)
{
Process o = new Process();
string text1 = base.Server.MapPath(this.flvstr);
o.StartInfo = new ProcessStartInfo(text1);
o.StartInfo.Arguments = P.mencoder(VideoName,FormPath,ToPath);
o.Start();
o.WaitForExit();
Xiu(VideoName,ToPath);
}

private void Xiu(string VideoName,string ToPath)
{
Process r = new Process();
string text2 = base.Server.MapPath(this.flvmdi);
r.StartInfo = new ProcessStartInfo(text2);
r.StartInfo.Arguments = P.flvmdi(ToPath,VideoName);
r.Start();
r.WaitForExit();
}
cqdyh 2006-11-09
  • 打赏
  • 举报
回复
window + IIS 权限是个繁琐的东西

Process proc = new Process();
proc.Exited += new EventHandler(proc_Exited);
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.WorkingDirectory = AppFolder;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.UseShellExecute = false;

proc.StartInfo.RedirectStandardInput = true; //输入重定向
proc.StartInfo.RedirectStandardOutput = true; //标准输出重定向

proc.Start();
proc.StandardInput.WriteLine(sExecuteCommand);
Thread.Sleep(new System.TimeSpan(0, 0, 0, 5));
proc.StandardInput.WriteLine("exit");

sExecResult = proc.StandardOutput.ReadToEnd(); //关闭前返回脚本执行的结果
proc.WaitForExit();

以前在 win2000 + iis5通过
在 win2003+ iis6 就报权限问题, 几乎所有可能的权限都设了, 还是不行, =_="
Rainightwind 2006-11-09
  • 打赏
  • 举报
回复
你可以看到 bat 文件能创建一个文件

说明 bat 有执行
Rainightwind 2006-11-09
  • 打赏
  • 举报
回复
应该是可以执行 bat

但是 bat 中的某些命令权限不足

你可以在bat中第一句上加上一句

echo %time% > c:\test.txt

把 c:\test.txt 设为everyone 可读写
rhathymia 2006-10-23
  • 打赏
  • 举报
回复
参考
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Web.Security;
using System.Security.Principal;
using System.Runtime.InteropServices;
namespace Security
{
/// <summary>
/// 模拟
/// </summary>
public class ASPNETImp : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lbExist;
protected System.Web.UI.WebControls.Label Label2;
public const int LOGON32_LOGON_INTERACTIVE = 2;
public const int LOGON32_PROVIDER_DEFAULT = 0;
WindowsImpersonationContext impersonationContext;
[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 void Page_Load(object sender, System.EventArgs e)
{
//noImpersonate();
//ImpersonateIIS();
ImpersonateUser();
}
private void noImpersonate()
{
try
{
if(File.Exists("c:\\Documents and Settings\\shaozhidong\\test.txt"))
lbExist.Text = "存在!";
else
lbExist.Text = "该文件不存在!";
}
catch(Exception)
{
lbExist.Text = "没有权限!";
}
}
private void ImpersonateIIS()
{
// 在代码中模拟IIS认证帐号
System.Security.Principal.WindowsImpersonationContext impersonationContext;
impersonationContext = ((System.Security.Principal.WindowsIdentity)User.Identity).Impersonate();

if(File.Exists("c:\\Documents and Settings\\shaozhidong\\test.txt"))
lbExist.Text = "存在!";
else
lbExist.Text = "该文件不存在!";

impersonationContext.Undo();
}
private void ImpersonateUser()
{
//在代码中模拟指定账号
if(impersonateValidUser("shaozhidong", "shaozhd", "111"))
{
if(File.Exists("c:\\Documents and Settings\\shaozhidong\\test.txt"))
lbExist.Text = "存在!";
else
lbExist.Text = "该文件不存在!";
undoImpersonation();
}
else
{
lbExist.Text = "权限不够!";
}
}
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();
}

#region Web Form Designer generated code
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
}
}
beauhan 2006-10-23
  • 打赏
  • 举报
回复
可以建文件,刪除修改文件。就是不能執行bat文件。點解呢
beauhan 2006-10-23
  • 打赏
  • 举报
回复
报"没有应用程序与此操作的指定文件有关联"错误?
beauhan 2006-10-23
  • 打赏
  • 举报
回复
我在文件存在的时候,并且有权限的情况下.执行 System.Diagnostics.Process.Start(@"H:\1.bat");
没反映,why?

62,046

社区成员

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

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

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

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