Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Store Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems.

Go Back   Vista Forums > Vista technology newsgroups > PowerShell

Access denied while impersonating

Reply
 
Thread Tools Display Modes
Old 04-12-2008   #1 (permalink)
luke.quinane
Guest
 
Posts: n/a

Access denied while impersonating

Hi All,

I'm trying to wrap Powershell in C# for a SSH server implementation
but I am getting the following message:

Windows PowerShell terminated with the following error:
Access is denied. (Exception from HRESULT: 0x80070005
(E_ACCESSDENIED))


To start Powershell I am impersonating another user like so:

WindowsIdentity windowsIdentity = (WindowsIdentity)
identity;
windowsIdentity.Impersonate();

ProcessStartInfo psi = new ProcessStartInfo()
{
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
RedirectStandardError = true,
RedirectStandardOutput = true,
RedirectStandardInput = true,
UseShellExecute = false,
ErrorDialog = false,
WorkingDirectory = @"C:\windows
\system32\WindowsPowerShell\v1.0\",
FileName = @"C:\windows\system32\WindowsPowerShell
\v1.0\powershell.exe",
Arguments = "-i Text -NoExit -Command -"
};

_childProcess = Process.Start(psi);

Does anyone have any idea why this is not working? What sort of
permission would Powershell be requiring to start up?


Thanks in advance,


Luke
  Reply With Quote

Old 04-12-2008   #2 (permalink)
RichS [MVP]
Guest
 
Posts: n/a

RE: Access denied while impersonating

I'm curious as to why you are starting PowerShell as a new process rather
than hosting it within the application as shown here

http://msdn2.microsoft.com/en-us/lib...42(VS.85).aspx

--
Richard Siddaway
All scripts are supplied "as is" and with no warranty
PowerShell MVP
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"luke.quinane@xxxxxx" wrote:
Quote:

> Hi All,
>
> I'm trying to wrap Powershell in C# for a SSH server implementation
> but I am getting the following message:
>
> Windows PowerShell terminated with the following error:
> Access is denied. (Exception from HRESULT: 0x80070005
> (E_ACCESSDENIED))
>
>
> To start Powershell I am impersonating another user like so:
>
> WindowsIdentity windowsIdentity = (WindowsIdentity)
> identity;
> windowsIdentity.Impersonate();
>
> ProcessStartInfo psi = new ProcessStartInfo()
> {
> WindowStyle = ProcessWindowStyle.Hidden,
> CreateNoWindow = true,
> RedirectStandardError = true,
> RedirectStandardOutput = true,
> RedirectStandardInput = true,
> UseShellExecute = false,
> ErrorDialog = false,
> WorkingDirectory = @"C:\windows
> \system32\WindowsPowerShell\v1.0\",
> FileName = @"C:\windows\system32\WindowsPowerShell
> \v1.0\powershell.exe",
> Arguments = "-i Text -NoExit -Command -"
> };
>
> _childProcess = Process.Start(psi);
>
> Does anyone have any idea why this is not working? What sort of
> permission would Powershell be requiring to start up?
>
>
> Thanks in advance,
>
>
> Luke
>
  Reply With Quote
 
Reply

Thread Tools
Display Modes









Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48