可以使用 URL rewrite的機制
takeown /a /r /d Y /f C:\{foldername}
參考:
https://www.petenetlive.com/KB/Article/0001200
https://ithelp.ithome.com.tw/articles/10238630
// 參考: https://docs.microsoft.com/zh-TW/troubleshoot/aspnet/implement-impersonation
public class ImpersonateHelper {
public const int LOGON32_LOGON_INTERACTIVE = 2;
public const int LOGON32_PROVIDER_DEFAULT = 0;
WindowsImpersonationContext impersonationContext;
[DllImport("advapi32.dll")]
public static extern int LogonUserA(String lpszUserName,
String lpszDomain,
String lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken);
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern int DuplicateToken(IntPtr hToken,
int impersonationLevel,
ref IntPtr hNewToken);
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool RevertToSelf();
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern bool CloseHandle(IntPtr handle);
public bool impersonateValidUser(string userName, string password, string domain) {
WindowsIdentity tempWindowsIdentity;
IntPtr token = IntPtr.Zero;
IntPtr tokenDuplicate = IntPtr.Zero;
if (RevertToSelf()) {
if (LogonUserA(userName, domain, password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref token) != 0) {
if (DuplicateToken(token, 2, ref tokenDuplicate) != 0) {
tempWindowsIdentity = new WindowsIdentity(tokenDuplicate);
impersonationContext = tempWindowsIdentity.Impersonate();
if (impersonationContext != null) {
CloseHandle(token);
CloseHandle(tokenDuplicate);
return true;
}
}
}
}
if (token != IntPtr.Zero)
CloseHandle(token);
if (tokenDuplicate != IntPtr.Zero)
CloseHandle(tokenDuplicate);
return false;
}
public void undoImpersonation() {
impersonationContext.Undo();
}
}
static void Main(string[] args) {
XElement bookElement = new XElement("book");
XDocument doc = new XDocument(bookElement);
AddElement(ref doc, "author", "Gambardella, Matthew");
AddElement(ref doc, "title", "XML Developer's Guide");
AddElement(ref doc, "genre", "Computer");
AddElement(ref doc, "price", 44.95);
AddElement(ref doc, "publish_date", new DateTime(2000, 1, 1));
AddElement(ref doc, "description", "An in-depth look at creating applications with XML.");
Console.WriteLine(doc.ToString());
ReplaceTagName(ref doc, "description", "memo");
Console.WriteLine(doc.ToString());
RemoveElement(ref doc, "genre");
Console.WriteLine(doc.ToString());
}
// 更換xml的tag name
public static void ReplaceTagName(ref XDocument doc, string origTagName, string newTagName) {
foreach (var element in doc.Descendants()) {
if (element.Name.LocalName.Equals(origTagName)) {
element.Name = newTagName;
}
}
}
// 新增欄位
public static void AddElement(ref XDocument doc, string elementName, object elementValue) {
try {
doc.Root.Add(new XElement(elementName, elementValue));
} catch (Exception e) {
Console.WriteLine("AddElement error:" + doc.ToString() + Environment.NewLine + e.StackTrace);
}
}
// 移除欄位
public static void RemoveElement(ref XDocument doc, string elementName) {
try {
doc.Descendants().SingleOrDefault(p => p.Name == elementName).Remove();
} catch (Exception e) {
Console.WriteLine("RemoveElement error:" + doc.ToString() + Environment.NewLine + e.StackTrace);
}
}
UPDATE UpdateTarget
SET seq = rownum
FROM (
SELECT seq, row_number () OVER (ORDER BY seq) rownum
FROM Table
WHERE no = @no
) UpdateTarget