.NET Framework Developer Center >
.NET Development Forums
>
Common Language Runtime
>
"Not found" exception when populating a Win32_Trustee object
"Not found" exception when populating a Win32_Trustee object
- The purpose of my code is to create a share on a folder on the local machine and give a local user account rights to it. This code is working great on every machine but one (Windows XP SP2). On that particular machine, the user gets a "Not found" exception when the code tries to assign any of the properties of the Trustee ManagementObject object.This is the exception text:
Dim account As New NTAccount(Environment.MachineName.ToString(), User1) Dim sid As SecurityIdentifier = DirectCast(account.Translate(GetType(SecurityIdentifier)), SecurityIdentifier) Dim sidArray As Byte() = New Byte(sid.BinaryLength - 1) {} sid.GetBinaryForm(sidArray, 0) Dim Trustee As ManagementObject = New ManagementClass(New ManagementPath("Win32_Trustee"), Nothing) Trustee("SID") = sidArray 'ERROR OCCURS HERE Dim AdminACE As ManagementObject = New ManagementClass(New ManagementPath("Win32_Ace"), Nothing) AdminACE("AccessMask") = 1245631 '2032127 = "Full"; 1245631 = "Change"; 1179817 = "Read" AdminACE("AceFlags") = 3 AdminACE("AceType") = 0 AdminACE("Trustee") = Trustee Dim secDescriptor As ManagementObject = New ManagementClass(New ManagementPath("Win32_SecurityDescriptor"), Nothing) secDescriptor("ControlFlags") = 4 'SE_DACL_PRESENT secDescriptor("DACL") = New Object() {AdminACE} Dim managementClass As New ManagementClass("Win32_Share") Dim inParams As ManagementBaseObject = managementClass.GetMethodParameters("Create") Dim outParams As ManagementBaseObject inParams("Name") = "ShareName" inParams("Type") = &H0 ' Disk Drive inParams("Access") = secDescriptor inParams("Path") = "C:\SharedFolder" outParams = managementClass.InvokeMethod("Create", inParams, Nothing) ' Check to see if the method invocation was successful Select Case CUInt((outParams.Properties("ReturnValue").Value)) Case 0 'No Error MsgBox("Success") Case 22 'Share name already exists. MsgBox("Share Name already exists") Case Else '?? Throw New Exception("Unexpected error. Unable to share directory. Error: " & outParams.Properties("ReturnValue").Value) End Select
exception: Not found
Stack: at System.Management.ThreadDispatch.Start()
at System.Management.ManagementScope.Initialize()
at System.Management.ManagementObject.Initialize(Boolean getObject)
at System.Management.ManagementBaseObject.set_Item(String propertyName, Object value)
This is only happening on one machine. I've tried deleting and recreating the local user account thinking maybe that was corrupt in some way but that didn't help. I 've tried creating a new local folder but that didn't help. I can assign the share permissions to the local folder using the Windows interface without any errors.
Has anyone seen this? Any suggestions?
Answers
- Thanks for the reply Eric. The line that was causing the error is marked with "'ERROR OCCURS HERE" in the above code. Fortunately I have found the resolution to this issue. It was being caused by a corrupt WMI installation. I fixed WMI by running this script.
--------------------------------------------------------------------------------------
net stop winmgmt
pause
c:
cd c:\windows\system32\wbem
rd /S /Q repository
regsvr32 /s %systemroot%\system32\scecli.dll
regsvr32 /s %systemroot%\system32\userenv.dll
mofcomp cimwin32.mof
mofcomp cimwin32.mfl
mofcomp rsop.mof
mofcomp rsop.mfl
for /f %%s in ('dir /b /s *.dll') do regsvr32 /s %%s
for /f %%s in ('dir /b *.mof') do mofcomp %%s
for /f %%s in ('dir /b *.mfl') do mofcomp %%s
mofcomp exwmi.mof
mofcomp -n:root\cimv2\applications\exchange wbemcons.mof
mofcomp -n:root\cimv2\applications\exchange smtpcons.mof
mofcomp exmgmt.mof
-------------------------------------------------------------------------
I found the script here. I'm not sure exactly what was corrupt or how it happened but the script did fix it.
I hope this helps anyone else having this issue.- Marked As Answer bydiver7 Wednesday, November 11, 2009 2:08 PM
All Replies
- Hi,
It sounds that a property cannot be found, if you VS environment in that machine, debug your source code to find out which line brings the exception. if not, CLR Dbg can help you to do some debugging at the target machine.
Thanks,
Eric
Please remember to mark helpful replies as answers and unmark them if they provide no help. - Thanks for the reply Eric. The line that was causing the error is marked with "'ERROR OCCURS HERE" in the above code. Fortunately I have found the resolution to this issue. It was being caused by a corrupt WMI installation. I fixed WMI by running this script.
--------------------------------------------------------------------------------------
net stop winmgmt
pause
c:
cd c:\windows\system32\wbem
rd /S /Q repository
regsvr32 /s %systemroot%\system32\scecli.dll
regsvr32 /s %systemroot%\system32\userenv.dll
mofcomp cimwin32.mof
mofcomp cimwin32.mfl
mofcomp rsop.mof
mofcomp rsop.mfl
for /f %%s in ('dir /b /s *.dll') do regsvr32 /s %%s
for /f %%s in ('dir /b *.mof') do mofcomp %%s
for /f %%s in ('dir /b *.mfl') do mofcomp %%s
mofcomp exwmi.mof
mofcomp -n:root\cimv2\applications\exchange wbemcons.mof
mofcomp -n:root\cimv2\applications\exchange smtpcons.mof
mofcomp exmgmt.mof
-------------------------------------------------------------------------
I found the script here. I'm not sure exactly what was corrupt or how it happened but the script did fix it.
I hope this helps anyone else having this issue.- Marked As Answer bydiver7 Wednesday, November 11, 2009 2:08 PM


