472,779 Members | 2,735 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,779 software developers and data experts.

Subject: How Take Ownership of Registry Key with .NET 2.0?

Apologies for the double-post.. I'm new, just getting used to this.. and
should have posted this way in the first place..

How does one go about taking ownership of a registry key using C# & .NET 2.0
*IF* one has _only_ TakeOwnership privilege?

The problem is exactly as specified in MS KB Article ID: 111546 at:
http://support.microsoft.com/kb/111546/EN-US/

...except that I would like to know how to do it in C#

Any help would be much appreciated. Thanks! (Again!)

Nov 17 '05 #1
9 7154
Hi Rheal,

Thanks for your post.

In .Net 1.1, there is no build-in for Access Control support, however,
Net2.0 has finally released several access control namespace such as
System.Security.AccessControl and System.Security.Principal. The article
below showed how to use these 2 namespaces to do what you want:
"Item 46: How to take ownership of an object"
http://www.pluralsight.com/keith/boo...ownership.html

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #2

Thank you for your reply:

On Fri, 23 Sep 2005 09:13:33 GMT, "Jeffrey Tan[MSFT]" wrote:
In .Net 1.1, there is no build-in for Access Control support, however,
.Net2.0 has finally released several access control namespace such as
System.Security.AccessControl and System.Security.Principal. The article
below showed how to use these 2 namespaces to do what you want:
"Item 46: How to take ownership of an object"
http://www.pluralsight.com/keith/boo...ownership.html


Unfortunately, the code example uses a type that VS 2005 RC does not
recognize - "LeafObjectSecurity"

A google search turns up very little, but more than a search on msdn,
microsoft.com, or the Visual Studio 2005 RC help, all of which turned up
absolutely *nothing* when I searched for simply "LeafObjectSecurity" - Of
the few results from Google, only one provided any hint - which seems to be
that LeafObjectSecurity was introduced in .NET Beta 1, but dropped in .NET
Beta 2.

http://www.aspnetdev.de/ClassReferen...ssControl.aspx

I am aware of the other namespaces you mentioned, and am able to pretty
much do any type of security manipulation with the Registry Keys *except*
take ownership when I have no other privileges than TakeOwner. ;)

Do you have any other thoughts on how I might be able to take ownership of
a Registry Key using C# and any of the new .NET 2.0 features? (that are
still valid in RC1, and hopefully also in Beta 2) .. and assuming still, of
course, that I have no other privileges than TakeOwner.

Thank you again for your time and assistance.

Cheers
Nov 17 '05 #3
Hi Andrew,

Thanks for your feedback.

Yes, Whidbey is in beta versions, and everything may be changed in RTM.

Currently, I suggest you p/invoke RegOpenKeyEx and RegSetKeySecurity to get
this done. With this, we do not reply on the change of Whidbey framework.
Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #4
On Wed, 28 Sep 2005 09:21:56 GMT, "Jeffrey Tan[MSFT]" wrote:
Hi Andrew,

Thanks for your feedback.

Yes, Whidbey is in beta versions, and everything may be changed in RTM.

Currently, I suggest you p/invoke RegOpenKeyEx and RegSetKeySecurity to get
this done. With this, we do not reply on the change of Whidbey framework.
Thanks


Hi Jeffrey,

Thank you very much again for your reply, and for the information. :)

Just to clarify - Is .NET 2.0 essentially a part of Whidbey? (and thus
meaning there's essentially no documented way to do what I want in .NET 2.0
for now..?)

I only ask because I sort of had the impression the .NET 2.0 went with
Visual Studio .NET 2005, and was thus going to be "released" with VS 2005.
If that were true (and I could obviously be totally mistaken) then there
"should" be a way to use the new .NET 2.0 functionality to take ownership
of a registry key as I wanted to, shouldn't there?

Meantime -- I'll try your suggestion about p/invoke - I've just never used
that before and it sounds complicated. ;)

Thanks again! I totally appreciate having you and the Concierge available!

Cheers

- Andrew
Nov 17 '05 #5
Hi

Thanks for your feedback.

Yes, Whidbey is the code name of .Net 2.0. I agree with you that Whidbey
should have build-in method to take the ownership of an object. But,
because Whidbey is still does not release, everything may change, and may
not available in RTM version. So using p/invoke to do this should be more
reliable currently. This is why I suggest you use legacy Win32 way(p/invoke
to Win32 API).

Anyway, in my Whidbey Beta2 version, there is a RegistrySecurity class can
be used for representing registry security. The code snippet below how to
get this done:

NTAccount account = new NTAccount(Environment.UserDomainName+
"\\"+Environment.UserName);
RegistryKey rk = Registry.ClassesRoot.CreateSubKey("mytest");
RegistrySecurity rs=rk.GetAccessControl();
rs.SetOwner(account);
rk.SetAccessControl(rs);

Note: we should first enable the TakeOwnership privilege in the process
token, however, currently, .Net still did not provide a way to enable this
privilege, we have to resort to win32 way. For a sample, please refer to
the link below:
http://pluralsight.com/wiki/default....oUseAPrivilege.
html
================================================== =
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #6
Hi Andrew,

