中の技術日誌ブログ

C#とC++/CLIと
VBと.NETとWindowsで戯れる
 

目次

Blog 利用状況

ニュース

自己紹介

東京でソフトウェアエンジニアをやっています。
お仕事大募集中です。
記事執筆や、講師依頼とかでも何でもどうぞ(*^_^*)
似顔絵 MSMVPロゴ
MSMVP Visual C# Since 2004/04-2013/03

記事カテゴリ

書庫

日記カテゴリ

00-整理

01-MSMVP

WMIでアクセス権を操作するのと、.NETで操作するのと

別に中身は見なくてもいいです。

VBS+WMI

Function SetSecurityHomeDirectory(strComputer, strUser, HomePath)
SetSecurityHomeDirectory = False
Set objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
'アカウント取得
Set wmiAccounts = objWMIService.ExecQuery ( "select * from Win32_Account where Name='" & strUser & "'")
For Each obj in wmiAccounts
Set wmiAccount = obj
Exit For
Next

'Trusteeに変換する
Set wmiTrusteeClass = objWMIService.Get("Win32_Trustee")
Set wmiTrustee = wmiTrusteeClass.spawnInstance_()
Set wmiSID = objWMIService.Get("Win32_SID.SID='" & wmiAccount.sid & "'")
wmiTrustee.domain = wmiSID.ReferencedDomainName
wmiTrustee.name = wmiSID.AccountName
wmiTrustee.sid = wmiSID.BinaryRepresentation
wmiTrustee.sidLength = wmiSID.sidLength
wmiTrustee.sidString = wmiSID.sid
'ACEオブジェクトを作成する
Set wmiACEClass = objWMIService.get("Win32_ACE")
Set wmiACE = wmiACEClass.spawnInstance_()
wmiACE.AccessMask = 1+2+4+8+16+32+64+128+256+65536+131072+262144+524288+1048576 ' 2032127
wmiACE.trustee = wmiTrustee
wmiACE.AceType = 0
wmiACE.AceFlags = 3

'対象フォルダのセキュリティデスクリプタを取得する
Set wmiFileSecSetting = GetObject( "winmgmts:Win32_LogicalFileSecuritySetting.path='" & HomePath & "'")
RetVal = wmiFileSecSetting.GetSecurityDescriptor(wmiSecurityDescriptor)
If ( RetVal <> 0 ) Then
WScript.Echo "GetSecurityDescriptorに失敗しました:" & RetVal
Exit Function
End If

'ディクショナリにDACLを転記する
Set DictACE = CreateObject("Scripting.Dictionary")
For i = LBound(wmiSecurityDescriptor.DACL) to UBound(wmiSecurityDescriptor.DACL)
If ( not wmiSecurityDescriptor.DACL(i).AceFlags and 16 ) Then
Call DictACE.Add( i, wmiSecurityDescriptor.DACL(i) )
End if
Next

'設定する新しいACEオブジェクトを最後に足す
Call DictACE.add( "NewUser", wmiACE )

'DACLに書き戻す
wmiSecurityDescriptor.DACL = DictACE.Items

'対象フォルダのセキュリティデスクリプタを設定する
RetVal = wmiFileSecSetting.SetSecurityDescriptor(wmiSecurityDescriptor)
If ( RetVal <> 0 ) Then
WScript.Echo "SetSecurityDescriptorに失敗しました:" & RetVal
Exit Function
End If
SetSecurityHomeDirectory = True
End Function

C#+.NET2,0

 

public void SetFullAccess(string Path, string UserName)
{
DirectorySecurity ds = System.IO.Directory.GetAccessControl(Path);
bool modified;
bool ReturnValue = ds.ModifyAccessRule(AccessControlModification.Set, new FileSystemAccessRule(UserName, FileSystemRights.FullControl, AccessControlType.Allow), out modified);
if (modified == false || ReturnValue == false)
{
throw new Exception("アクセス権限を変更するのに失敗しました。");
}
ReturnValue = ds.ModifyAccessRule(AccessControlModification.Add, new FileSystemAccessRule(UserName, FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.InheritOnly, AccessControlType.Allow), out modified);
if (modified == false || ReturnValue == false)
{
throw new Exception("アクセス権限を変更するのに失敗しました。");
}
System.IO.Directory.SetAccessControl(Path, ds);
//FileSystemAccessRule fsar = new FileSystemAccessRule(UserName, FileSystemRights.

}

