In my scenario, I had to write to a file through an existing COM Component via a .NET COM Interop library. It depended on the write operation being done from the context of a valid user - otherwise the file wouldn't be stamped correctly with author metadata.
To do this, I had to use an overload of the WindowsIdentity constructor which accepts a UPN (User Principal Name). From there, you can impersonate users within your code at will.
NOTE: the account that is doing the impersonation (e.g. svcSP) will need to have the "Act as Part of the Operating System" right as defined in your Local User Policy for this to work.
Code Sample:
void Main() { var userName = "LOCALDEV\\david.klein"; PrincipalContext ctx = new PrincipalContext(ContextType.Domain); var user = UserPrincipal.FindByIdentity(ctx, userName); if (user != null) { var upn = user.UserPrincipalName; Debug.Print(upn); WindowsIdentity id = new WindowsIdentity(upn); WindowsImpersonationContext wic = id.Impersonate(); try { // Do what you need here under the impersonation context. var currentId = WindowsIdentity.GetCurrent().Name; Debug.Print(currentId); } finally { wic.Undo(); } } }
27 comments:
Your content is awesome . You have done a great job and its very useful for me . I appreciate your effort and I hope that you will get more positive comments from the web users.
SMO Services Chennai
Got a creative information. Understand well in this. This gives the easy technique of experiment. New technologies are developed more. so techniques are also improved. Thank you for this information.
Digital Marketing Company in Chennai
Wonderful blog.. Thanks for sharing informative blog.. its very useful to me..
iOS Training in Chennai
Thank you for taking the time to provide us with your valuable information. We strive to provide our candidates with excellent care and we take your comments to heart.As always, we appreciate your confidence and trust in us.
Best Dental Clinic In Velachery
Nice it seems to be good post... It will get readers engagement on the article since readers engagement plays an vital role in every
blog.. i am expecting more updated posts from your hands.
Android App Development Company
mobile App Development Company
I am expecting more interesting topics from you. And this was nice content and definitely it will be useful for many people.
iOS App Development Company
iOS App Development Company
These ways are very simple and very much useful, as a beginner level these helped me a lot thanks fore sharing these kinds of useful and knowledgeable information.
Fitness SMS
Fitness Text
Salon SMS
Salon Text
Investor Relation SMS
Investor Relation Text
great and nice blog thanks sharing..I just want to say that all the information you have given here is awesome...Thank you very much for this one.
web design Company
web development Company
web design Company in chennai
web development Company in chennai
web design Company in India
web development Company in India
it is really amazing...thanks for sharing....provide more useful information...
Mobile app development company
it is really amazing...thanks for sharing....provide more useful information...
Mobile app development company
Get Details of Flooring Tiles Manufacturers And Dealers. ... Heat Resistance Tiles, Heat Resistant Terrace Tiles. Thanks you for sharing
tile bonder manufacturer in delhi
Lifestyle Magazine India; Lifestyle is a elite magazine circulated to the elite at page parties. Lifestyle Magazine also circulated to the elite at clubs, lounge bars etc.
Lifestyle Magazine
hi, nice information is given in this blog. Thanks for sharing this type of information, it is so useful for me. nice work keep it up.
digital marketing company in delhi
nice topic which you have choose.
second is, the information which you have provided is better then other blog.
so nice work keep it up. And thanks for sharing.
Epoxy Grout manufacturer in delhi
Laminated Doors manufacturer in hubli
hi, nice information is given in this blog. Thanks for sharing this type of information, it is so useful for me. nice work keep it up. led lawn lights in delhi
All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.
Java training in Pune
Java interview questions and answers
Java training in Chennai | Java training institute in Chennai | Java course in Chennai
Java training in Bangalore | Java training institute in Bangalore | Java course in Bangalore
This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me..
python course in pune
python course in chennai
python course in Bangalore
Thanks for such a great article here. I was searching for something like this for quite a long time and at last I’ve found it on your blog. It was definitely interesting for me to read about their market situation nowadays.
Data Science course in Chennai | Best Data Science course in Chennai
Data science course in bangalore | Best Data Science course in Bangalore
Data science course in pune | Data Science Course institute in Pune
Data science online course | Online Data Science certification course-Gangboard
Data Science Interview questions and answers
Nice tutorial. Thanks for sharing the valuable information. it’s really helpful. Who want to learn this blog most helpful. Keep sharing on updated tutorials…
Best Devops training in sholinganallur
Devops training in velachery
Devops training in annanagar
Devops training in tambaram
I appreciate your efforts because it conveys the message of what you are trying to say. It's a great skill to make even the person who doesn't know about the subject could able to understand the subject . Your blogs are understandable and also elaborately described. I hope to read more and more interesting articles from your blog. All the best.
rpa training in Chennai | rpa training in bangalore | best rpa training in bangalore | rpa course in bangalore | rpa training institute in bangalore | rpa training in bangalore | rpa online training
Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
angularjs interview questions and answers
angularjs Training in bangalore
angularjs Training in bangalore
angularjs interview questions and answers
angularjs Training in marathahalli
angularjs interview questions and answers
شركة مكافحة حشرات بنجران
Thanks for sharing this blog, this blog is very helpful information for every one.
Mobile app Development Company in Noida
Inspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you.
Keep update more information..
Selenium training in bangalore
Selenium training in Chennai
Selenium training in Bangalore
Selenium training in Pune
Selenium Online training
Selenium interview questions and answers
Read all the information that i've given in above article. It'll give u the whole idea about it.
microsoft azure training in bangalore
rpa training in bangalore
best rpa training in bangalore
rpa online training
شركة تنظيف بالدمام
شركة تركيب كهرباء بالدمام
شركة تمديد و صيانة برك مسابح بالدمام
Post a Comment