通过c#.net获取oracle数据库转储
我有一个非常有趣的问题 我使用进程。从“runas”动词开始,以管理员的身份运行进程通过c#.net获取oracle数据库转储,c#,.net,oracle,oracle10g,C#,.net,Oracle,Oracle10g,我有一个非常有趣的问题 我使用进程。从“runas”动词开始,以管理员的身份运行进程 string currentstatus; ProcessStartInfo startInfo = new ProcessStartInfo(); Process myprocess = new Process(); try { startInfo.FileName = "cmd";
string currentstatus;
ProcessStartInfo startInfo = new ProcessStartInfo();
Process myprocess = new Process();
try
{
startInfo.FileName = "cmd"; //
startInfo.Verb = "runas";
startInfo.Arguments = "/env /user:" + "Administrator" + " cmd";
startInfo.RedirectStandardInput = true;
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false; //'required to redirect
startInfo.CreateNoWindow = true; // '<---- creates no window, obviously
myprocess.StartInfo = startInfo; //
myprocess.Start(); //
System.IO.StreamReader SR;
System.IO.StreamWriter SW;
Thread.Sleep(200);
SR = myprocess.StandardOutput;
SW = myprocess.StandardInput;
SW.WriteLine(commandexecuted); // 'the command you wish to run.....
SW.WriteLine("exit"); // 'exits command prompt window
Thread.Sleep(200);
currentstatus = SR.ReadToEnd();
SW.Close();
SR.Close();
}
catch (Exception e)
{ }
现在我的问题是
1) 当我通过右键单击cmd.exe并选择“以管理员身份运行”手动运行上述查询时,它工作正常,但如果没有它,就会抛出错误
2) 所以我需要通过代码来执行这个过程
我不知道我哪里出错了
这只是获取oracle转储的唯一方法吗?或者它可能有其他方法
等待您宝贵的回复和评论
更新1)
我也使用此代码检查当前用户是否是管理员
private static bool IsAdministrator()
{
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
它返回我,因为当前用户只是管理员
对我的上述问题有什么建议吗 既然runas是无用的,试着嵌入一个
谢谢你的回复,我已经检查过了,但我不明白你能帮我解决这个问题吗?不需要管理员用户名和密码。这可能吗?@GowthamanSS当然可以,请参阅提供的链接的最后一点。1.使用文本编辑器(如Windows记事本)创建默认清单文件temp.manifest。2.使用mt.exe插入清单。命令应该是:mt.exe–manifest temp.manifest–outputresource:YourApp.exe#1.我获取的错误代码为错误:读取Win32清单文件“D”时出错:*********\mt.exe-manifest“$(ProjectDir)$(TargetName.exe.manifest”-updateresource:$(TargetDir)$(TargetName.exe;#1”'-“文件名、目录名或卷标语法不正确。”@Gowthamans当您烧录用户和密码并尝试在没有右键单击的情况下运行并以管理员身份运行时会发生什么?
private static bool IsAdministrator()
{
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
myprocess.StartInfo.UserName = "Administrator";
myprocess.StartInfo.Password = "password";