投稿日時 : 2007年4月20日 0:12

コメントを追加

# re: WMIでアクセス権を操作するのと、.NETで操作するのと 2007/04/20 0:13 中博俊

簡単さがわかればOK

# re: WMIでアクセス権を操作するのと、.NETで操作するのと 2007/04/20 1:20 ちゃっぴ

WSH で実装したことある私に喧嘩売ってます?
# 余裕で負けますけど。。。
# その前非常に苦労し、VB から Win32 呼び出してやったこともある。

いや、そりゃ .NET 使えれば楽でしたとも。。。
というか、昨日調べたんですけどこれ .NET 2.0 からなんですよね。

# re: WMIでアクセス権を操作するのと、.NETで操作するのと 2007/04/20 9:02 中博俊

いいえ(w
両方とも私のソースです。
移植中です

びっくりするくらい簡単

とりあえずTrasteeがないのがイイ

# It's very simple to find out any topic on net as compared to textbooks, as I found this post at this site. 2021/09/03 18:29 It's very simple to find out any topic on net as

It's very simple to find out any topic on net as compared
to textbooks, as I found this post at this site.

# At this moment I am ready to do my breakfast, after having my breakfast coming over again to read more news. 2021/09/05 6:50 At this moment I am ready to do my breakfast, afte

At this moment I am ready to do my breakfast, after having my breakfast coming over again to read more news.

# At this moment I am ready to do my breakfast, after having my breakfast coming over again to read more news. 2021/09/05 6:51 At this moment I am ready to do my breakfast, afte

At this moment I am ready to do my breakfast, after having my breakfast coming over again to read more news.

# At this moment I am ready to do my breakfast, after having my breakfast coming over again to read more news. 2021/09/05 6:52 At this moment I am ready to do my breakfast, afte

At this moment I am ready to do my breakfast, after having my breakfast coming over again to read more news.

# At this moment I am ready to do my breakfast, after having my breakfast coming over again to read more news. 2021/09/05 6:53 At this moment I am ready to do my breakfast, afte

At this moment I am ready to do my breakfast, after having my breakfast coming over again to read more news.

# Great beat ! I would like to apprentice even as you amend your web site, how could i subscribe for a blog site? The account helped me a appropriate deal. I had been tiny bit familiar of this your broadcast provided vivid transparent idea scoliosis surge 2021/09/14 6:52 Great beat ! I would like to apprentice even as yo

Great beat ! I would like to apprentice even as you amend your web site, how could
i subscribe for a blog site? The account helped me a appropriate deal.
I had been tiny bit familiar of this your broadcast provided vivid transparent idea
scoliosis surgery https://coub.com/stories/962966-scoliosis-surgery scoliosis surgery

# Great beat ! I would like to apprentice even as you amend your web site, how could i subscribe for a blog site? The account helped me a appropriate deal. I had been tiny bit familiar of this your broadcast provided vivid transparent idea scoliosis surge 2021/09/14 6:53 Great beat ! I would like to apprentice even as yo

Great beat ! I would like to apprentice even as you amend your web site, how could
i subscribe for a blog site? The account helped me a appropriate deal.
I had been tiny bit familiar of this your broadcast provided vivid transparent idea
scoliosis surgery https://coub.com/stories/962966-scoliosis-surgery scoliosis surgery

# Great beat ! I would like to apprentice even as you amend your web site, how could i subscribe for a blog site? The account helped me a appropriate deal. I had been tiny bit familiar of this your broadcast provided vivid transparent idea scoliosis surge 2021/09/14 6:54 Great beat ! I would like to apprentice even as yo

Great beat ! I would like to apprentice even as you amend your web site, how could
i subscribe for a blog site? The account helped me a appropriate deal.
I had been tiny bit familiar of this your broadcast provided vivid transparent idea
scoliosis surgery https://coub.com/stories/962966-scoliosis-surgery scoliosis surgery

# Great beat ! I would like to apprentice even as you amend your web site, how could i subscribe for a blog site? The account helped me a appropriate deal. I had been tiny bit familiar of this your broadcast provided vivid transparent idea scoliosis surge 2021/09/14 6:55 Great beat ! I would like to apprentice even as yo

Great beat ! I would like to apprentice even as you amend your web site, how could
i subscribe for a blog site? The account helped me a appropriate deal.
I had been tiny bit familiar of this your broadcast provided vivid transparent idea
scoliosis surgery https://coub.com/stories/962966-scoliosis-surgery scoliosis surgery

# ivermectin usa 2021/09/28 13:32 MarvinLic

ivermectin generic cream https://stromectolfive.com/# stromectol ireland

# It's not my first time to pay a quick visit this site, i am visiting this website dailly and take fastidious facts from here all the time. 2021/10/25 20:56 It's not my first time to pay a quick visit this s

It's not my first time to pay a quick visit this site,
i am visiting this website dailly and take fastidious facts from here all the time.

# buy ivermectin cream 2021/11/01 6:58 DelbertBup

generic ivermectin for humans http://stromectolivermectin19.com/# ivermectin 2%
ivermectin rx

# ivermectin syrup 2021/11/02 2:00 DelbertBup

ivermectin rx https://stromectolivermectin19.com/# ivermectin buy online
buy ivermectin cream

# ivermectin drug 2021/11/03 23:46 DelbertBup

ivermectin 50 https://stromectolivermectin19.com/# ivermectin lotion cost
ivermectin buy

# bimatoprost buy online usa 2021/12/14 3:12 Travislyday

http://stromectols.com/ ivermectin 2mg

# stromectol 6 mg dosage 2021/12/19 4:03 Eliastib

cdgjys https://stromectolr.com buy ivermectin nz

# Hello there! This article couldn't be written any better! Reading through this article reminds me of my previous roommate! He continually kept talking about this. I will forward this post to him. Fairly certain he'll have a very good read. Thanks for sh 2022/01/12 12:51 Hello there! This article couldn't be written any

Hello there! This article couldn't be written any better!

Reading through this article reminds me of my previous roommate!
He continually kept talking about this. I will forward this post to him.
Fairly certain he'll have a very good read. Thanks for sharing!

# finasteride tablets https://finasteridemen.com/
2022/05/11 23:50 Finasteride

finasteride tablets https://finasteridemen.com/

# prednisone prescription for sale https://deltasone.icu/
prednisone 5 mg cheapest 2022/08/22 17:36 Prednisone

prednisone prescription for sale https://deltasone.icu/
prednisone 5 mg cheapest

# metformin price australia https://glucophage.top/
buy metformin 1000 mg online 2022/08/23 15:35 Niujsdkj

metformin price australia https://glucophage.top/
buy metformin 1000 mg online

# prednisone uk buy https://prednisonepills.site/
buy prednisone 20mg 2022/11/30 7:55 Prednisone

prednisone uk buy https://prednisonepills.site/
buy prednisone 20mg

# doors2.txt;1 2023/03/14 14:51 CfroHuFTSGAIwGDY

doors2.txt;1

# le migliori pillole per l'erezione https://viasenzaricetta.com/# 2023/04/16 14:30 ViaSenza

le migliori pillole per l'erezione https://viasenzaricetta.com/#

# buying ed pills online https://edpill.pro/# - ed medications 2023/06/27 16:03 EdPills

buying ed pills online https://edpill.pro/# - ed medications

# canadian meds https://fastpills.pro/# overseas pharmacies shipping to usa 2023/06/30 1:04 FastPills

canadian meds https://fastpills.pro/# overseas pharmacies shipping to usa

# paxlovid generic https://paxlovid.bid/ paxlovid buy 2023/10/26 0:37 Paxlovid

paxlovid generic https://paxlovid.bid/ paxlovid buy

# farmaci senza ricetta elenco https://farmaciait.pro/ farmacia online miglior prezzo 2023/12/04 11:16 Farmacia

farmaci senza ricetta elenco https://farmaciait.pro/ farmacia online miglior prezzo

# prednisone canada prices https://prednisonepharm.store/ where can i buy prednisone 2024/01/20 18:05 Prednisone

prednisone canada prices https://prednisonepharm.store/ where can i buy prednisone

# Abella Danger https://abelladanger.online/ abella danger video
2024/03/06 11:18 Adella

Abella Danger https://abelladanger.online/ abella danger video

タイトル
名前
URL
コメント