示例#1
0
        public static MiResult SetServerName(Microsoft.Management.Infrastructure.Native.InstanceHandle handle, string serverName)
        {
            IntPtr            ptr      = handle.DangerousGetHandle();
            NativeCimInstance instance = CimNativeApi.MarshalledObject.FromPointer <NativeCimInstance>(ptr);

            instance.ServerName = serverName;
            return(MiResult.OK);
        }
示例#2
0
 private static string PropertiesOrSystem(NativeCimInstance instance)
 {
     if (instance.CimClassName.Equals("meta_class", StringComparison.OrdinalIgnoreCase))
     {
         return(instance.SystemProperties);
     }
     return(instance.Properties);
 }
示例#3
0
        public static MiResult GetNamespace(Microsoft.Management.Infrastructure.Native.InstanceHandle instanceHandle, out string str2)
        {
            IntPtr            ptr      = instanceHandle.DangerousGetHandle();
            NativeCimInstance instance = CimNativeApi.MarshalledObject.FromPointer <NativeCimInstance>(ptr);

            str2 = instance.Namespace;
            return(MiResult.OK);
        }
示例#4
0
        public static MiResult GetElementCount(InstanceHandle handle, out int num)
        {
            NativeCimInstance instance = CimNativeApi.MarshalledObject.FromPointer <NativeCimInstance> (handle.DangerousGetHandle());
            var properties             = NativeCimPropertiesHelper.Deserialize(PropertiesOrSystem(instance));

            num = properties.Count;
            return(MiResult.OK);
        }
		public NativeCimInstance InvokeMethod (string namespaceName, string className, string methodName, NativeCimInstance instance, NativeCimInstance inSignature)
		{
			var classObj = new System.Management.ManagementClass(string.Format ("//./{0}/{1}",  namespaceName, className));
			var inObj = classObj.GetMethodParameters (className);
			inObj.Properties["CommandLine"].Value = "notepad.exe";
			var result = classObj.InvokeMethod(methodName, inObj, new System.Management.InvokeMethodOptions());
			var endpoint = CimEnumerator.ToEndointAddress (result, true);
			return CimEnumerationHelper.CreateInstance (endpoint);
		}
示例#6
0
        public static MiResult ClearElementAt(InstanceHandle handle, int _index)
        {
            NativeCimInstance instance = CimNativeApi.MarshalledObject.FromPointer <NativeCimInstance> (handle.DangerousGetHandle());
            var properties             = NativeCimPropertiesHelper.Deserialize(PropertiesOrSystem(instance));

            properties.ElementAt(_index).Value = null;
            instance.Properties = NativeCimPropertiesHelper.Serialize(properties);
            handle.DangerousSetHandle((IntPtr)CimNativeApi.MarshalledObject.Create <NativeCimInstance>(instance));
            return(MiResult.OK);
        }
示例#7
0
        public static MiResult GetElementAt_GetValue(InstanceHandle handle, int _index, out object obj)
        {
            NativeCimInstance instance = CimNativeApi.MarshalledObject.FromPointer <NativeCimInstance> (handle.DangerousGetHandle());

            obj = null;
            if (_index != -1)
            {
                var properties = NativeCimPropertiesHelper.Deserialize(PropertiesOrSystem(instance));
                var element    = properties.ElementAtOrDefault(_index);
                obj = element.Value;
            }
            return(MiResult.OK);
        }
示例#8
0
        public static MiResult AddElement(InstanceHandle handle, string name, object obj, object par, MiFlags miFlags)
        {
            NativeCimInstance   instance   = CimNativeApi.MarshalledObject.FromPointer <NativeCimInstance>(handle.DangerousGetHandle());
            NativeCimProperties properties = NativeCimPropertiesHelper.Deserialize(instance.Properties);

            CimType type = CimConverter.GetCimType(obj.GetType());

            properties.Add(new NativeCimProperty {
                Name = name, Type = type, Origin = "client", IsArray = false, IsLocal = false, Value = obj
            });
            instance.Properties = NativeCimPropertiesHelper.Serialize(properties);
            handle.DangerousSetHandle((IntPtr)CimNativeApi.MarshalledObject.Create <NativeCimInstance>(instance));
            return(MiResult.OK);
        }
示例#9
0
        internal static MiResult NewInstance(ApplicationHandle applicationHandle, string p1, object p2, out InstanceHandle instanceHandle)
        {
			NativeCimInstance instance = new NativeCimInstance();
			instance.CimClassName = p1;
			instance.ClassName = p1;
			instance.Properties = NativeCimPropertiesHelper.Serialize (new NativeCimProperties());
			instance.SystemProperties = NativeCimPropertiesHelper.Serialize (new NativeCimProperties());
			instance.Namespace = "root/cimv2";
			instance.ServerName = "localhost";
			instance.Qualifiers = NativeCimQualifiersHelper.Serialize (new NativeCimQualifiers());
			IntPtr instancePtr = CimNativeApi.MarshalledObject.Create<NativeCimInstance>(instance);
			instanceHandle = new InstanceHandle(instancePtr, false);
			return MiResult.OK;
        }
