<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="de">
	<id>https://wiki.wingeav.de/index.php?action=history&amp;feed=atom&amp;title=Windows_SetOwner_mit_C-Sharp</id>
	<title>Windows SetOwner mit C-Sharp - Versionsgeschichte</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.wingeav.de/index.php?action=history&amp;feed=atom&amp;title=Windows_SetOwner_mit_C-Sharp"/>
	<link rel="alternate" type="text/html" href="https://wiki.wingeav.de/index.php?title=Windows_SetOwner_mit_C-Sharp&amp;action=history"/>
	<updated>2026-04-17T21:06:47Z</updated>
	<subtitle>Versionsgeschichte dieser Seite in MyWiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://wiki.wingeav.de/index.php?title=Windows_SetOwner_mit_C-Sharp&amp;diff=85&amp;oldid=prev</id>
		<title>Rueling am 19. März 2013 um 16:30 Uhr</title>
		<link rel="alternate" type="text/html" href="https://wiki.wingeav.de/index.php?title=Windows_SetOwner_mit_C-Sharp&amp;diff=85&amp;oldid=prev"/>
		<updated>2013-03-19T16:30:13Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;de&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Nächstältere Version&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Version vom 19. März 2013, 16:30 Uhr&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l3&quot;&gt;Zeile 3:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Zeile 3:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Windows erlaubt es nicht, den Besitzer einer Datei oder eines Verzeichnisses auf einen anderen Benutzer zu setzen als den angemeldeten. Das betrifft zumindest Powershell und C# Programme. Per Explorer-GUI funktioniert es.  &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Windows erlaubt es nicht, den Besitzer einer Datei oder eines Verzeichnisses auf einen anderen Benutzer zu setzen als den angemeldeten. Das betrifft zumindest Powershell und C# Programme. Per Explorer-GUI funktioniert es.  &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Die Fehlermeldung die beim Versuch den Besitzer zu setzen kommt, lautet:&amp;lt;br&amp;gt; &quot;Die Sicherheits-ID darf nicht der Besitzer dieses Objekts sein&quot;&amp;lt;br&amp;gt; bzw. &quot;The security identifier is not allowed to be the owner of this object&quot; &amp;lt;br&amp;gt;&amp;lt;br&amp;gt; Wenn ich es richtig gelesen habe, wird dafür die Berechtigung &quot;Restore files and directories&quot; benötigt&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; im Internet auf der folgenden Seite habe ich ein Code-Beispiel gefunden, mit dem die Berechtigung während der Laufzeit gesetzt wird.&amp;lt;br&amp;gt; Damit ist es möglich die SetOwner Funktion aufzurufen&amp;lt;br&amp;gt; Der Code stammt von: http://blog.salamandersoft.co.uk/index.php/2009/10/setting-the-owner-of-files-and-directories-in-c  &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Die Fehlermeldung die beim Versuch den Besitzer zu setzen kommt, lautet:&amp;lt;br&amp;gt; &quot;Die Sicherheits-ID darf nicht der Besitzer dieses Objekts sein&quot;&amp;lt;br&amp;gt; bzw. &quot;The security identifier is not allowed to be the owner of this object&quot; &amp;lt;br&amp;gt;&amp;lt;br&amp;gt; Wenn ich es richtig gelesen habe, wird dafür die Berechtigung &quot;Restore files and directories&quot; benötigt&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; im Internet auf der folgenden Seite habe ich ein Code-Beispiel gefunden, mit dem die Berechtigung während der Laufzeit gesetzt wird.&amp;lt;br&amp;gt; Damit ist es möglich die SetOwner Funktion aufzurufen&amp;lt;br&amp;gt; Der Code stammt von: &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&#039;&#039;&lt;/ins&gt;http://blog.salamandersoft.co.uk/index.php/2009/10/setting-the-owner-of-files-and-directories-in-c&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&#039;&#039; &lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Der Code wird ausgeführt mit: EnablePriviledge.GiveRestorePrivilege();&amp;amp;nbsp;&amp;lt;br&amp;gt;&amp;#039;&amp;#039;&amp;#039;Die erstellte Anwendung muss trotzdem mit Admin-Rechten ausgeführt werden&amp;#039;&amp;#039;&amp;#039;  &lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Der Code wird ausgeführt mit: EnablePriviledge.GiveRestorePrivilege();&amp;amp;nbsp;&amp;lt;br&amp;gt;&amp;#039;&amp;#039;&amp;#039;Die erstellte Anwendung muss trotzdem mit Admin-Rechten ausgeführt werden&amp;#039;&amp;#039;&amp;#039;  &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l120&quot;&gt;Zeile 120:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Zeile 120:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     }&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     }&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;/pre&amp;gt; &lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;br&amp;gt; Die Funktion zum Setzen der Berechtigung ist wie folgt: &lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&amp;lt;pre&amp;gt;        public static DirectorySecurity SetACL(string username, string domain)&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;        {&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;            DirectorySecurity dirSecurity = new DirectorySecurity();&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;            NTAccount account = new NTAccount(domain, username);&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;            dirSecurity.SetAccessRuleProtection(true, false); // Vererbung deaktivieren, alle vererbten ACLs löschen&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;            &lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;            FileSystemAccessRule rule = new FileSystemAccessRule(account, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow);&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;            dirSecurity.ResetAccessRule(rule);&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;            dirSecurity.SetOwner(account);&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;            &lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;            //********* Regel für Benutzer: &quot;NT-AUTORITÄT\SYSTEM&quot; bzw. &quot;NT AUTHORITY\SYSTEM&quot; ********\\&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;            SecurityIdentifier sid = new SecurityIdentifier(&quot;S-1-5-18&quot;);&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;            NTAccount system_account = (NTAccount)sid.Translate(typeof(NTAccount));&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;            rule = new FileSystemAccessRule(system_account, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow);&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;            dirSecurity.AddAccessRule(rule);&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;            //********* Regel für Benutzer: &quot;NT-AUTORITÄT\SYSTEM&quot; bzw. &quot;NT AUTHORITY\SYSTEM&quot; ********\\&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;            return dirSecurity;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;        }&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;		&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;        DirectoryInfo dirInfo = new DirectoryInfo(pfad);&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;	DirectorySecurity dirsec = SetACL(&quot;Hans.Mustergatte&quot;, &quot;CONTOSO&quot;) // nicht contoso.com &lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;	dirInfo.SetAccessControl(dirsec);&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;		&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/pre&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Rueling</name></author>
	</entry>
	<entry>
		<id>https://wiki.wingeav.de/index.php?title=Windows_SetOwner_mit_C-Sharp&amp;diff=84&amp;oldid=prev</id>
		<title>Rueling: Die Seite wurde neu angelegt: „&lt;u&gt;&lt;/u&gt;   Windows erlaubt es nicht, den Besitzer einer Datei oder eines Verzeichnisses auf einen anderen Benutzer zu setzen als den angemeldeten. Das betrifft zum…“</title>
		<link rel="alternate" type="text/html" href="https://wiki.wingeav.de/index.php?title=Windows_SetOwner_mit_C-Sharp&amp;diff=84&amp;oldid=prev"/>
		<updated>2013-03-19T16:23:34Z</updated>

		<summary type="html">&lt;p&gt;Die Seite wurde neu angelegt: „&amp;lt;u&amp;gt;&amp;lt;/u&amp;gt;   Windows erlaubt es nicht, den Besitzer einer Datei oder eines Verzeichnisses auf einen anderen Benutzer zu setzen als den angemeldeten. Das betrifft zum…“&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Neue Seite&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;u&amp;gt;&amp;lt;/u&amp;gt; &lt;br /&gt;