Does my reply make sense to you? Is your problem resolved? Please feel free
to tell me, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #7
On Tue, 11 Oct 2005 07:35:45 GMT, "Jeffrey Tan[MSFT]" wrote:
Hi Andrew,

Does my reply make sense to you? Is your problem resolved? Please feel free
to tell me, thanks


Hi Jeffrey,

Thanks for the reply! :) And.. well.. your reply in and of itself does
make sense to me... ;)

However, that code you pointed me at, over on pluralsight.com seems
excessively complicated just to be _able_ to take ownership of a registry
key.. But if that's what I need to do, well, I'll try and figure it out. :)

I have to admit that all that token stuff is new to me... nor am I really
that sure how I'm supposed to use that code. It sounds like he's talking
about multiple privileges (privCount) - I don't even know how to begin to
call it and specify that I want the TakeOwnership privilege in the process
token. He also seems to be indicating that I should disable the privilege
afterwards.

I get the feeling that I can't just take that code, and dump it in at the
end of my source file and have it work. ;) (even if I _did_ know how to
call it..)

Is there somewhere that sort of eases into that stuff slowly, so that I
might have some hope of understanding it, and how I might make use of it? I
feel that I'm just missing some fundamentals about dealing with this type
of coding. (The privilege stuff from C++ _and_ calling C++ from C#)

Any pointers to documentation, tips, suggestions, thoughts, ideas, or any
other type of further assistance in figuring this out would again be very
much appreciated!

Thank you (again!) for your time and assistance with this!

- Andrew
Nov 17 '05 #8
Hi Andrew,

Thanks for your feedback.

I think your current concern is how to use the unmanaged code snippet of
enabling privilege in your application, yes?

I am not sure if you are familiar with making dll in VC++. I suggest you
use VC++ with that code snippet to create a dll which exports a function to
enable privilege. Then in .Net, we can use P/invoke to call this exported
function. After doing this, we should can use .Net2.0 classes to take the
ownership of registry.

Addtionally, if you just want to set the ownership of the registry to your
login account, just enabling SeTakeOwnershipPrivilege is enough. However,
if you want to set its ownership to any other valid account SID, we have to
enable another privilege: SeRestorePrivilege(These 2 privileges are both
assigned to Administrators local group by default, however it is disabled
by default, so we should enable it in our login account). For more
information about ownership, please refer to the links below:

http://win32.mvps.org/security/ownership.html
"A .NET Developer's Guide to Windows Security: Understanding Ownership"
http://www.awprofessional.com/articl...?p=350386&rl=1

For more information about p/invoke, please refer to the msdn article
below:
http://msdn.microsoft.com/msdnmag/issues/03/07/NET/

At last, for debugging or testing purpose, I usually use PView.exe in
Platform SDK to enable certain privilege of certain process. To do this, we
can first run up the application, then use PView.exe to find our process
and view its Process token, in the popup process token dialog, we can
enable any privilege we want. After enabling the privilege, we can force
the application to run the take ownership security code.

Hope this helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #9
Hi Andrew,

Does my reply make sense to you? Is your problem resolved? Please feel free
to tell me, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: steve b | last post by:
I need to add a registry entry to internet explorer (I'm adding a right click menu item) with vb.net setup program. Anyone know how to do that? Thanks!
11
by: Jacob | last post by:
I am trying to find the best way of documenting (in code and comments) ownership of secondary contained objects. This is my current status, and I would appreciate feedback on it: Case 1: ...
14
by: Howard | last post by:
Hi, I recently had a problem where I decided to store objects in a vector. (Previously, I had always stored pointers in vectors). Well, naturally, when storing an object in a vector, using...
2
by: Andrew | last post by:
I spent tons of time searching the web for how to use .NET 2.0 and C# to modify Registry key security. After finally finding an example, and once I knew the function names a few other small...
0
by: Andrew | last post by:
How does one go about taking ownership of a registry key using C# & .NET 2.0 *IF* one has _only_ TakeOwnership privilege? The problem is exactly as specified in MS KB Article ID: 111546 at:...
7
by: Stephen Engle | last post by:
I am trying to allow for user account to take ownership of an Active Directory object. I have assigned the Modify Owner permission to the user on the AD object - a distribution list in this case. ...
1
by: Martin Horn | last post by:
Hi all, I need to be able to do what it says in the subject line. For example I need to be able to take ownership of a file and set it's file security to Everyone/Full control. Had a quick...
3
by: YXQ | last post by:
Hello, I need to programmatically take ownership of a registry-key as current user using VB2005. To test this , i created a key HKEY_LOCAL_MACHINE\Software\TestKey and removed all accessrights...
0
by: riteshtechie | last post by:
I am trying to add following reg file to registry programatically using VB.NET http://www.winhelponline.com/fileasso/avi_fix_w7.zip But I am getting the following error. A search on...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.