示例#10
0
        internal static MiResult NewInstance(ApplicationHandle applicationHandle, string p1, object p2, out InstanceHandle instanceHandle)
        {
            NativeCimInstance instance = new NativeCimInstance();

            instance.CimClassName     = p1;
            instance.ClassName        = p1;
            instance.Properties       = NativeCimPropertiesHelper.Serialize(new NativeCimProperties());
            instance.SystemProperties = NativeCimPropertiesHelper.Serialize(new NativeCimProperties());
            instance.Namespace        = "root/cimv2";
            instance.ServerName       = "localhost";
            instance.Qualifiers       = NativeCimQualifiersHelper.Serialize(new NativeCimQualifiers());
            IntPtr instancePtr = CimNativeApi.MarshalledObject.Create <NativeCimInstance>(instance);

            instanceHandle = new InstanceHandle(instancePtr, false);
            return(MiResult.OK);
        }
示例#11
0
        public static MiResult GetClass(Microsoft.Management.Infrastructure.Native.InstanceHandle instanceHandle, out ClassHandle classHandle)
        {
            MiResult          result   = MiResult.OK;
            IntPtr            ptr      = instanceHandle.DangerousGetHandle();
            NativeCimInstance instance = CimNativeApi.MarshalledObject.FromPointer <NativeCimInstance> (ptr);

            classHandle = null;
            if (!string.IsNullOrEmpty(instance.ClassName))
            {
                var options  = CimNativeApi.GetDestinationOptions(new SessionHandle(instance.SessionHandle));
                var classObj = CimNativeApi.QueryClasses(options, instance.Namespace, CimNativeApi.WQLNamespace, "SELECT * FROM Meta_Class WHERE ClassName = '" + instance.ClassName + "'").FirstOrDefault();
                classObj.SessionHandle = instance.SessionHandle;
                IntPtr classPtr = CimNativeApi.MarshalledObject.Create <NativeCimClass>(classObj);
                classHandle = new ClassHandle(classPtr, true);
            }
            return(result);
        }
示例#12
0
        public static MiResult GetElementAt_GetName(InstanceHandle handle, int _index, out string str)
        {
            NativeCimInstance instance = CimNativeApi.MarshalledObject.FromPointer <NativeCimInstance> (handle.DangerousGetHandle());
            var properties             = NativeCimPropertiesHelper.Deserialize(PropertiesOrSystem(instance));
            int i = 0;

            str = null;
            foreach (var element in properties)
            {
                if (i == _index)
                {
                    str = element.Name;
                    break;
                }
                i++;
            }
            return(MiResult.OK);
        }
示例#13
0
        public static MiResult GetElement_GetIndex(InstanceHandle handle, string propertyName, out int num)
        {
            NativeCimInstance instance = CimNativeApi.MarshalledObject.FromPointer <NativeCimInstance> (handle.DangerousGetHandle());
            var properties             = NativeCimPropertiesHelper.Deserialize(PropertiesOrSystem(instance));

            num = -1;
            int i = 0;

            foreach (var element in properties)
            {
                if (element.Name == propertyName)
                {
                    num = i;
                    break;
                }
                i++;
            }
            return(MiResult.OK);
        }
示例#14
0
        public static MiResult GetElementAt_GetType(InstanceHandle handle, int _index, out MiType miType)
        {
            NativeCimInstance instance = CimNativeApi.MarshalledObject.FromPointer <NativeCimInstance> (handle.DangerousGetHandle());
            var properties             = NativeCimPropertiesHelper.Deserialize(PropertiesOrSystem(instance));
            int i = 0;

            miType = MiType.Boolean;
            foreach (var element in properties)
            {
                if (i == _index)
                {
                    Type type = element.Value.GetType();
                    miType = CimConverter.GetCimType(type).ToMiType();
                    break;
                }
                i++;
            }
            return(MiResult.OK);
        }