&lt;br /&gt;
Windows erlaubt es nicht, den Besitzer einer Datei oder eines Verzeichnisses auf einen anderen Benutzer zu setzen als den angemeldeten. Das betrifft zumindest Powershell und C# Programme. Per Explorer-GUI funktioniert es. &lt;br /&gt;
&lt;br /&gt;
Die Fehlermeldung die beim Versuch den Besitzer zu setzen kommt, lautet:&amp;lt;br&amp;gt; &amp;quot;Die Sicherheits-ID darf nicht der Besitzer dieses Objekts sein&amp;quot;&amp;lt;br&amp;gt; bzw. &amp;quot;The security identifier is not allowed to be the owner of this object&amp;quot; &amp;lt;br&amp;gt;&amp;lt;br&amp;gt; Wenn ich es richtig gelesen habe, wird dafür die Berechtigung &amp;quot;Restore files and directories&amp;quot; benötigt&amp;lt;br&amp;gt;&amp;lt;br&amp;gt; im Internet auf der folgenden Seite habe ich ein Code-Beispiel gefunden, mit dem die Berechtigung während der Laufzeit gesetzt wird.&amp;lt;br&amp;gt; Damit ist es möglich die SetOwner Funktion aufzurufen&amp;lt;br&amp;gt; Der Code stammt von: http://blog.salamandersoft.co.uk/index.php/2009/10/setting-the-owner-of-files-and-directories-in-c &lt;br /&gt;
&lt;br /&gt;
Der Code wird ausgeführt mit: EnablePriviledge.GiveRestorePrivilege();&amp;amp;nbsp;&amp;lt;br&amp;gt;&amp;#039;&amp;#039;&amp;#039;Die erstellte Anwendung muss trotzdem mit Admin-Rechten ausgeführt werden&amp;#039;&amp;#039;&amp;#039; &lt;br /&gt;
&amp;lt;pre&amp;gt;using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.Threading.Tasks;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
namespace CreateHomeDirs&lt;br /&gt;
{&lt;br /&gt;
    sealed class EnablePriviledge&lt;br /&gt;
    {&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        static extern bool CloseHandle(IntPtr hObject);&lt;br /&gt;
&lt;br /&gt;
        // Use this signature if you do not want the previous state&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        [return: MarshalAs(UnmanagedType.Bool)]&lt;br /&gt;
        static extern bool AdjustTokenPrivileges(IntPtr tokenHandle,&lt;br /&gt;
            [MarshalAs(UnmanagedType.Bool)]bool disableAllPrivileges,&lt;br /&gt;
            ref TOKEN_PRIVILEGES newState,&lt;br /&gt;
            UInt32 bufferLength,&lt;br /&gt;
            IntPtr previousState,&lt;br /&gt;
            IntPtr returnLength);&lt;br /&gt;
&lt;br /&gt;
        [DllImport(&amp;quot;kernel32.dll&amp;quot;, ExactSpelling = true)]&lt;br /&gt;
        static extern IntPtr GetCurrentProcess();&lt;br /&gt;
&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, ExactSpelling = true, SetLastError = true)]&lt;br /&gt;
        static extern bool OpenProcessToken&lt;br /&gt;
            (IntPtr processHandle, int desiredAccess, ref IntPtr phtok);&lt;br /&gt;
