impersonation

How to run PowerShell scripts from C#

断了今生、忘了曾经 提交于 2019-12-05 12:56:46
I am trying to run a PowerShell script with C#, but I don't have any success. Here is my function: private void ExecutePowerShellCommand(string scriptfile) { RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create(); Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration); runspace.Open(); RunspaceInvoke scriptInvoker = new RunspaceInvoke(); scriptInvoker.Invoke("Set-ExecutionPolicy Unrestricted"); Pipeline pipeline = runspace.CreatePipeline(); //Here's how you add a new script with arguments Command myCommand = new Command(scriptfile); //CommandParameter

Help understanding impersonation

雨燕双飞 提交于 2019-12-05 11:21:03
Could somebody please help me understand the concept of 'impersonation'? The way I understand it is that when impersonation occurs, code executes on behalf of some identity. So, for a web page, as long as impersonation is disabled, the web page will always run under its configured account. If it’s enabled, I can ‘override’ its default account and set the account under which I want the web application to run. So if I'm using IIS7 and I have the following: - An application pool with identity set to a Custom account ‘user1’. - An asp.net web site, with its application pool set to the one above,

.Net classes to control services on a remote machine?

[亡魂溺海] 提交于 2019-12-05 09:59:56
问题 Yes I could google this but I'm being a little lazy. I need to remotely control windows services on another machine. Does the ServiceController class let me do this? What restrictions are there? Can I start / stop / change the "run as" details remotely, ie change a password that's due to expire? I'll be attempting to give users at work a ASP.Net website dashboard to control several services that run on their local machine under their own account (they're all local administrators on their

Impersonation and Delegation

对着背影说爱祢 提交于 2019-12-05 07:52:51
问题 I am using impersonation is used to access file on UNC share as below. var ctx = ((WindowsIdentity)HttpContext.Current.User.Identity).Impersonate(); string level = WindowsIdentity.GetCurrent().ImpersonationLevel); On two Windows 2003 servers using IIS6, I am getting different impersonation levels: Delegation on one server and Impersonation on the other server. This causes issues where I am unable to access the UNC share on the server with 'Impersonation' level. What could be causing this

How to pass impersonated user in Web API call from Console App with Windows Authentication?

旧时模样 提交于 2019-12-05 06:30:55
问题 I have a Console App and a Web API 2 project, both run on the same server. I have setup my Console App to call a RESTful endpoint in my Web API using HttpClient while impersonating a domain account. Console.WriteLine("Setting up impersonator."); using (new Impersonator(accountUsername, accountDomain, accountPwd)) { Console.WriteLine("Impersonator set up."); HttpClientHandler handler = new HttpClientHandler(); handler.UseDefaultCredentials = true; Console.WriteLine("Executing as: " + System

Set up impersonation with ASP.NET

馋奶兔 提交于 2019-12-05 05:36:04
for a first understanding, I have created a very simple project which tries to count the number of files in two directories. User1 is not allowed to access Directory2 and User2 is not allowed to access Directory1 . Due to impersonation I should get only one number, depending on the user who is calling my application. Both user are set up as administrators. So I have created a new MVC-project in Visual Studio 2015 (running on Windows 8.1) and selected to use Windows authentication. Once the application is up and running (in ISS Express), I switch to User1 on my machine (there is no Active

Impersonation and DirectoryEntry

别来无恙 提交于 2019-12-05 05:19:05
I am impersonating a user account successfully, but I am not able to use the impersonated account to bind to AD and pull down a DirectoryEntry . The below code outputs: Before impersonation I am: DOMAIN\user After impersonation I am: DOMAIN\admin Error: C:\Users\user\ADSI_Impersonation\bin\Debug\ADSI_Impersonation.exe samaccountname: My issue seems similar to: How to use the System.DirectoryServices namespace in ASP.NET I am obtaining a primary token. I understand that I need to use delegation to use the impersonated token on a remote computer. I confirmed that the account doesn't have the

What is the magic to Windows impersonation with LOGON32_LOGON_NEW_CREDENTIALS?

时光毁灭记忆、已成空白 提交于 2019-12-04 22:14:24
问题 From my reading on user impersonation on Windows, one should properly use the LOGON32_LOGON_NEW_CREDENTIALS logon type for impersonating a user to a database. Using Matt Johnson's nice impersonation wrapper (originally posted here and then polished up here), I tried to test this out--here is my entire program except for constants defining my particular DOMAIN, USER, PWD, and CONN_STRING. using System; using System.Data.SqlClient; using SimpleImpersonation; namespace ImpersonationDemo { class

Impersonation in IIS 7.0

对着背影说爱祢 提交于 2019-12-04 21:33:19
问题 I have a website that works correctly under IIS 6.0: It authenticates users with windows credentials, and then when talking to the service that hits the DB, it passes the credentials. In IIS 7.0, the same config settings do not pass the credentials, and the DB gets hit with NT AUTHORITY\ANONYMOUS. Is there something I'm missing? I've turned ANONYMOUS access off in my IIS 7.0 website, but I can't get the thing to work. These are the settings that I'm using on both IIS 6.0 and 7.0:

Identity Impersonation with ASP.NET 4 MVC not working as expected

谁说胖子不能爱 提交于 2019-12-04 19:33:03
I am in the process of building a Intranet MVC 4 application for our analysts. The goal is to allow internal users access to this application without having to sign on given they are part of our internal network. When they access the application I want to be able to capture their windows user name and check against the active directory using LDAP and retrieve the department they belong to and display the relevant details on the screen. Based on the advice from different fora, I have chosen Windows Authentication for this application and I was able to test the app successfully running from