示例#15
0
		internal static unsafe void GetInstance(SessionHandle sessionHandle, MiOperationFlags operationFlags, OperationOptionsHandle operationOptionsHandle, string namespaceName, InstanceHandle instanceHandle, OperationCallbacks operationCallbacks, out OperationHandle operationHandle)
		{
			IntPtr sessionPtr = sessionHandle.DangerousGetHandle ();
			NativeDestinationOptions options = CimNativeApi.GetDestinationOptions (sessionHandle);
			operationHandle = new OperationHandle(IntPtr.Zero, true);
			operationHandle.SetOperationCallback(IntPtr.Zero.ToPointer ());
			NativeCimInstance obj = new NativeCimInstance();
			obj.Namespace = namespaceName;
			obj.ServerName = "localhost";
			obj.SessionHandle = sessionPtr;
			var properties = new NativeCimProperties();
			//properties.Keys = new string[] { "PSShowComputerName", "Name", "Status", "PSComputerName" };
			//properties.Values = new object[] { true, "test1", "Started", "localhost" };
			obj.Properties = NativeCimPropertiesHelper.Serialize (properties);
			IntPtr instancePtr = (IntPtr)CimNativeApi.MarshalledObject.Create<NativeCimInstance>(obj);
			InstanceHandle resultHandle = new InstanceHandle(instancePtr, true);
			operationCallbacks.InstanceResultCallback.Invoke (new OperationCallbackProcessingContext(operationCallbacks.ManagedOperationContext), operationHandle, resultHandle, false, MiResult.OK, null, null);

			/*
			_MI_OperationCallbacks _MIOperationCallback;
			_MI_OperationCallbacks* _MIOperationCallbacksPointer;
			DangerousHandleAccessor dangerousHandleAccessor = null;
			DangerousHandleAccessor dangerousHandleAccessor1 = null;
			DangerousHandleAccessor dangerousHandleAccessor2 = null;
			operationHandle = null;
			DangerousHandleAccessor dangerousHandleAccessor = new DangerousHandleAccessor(sessionHandle);
			try
			{
				dangerousHandleAccessor = dangerousHandleAccessor;
				DangerousHandleAccessor dangerousHandleAccessor1 = new DangerousHandleAccessor(instanceHandle);
				try
				{
					dangerousHandleAccessor1 = dangerousHandleAccessor1;
					DangerousHandleAccessor dangerousHandleAccessor2 = new DangerousHandleAccessor(operationOptionsHandle);
					try
					{
						dangerousHandleAccessor2 = dangerousHandleAccessor2;
						_MI_OperationOptions* _MIOperationOptionsPointer = (_MI_OperationOptions*)((void*)dangerousHandleAccessor2.DangerousGetHandle());
						&_MIOperationCallback;
						0;
						bool flag = operationCallbacks.SetMiOperationCallbacks(ref _MIOperationCallback);
						IntPtr hGlobalUni = Marshal.StringToHGlobalUni(namespaceName);
						IntPtr intPtr = hGlobalUni;
						try
						{
							_MI_Operation* _MIOperationPointer = (_MI_Operation*)<Module>.Microsoft.Management.Infrastructure.Native.MI_CLI_malloc_core((long)24);
							void* voidPointer = (void*)dangerousHandleAccessor.DangerousGetHandle();
							if (flag)
							{
								_MIOperationCallbacksPointer = &_MIOperationCallback;
							}
							else
							{
								_MIOperationCallbacksPointer = (_MI_OperationCallbacks*)((long)0);
							}
							_MI_OperationCallbacks* _MIOperationCallbacksPointer1 = _MIOperationCallbacksPointer;
							IntPtr intPtr1 = dangerousHandleAccessor1.DangerousGetHandle();
							<Module>.?A0xf16864c4.MI_Session_GetInstance((_MI_Session*)voidPointer, operationFlags, _MIOperationOptionsPointer, (void*)hGlobalUni, (void*)intPtr1, _MIOperationCallbacksPointer1, _MIOperationPointer);
							OperationHandle operationHandle = new OperationHandle((IntPtr)_MIOperationPointer, true);
							operationHandle = operationHandle;
							operationHandle.SetOperationCallback((long)_MIOperationCallback);
						}
						finally
						{
							if (intPtr != IntPtr.Zero)
							{
								Marshal.FreeHGlobal(intPtr);
							}
						}
					}
					dangerousHandleAccessor2.Dispose();
				}
				dangerousHandleAccessor1.Dispose();
			}
			dangerousHandleAccessor.Dispose();
			*/
		}
示例#16
0
 public static NativeCimInstance InvokeMethod(NativeDestinationOptions options, string namespaceName, string className, string methodName, NativeCimInstance instance, NativeCimInstance inSignature)
 {
     return(GetHandler(options).InvokeMethod(namespaceName, className, methodName, instance, inSignature));
 }
示例#17
0
		public NativeCimInstance InvokeMethod (string namespaceName, string className, string methodName, NativeCimInstance instance, NativeCimInstance inSignature)
		{
			return new NativeCimInstance();
		}
示例#18
0
		private static string PropertiesOrSystem (NativeCimInstance instance)
		{
			if (instance.CimClassName.Equals ("meta_class", StringComparison.OrdinalIgnoreCase)) 
			{
				return instance.SystemProperties;
			}
			return instance.Properties;
		}