Win32_Directory 類別的 TakeOwnerShipEx 方法

TakeOwnerShipExWMI 類別方法會取得物件路徑中指定的邏輯目錄專案檔案擁有權。 這個方法是 TakeOwnerShip 方法的擴充版本。 如果邏輯檔案實際上是目錄,則此方法會以遞迴方式運作,並取得目錄包含之所有檔案和子目錄的擁有權。

本主題使用 Managed 物件格式 (MOF) 語法。 如需使用此方法的詳細資訊,請參閱 呼叫方法

語法

uint32 TakeOwnerShipEx(
  [out]          string  StopFileName,
  [in, optional] string  StartFileName,
  [in, optional] boolean Recursive
);

參數

StopFileName [out]

TakeOwnerShipEx方法失敗的檔案或目錄名稱。 如果方法成功,則此參數為 Null

StartFileName [in, optional]

將子檔案或目錄命名為 TakeOwnerShipEx的起點。 StartFileName參數通常是StopFileName參數,指定先前方法呼叫發生錯誤的檔案或目錄。 如果此參數為 Null,則會在 ExecMethod 呼叫中指定的檔案或目錄上執行作業。

如果使用 StartFileName則 Recursive 也必須設定為 true。

遞迴 [in, 選擇性]

如果為 True,則會以遞迴方式將擁有權變更套用至 CIM_LogicalFile 實例所指定目錄中的檔案和目錄。

注意

如果是檔案實例,則會忽略 遞迴 輸入參數。

傳回值

傳回 0 的整數值, (零) 成功時,傳回任何其他數位來表示錯誤。

0

要求成功。

2

拒絕存取。

8

發生未指定的失敗。

9

指定的名稱無效。

10

指定的物件已經存在。

11

檔案系統不是 NTFS。

12

平臺不是 Windows。

13

磁片磁碟機不相同。

14

目錄不是空的。

15

共用違規。

16

指定的啟動檔案無效。

17

不會保留作業所需的許可權。

21

指定的參數無效。

範例

下列 Visual Basic 腳本程式碼會呼叫 TakeOwnerShipEx 方法,以取得 C:\temp 資料夾的擁有權。

strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") 
' Obtain the definition of the class.
Set objShare = objWMIService.Get("Win32_Directory")
' Obtain an InParameters object specific
' to the method.
Set objInParam = objShare.Methods_("TakeOwnerShipEx").inParameters.SpawnInstance_()

' Add the input parameters.
objInParam.Properties_.Item("Recursive") =  true

' Execute the method and obtain the return status.
' The OutParameters object in objOutParams
' is created by the provider.
Set objOutParams = objWMIService.ExecMethod("Win32_Directory.Name='C:\Temp'", "TakeOwnerShipEx", objInParam)
wscript.echo objOutParams.ReturnValue

規格需求

需求
最低支援的用戶端
Windows Vista
最低支援的伺服器
Windows Server 2008
命名空間
Root\CIMV2
MOF
CIMWin32.mof
DLL
CIMWin32.dll

另請參閱

作業系統類別

Win32_Directory