【发布时间】:2012-10-03 08:07:31
【问题描述】:
我想以管理员身份在我的 VS 项目中运行一个 bat 文件。 bat 文件中有一些命令,我想执行该文件。这些命令需要管理员权限。代码如下。
AndroidSmS aHelper = new AndroidSmS();
string renameMsg = aHelper.RenameFile();
public string RenameFile() {
string renameBATPath = ConfigurationManager.AppSettings["RenameBATPath"].ToString();
string o;
string str = DateTime.Now.ToOADate().ToString();
using (var p = new System.Diagnostics.Process())
{
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = @renameBATPath;
p.StartInfo.Arguments = DateTime.Now.ToShortDateString().ToString().Replace('/', '-')+".db";
p.Start();
o = p.StandardOutput.ReadToEnd();
p.WaitForExit();
}
return o;
}
所以请告诉我如何运行这些命令或以管理员模式运行此文件。任何类型的帮助将不胜感激。提前致谢 问候
【问题讨论】:
-
你试过
p.Verb = "runas"吗? -
chk 如果这解决了你的prb stackoverflow.com/questions/1469764/run-command-prompt-commands
标签: c# android .net console-application elevated-privileges