&lt;br /&gt;
        [DllImport(&amp;quot;advapi32.dll&amp;quot;, SetLastError = true)]&lt;br /&gt;
        static extern bool LookupPrivilegeValue&lt;br /&gt;
                (string host, string name, ref LUID lpLuid);&lt;br /&gt;
&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential, Pack = 1)]&lt;br /&gt;
        struct TOKEN_PRIVILEGES&lt;br /&gt;
        {&lt;br /&gt;
            public UInt32 PrivilegeCount;&lt;br /&gt;
            public LUID Luid;&lt;br /&gt;
            public UInt32 Attributes;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        [StructLayout(LayoutKind.Sequential)]&lt;br /&gt;
        public struct LUID&lt;br /&gt;
        {&lt;br /&gt;
            public uint LowPart;&lt;br /&gt;
            public int HighPart;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        const int SE_PRIVILEGE_ENABLED = 0x00000002;&lt;br /&gt;
        const int TOKEN_QUERY = 0x00000008;&lt;br /&gt;
        const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;&lt;br /&gt;
        //http://msdn.microsoft.com/en-us/library/bb530716(VS.85).aspx&lt;br /&gt;
        const string SE_RESTORE_PRIVILEGE = &amp;quot;SeRestorePrivilege&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        public static void GiveRestorePrivilege()&lt;br /&gt;
        {&lt;br /&gt;
            TOKEN_PRIVILEGES tokenPrivileges;&lt;br /&gt;
            tokenPrivileges.PrivilegeCount = 1;&lt;br /&gt;
            tokenPrivileges.Luid = new LUID();&lt;br /&gt;
            tokenPrivileges.Attributes = SE_PRIVILEGE_ENABLED;&lt;br /&gt;
&lt;br /&gt;
            IntPtr tokenHandle = RetrieveProcessToken();&lt;br /&gt;
&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                bool success = LookupPrivilegeValue&lt;br /&gt;
                            (null, SE_RESTORE_PRIVILEGE, ref tokenPrivileges.Luid);&lt;br /&gt;
                if (success == false)&lt;br /&gt;
                {&lt;br /&gt;
                    int lastError = Marshal.GetLastWin32Error();&lt;br /&gt;
                    throw new Exception(&lt;br /&gt;
                        string.Format(&amp;quot;Could not find privilege {0}. Error {1}&amp;quot;,&lt;br /&gt;
                                            SE_RESTORE_PRIVILEGE, lastError));&lt;br /&gt;
                }&lt;br /&gt;
&lt;br /&gt;
                success = AdjustTokenPrivileges(&lt;br /&gt;
                                                    tokenHandle, false,&lt;br /&gt;
                                                    ref tokenPrivileges, 0,&lt;br /&gt;
                                                    IntPtr.Zero, IntPtr.Zero);&lt;br /&gt;
                if (success == false)&lt;br /&gt;
                {&lt;br /&gt;
                    int lastError = Marshal.GetLastWin32Error();&lt;br /&gt;
                    throw new Exception(&lt;br /&gt;
                        string.Format(&amp;quot;Could not assign privilege {0}. Error {1}&amp;quot;,&lt;br /&gt;
                                        SE_RESTORE_PRIVILEGE, lastError));&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            finally&lt;br /&gt;
            {&lt;br /&gt;
                CloseHandle(tokenHandle);&lt;br /&gt;
            }&lt;br /&gt;
&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        static IntPtr RetrieveProcessToken()&lt;br /&gt;
        {&lt;br /&gt;
            IntPtr processHandle = GetCurrentProcess();&lt;br /&gt;
            IntPtr tokenHandle = IntPtr.Zero;&lt;br /&gt;
            bool success = OpenProcessToken(processHandle,&lt;br /&gt;
                                            TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&lt;br /&gt;
                                            ref tokenHandle);&lt;br /&gt;
            if (success == false)&lt;br /&gt;
            {&lt;br /&gt;
                int lastError = Marshal.GetLastWin32Error();&lt;br /&gt;
                throw new Exception(&lt;br /&gt;
                    string.Format(&amp;quot;Could not retrieve process token. Error {0}&amp;quot;,&lt;br /&gt;
                                        lastError));&lt;br /&gt;
            }&lt;br /&gt;
            return tokenHandle;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Rueling</name></author>
	</entry>
</feed>