I have a very interesting problem.
I use Process.Start with the “runas” verb to run a process as administrator ie.
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)
{ }
Which said to have command executed is given as
exp *****/******@!!!!!!! owner =!!!!!!!! file =D:/SS.dmp
now my problem is
1) when i run the above query manually by right clicking the cmd.exe and choose “Run as administrator ” it works fine but with out it it throws me the error
2) so i need to execute that process through code.
i do not know where i went wrong?
is this only the way to take oracle dump or else it might be having some other way?
waiting for your valuable response and comments…..
updated 1)
I too use this code to check whether the current user is administrator or not through
private static bool IsAdministrator()
{
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
it returned me as the current user is only a administrator.
any sugessions for my above problem !
Since runas was useless, try embedding an application manifest
That should work, anyway you always have the handy: