Groups > Microsoft > Windows PowerShell > RE: Access denied while impersonating




Access denied while impersonating

Access denied while impersonating
Sat, 12 Apr 2008 04:53:28 -070
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,


Post Reply
RE: Access denied while impersonating
Sat, 12 Apr 2008 11:25:00 -070
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/library/cc136142(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@gmail.com" wrote:

> 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
Post Reply
about | contact