【问题标题】:Taking oracle database dump via c# .net通过 c# .net 进行 oracle 数据库转储
【发布时间】:2012-09-13 12:10:56
【问题描述】:

我有一个非常有趣的问题。

我使用带有“runas”动词的 Process.Start 以管理员身份运行进程,即。

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)
            { }

执行命令的命令为

exp *****/******@!!!!!!! owner =!!!!!!!! file =D:/SS.dmp

现在我的问题是

1) 当我通过右键单击 cmd.exe 并选择“以管理员身份运行”手动运行上述查询时,它工作正常,但没有它它会抛出错误

2) 所以我需要通过代码执行该过程。

不知道哪里出错了?

这只是进行 oracle 转储的方式还是可能有其他方式?

等待您的宝贵回复和cmets.....

更新 1)

我也是通过这段代码来检查当前用户是否是管理员

    private static bool IsAdministrator()
{
    WindowsIdentity identity = WindowsIdentity.GetCurrent();
    WindowsPrincipal principal = new WindowsPrincipal(identity);
    return principal.IsInRole(WindowsBuiltInRole.Administrator);
}

它返回了我,因为当前用户只是管理员。

对我上述问题的任何建议!

【问题讨论】:

    标签: c# .net oracle oracle10g


    【解决方案1】:

    由于 runas 没用,请尝试嵌入 application manifest

    <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> 
    

    这应该可以,反正你总是很方便:

    myprocess.StartInfo.UserName = "Administrator"; 
    myprocess.StartInfo.Password = "password"; 
    

    【讨论】:

    • 感谢您的回复,我已经检查过了,但我不明白您能帮我解决一下吗
    • 没有管理员用户名和密码这可能吗?
    • @GowthamanSS 当然,请参阅所提供链接的最后一点。 1. 使用文本编辑器(例如 Windows 记事本)创建默认清单文件 temp.manifest。 2. 使用 mt.exe 插入清单。命令是:mt.exe –manifest temp.manifest –outputresource:YourApp.exe;#1.
    • 我收到错误代码为 Error : Error reading Win32 manifest file 'D:**********\mt.exe -manifest "$(ProjectDir)$(TargetName). exe.manifest" -updateresource:"$(TargetDir)$(TargetName).exe;#1"' -- '文件名、目录名或卷标语法不正确。 '
    • @GowthamanSS 当你刻录用户和密码并尝试在没有右键单击的情况下运行并以管理员身份运行时发生了什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-19
    • 1970-01-01
    • 2011-07-28
    • 1970-01-01
    • 1970-01-01
    • 2012-02-20
    • 1970-01-01
    相关资源
    最近更新 更多