private void SetUIEnable(string serviceName)
 {
     System.Management.ManagementObject     wmi = new System.Management.ManagementObject(string.Format("Win32_Service.Name='{0}'", serviceName));
     System.Management.ManagementBaseObject cm  = wmi.GetMethodParameters("Change");
     cm["DesktopInteract"] = true;
     System.Management.ManagementBaseObject ut = wmi.InvokeMethod("Change", cm, null);
 }
Esempio n. 2
0
        private void OnMPCStarted(System.Management.ManagementObject obj)
        {
            string args = null;

            if (m_mpcAPI == null || !m_mpcAPI.isHooked || (UInt32)obj["ProcessID"] != m_mpcAPI.ProcessID)
            {
                args = obj["CommandLine"].ToString();
                obj.InvokeMethod("Terminate", null);

                Dispatcher.BeginInvoke(new Action(delegate
                {
                    if (m_mpcAPI == null || !m_mpcAPI.isHooked)
                    {
                        mpchcLaunch(null, null);
                    }

                    if (args != null)
                    {
                        string[] argsArray = args.Split('"').Where(x => !String.IsNullOrWhiteSpace(x)).ToArray <string>();

                        foreach (string arg in argsArray)
                        {
                            if (File.Exists(arg) && allowedVideoFiles.Contains(String.Format("*{0}", Path.GetExtension(arg).ToLower())))
                            {
                                m_mpcAPI.AddFileToPlaylist(arg);
                            }
                        }
                    }
                }));
            }
        }
Esempio n. 3
0
        int _execute_method(string methodname, string[] parameters)
        {
            object prd = _wmiservice_instance.InvokeMethod(methodname, parameters);
            int    rs  = int.Parse(prd.ToString());

            return(rs);
        }
Esempio n. 4
0
 protected override void OnAfterInstall(IDictionary savedState)
 {
     try
     {
         base.OnAfterInstall(savedState);
         System.Management.ManagementObject myService = new System.Management.ManagementObject(
             string.Format("Win32_Service.Name='{0}'", this.serviceInstaller1.ServiceName));
         System.Management.ManagementBaseObject changeMethod = myService.GetMethodParameters("Change");
         changeMethod["DesktopInteract"] = true;//允许服务与桌面交互
         System.Management.ManagementBaseObject OutParam = myService.InvokeMethod("Change", changeMethod, null);
     }
     catch (Exception)
     {
     }
 }
Esempio n. 5
0
 private static void StopAppPool(string pPoolName, bool DoRestart)
 {
     try
     {
         System.Management.ManagementScope scope = new System.Management.ManagementScope("root\\MicrosoftIISv2");
         scope.Connect();
         System.Management.ManagementObject appPool = new System.Management.ManagementObject(scope, new System.Management.ManagementPath("IIsApplicationPool.Name='W3SVC/AppPools/" + pPoolName + "'"), null);
         if (appPool != null)
         {
             if (DoRestart)
             {
                 appPool.InvokeMethod("Recycle", null, null);
             }
             else
             {
                 appPool.InvokeMethod("Stop", null, null);
             }
         }
     }
     catch (Exception ee)
     {
         StartupLog($"IIS Shutdown problem : {ee}");
     }
 }
Esempio n. 6
0
        private static void SetInterActWithDeskTop()
        {
            var service = new System.Management.ManagementObject(
                String.Format("WIN32_Service.Name='{0}'", "ServiceCrc"));

            try
            {
                var paramList = new object[11];
                paramList[5] = true;
                service.InvokeMethod("Change", paramList);
            }
            finally
            {
                service.Dispose();
            }
        }
 private void vInitializeRegistryToInteractWithDesktop()
 {
     try
     {
         System.Management.ConnectionOptions coOptions = new System.Management.ConnectionOptions();
         coOptions.Impersonation = System.Management.ImpersonationLevel.Impersonate;
         System.Management.ManagementScope mgmtScope = new System.Management.ManagementScope(@"root\CIMV2", coOptions);
         mgmtScope.Connect();
         System.Management.ManagementObject wmiService;
         wmiService = new System.Management.ManagementObject("Win32_Service.Name='" + mdlConstantes.clsConstantes.WINDOWSSERVICE_SISCOMENSAGEM_NAME + "'");
         System.Management.ManagementBaseObject InParam = wmiService.GetMethodParameters("Change");
         InParam["DesktopInteract"] = true;
         System.Management.ManagementBaseObject OutParam = wmiService.InvokeMethod("Change", InParam, null);
     }
     catch
     {
         // Cant access the registry
     }
 }
Esempio n. 8
0
        /// <summary>
        /// 取消共享指定目录。
        /// </summary>
        /// <param name="ShareName">共享名称。</param>
        public void DeleteShare(string ShareName)
        {
            System.Management.ManagementObject     classInstance = new System.Management.ManagementObject(@"root\CIMV2", "Win32_Share.Name='" + ShareName + @"'", null);
            System.Management.ManagementBaseObject outParams     = classInstance.InvokeMethod("Delete", null, null);
            switch ((uint)outParams.Properties["ReturnValue"].Value)
            {
            case 0:     //Success
                break;

            case 2:     //Access denied
                throw new System.Exception("无权访问");

            case 8:     //Unknown failure
                throw new System.Exception("未知失败");

            case 9:     //Invalid name
                throw new System.Exception("非法的共享名");

            case 10:     //Invalid level
                throw new System.Exception("非法的层次");

            case 21:     //Invalid parameter
                throw new System.Exception("非法的参数");

            case 22:     //Duplicate share
                throw new System.Exception("重复共享");

            case 23:     //Redirected path
                throw new System.Exception("重定向路径");

            case 24:     //Unknown device or directory
                throw new System.Exception("未知的目录");

            case 25:     //Net name not found
                throw new System.Exception("网络名不存在");

            default:
                throw new System.Exception("未知异常信息");
            }
        }
Esempio n. 9
0
        public static void SetNewDefaultPrinter(string newDefaultPrinterName)
        {
            string selectAllQuery = "SELECT * FROM Win32_Printer";

            System.Management.ObjectQuery oq = new System.Management.ObjectQuery(selectAllQuery);

            System.Management.ManagementObjectSearcher   query1           = new System.Management.ManagementObjectSearcher(oq);
            System.Management.ManagementObjectCollection queryCollection1 = query1.Get();
            System.Management.ManagementObject           newDefault       = null;

            foreach (System.Management.ManagementObject mo in queryCollection1)
            {
                System.Management.PropertyDataCollection pdc = mo.Properties;
                if (mo["Name"].ToString().ToUpper().Trim() == newDefaultPrinterName.ToUpper())
                {
                    newDefault = mo;
                    break;
                }
            }

            if (newDefault != null)
            {
                System.Management.ManagementBaseObject outParams = newDefault.InvokeMethod("SetDefaultPrinter", null, null);
                string returnValue = outParams["returnValue"].ToString();
                if (returnValue != "0")
                {
                    throw new ApplicationException(string.Format("Change Printer '{0}' failed. Return Value: {1}", newDefault.ToString(), returnValue));
                }

                var     HWND_BROADCAST   = new IntPtr(0xffff);
                uint    WM_SETTINGCHANGE = 0x001A;
                UIntPtr innerPinvokeResult;
                var     pinvokeResult = SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, UIntPtr.Zero,
                                                           IntPtr.Zero, SendMessageTimeoutFlags.SMTO_NORMAL, 1000, out innerPinvokeResult);
            }
            else
            {
                throw new ApplicationException(string.Format("Change Printer '{0}' failed. Managemengt object not found", newDefaultPrinterName));
            }
        }
        private void SetServiceProperties(Dictionary <SystemServiceProperty, object> serviceProperties, bool restart)
        {
            if (GetStatus() == SystemServiceStatus.NotInstalled)
            {
                return;
            }

            var service = new System.Management.ManagementObject(String.Format("WIN32_Service.Name='{0}'", ServiceName));

            try
            {
                var paramList = new object[11];

                foreach (KeyValuePair <SystemServiceProperty, object> kvp in serviceProperties)
                {
                    SystemServiceProperty systemServiceProperty = kvp.Key;
                    object        servicePropertyValue          = kvp.Value;
                    TypeAttribute typeAttribute = systemServiceProperty.GetEnumAttribute <TypeAttribute>();
                    paramList[(int)systemServiceProperty] = Convert.ChangeType(servicePropertyValue, typeAttribute.Type);
                }

                var output = (int)service.InvokeMethod("Change", paramList);

                if (output != 0)
                {
                    throw new Exception(string.Format("FAILED with code {0}", output));
                }

                if (restart)
                {
                    Stop();
                    Start();
                }
            }
            finally
            {
                service.Dispose();
            }
        }
Esempio n. 11
0
 int _execute_method(string methodname, string[] parameters)
 {
     return((int)_win_logicaldisk.InvokeMethod(methodname, parameters));
 }
Esempio n. 12
0
        //PHUOCNT TODO: Chưa sử dụng
        public bool SetPrinterToDefault(string printer)
        {
            //path we need for WMI
            string queryPath = "win32_printer.DeviceId='" + printer + "'";
            try
            {
                //ManagementObject for doing the retrieval
                System.Management.ManagementObject managementObj = new System.Management.ManagementObject(queryPath);
                //ManagementBaseObject which will hold the results of InvokeMethod
                System.Management.ManagementBaseObject obj = managementObj.InvokeMethod("SetDefaultPrinter", null, null);
                //if we're null the something went wrong
                if (obj == null)
                    throw new Exception("Không cho phép chọn máy in mặc định.");
                //now get the return value and make our decision based on that
                int result = (int)obj.Properties["ReturnValue"].Value;

                if (result == 0)
                    return true;
                else
                    return false;
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);
                return false;
            }
        }
Esempio n. 13
0
 int _execute_method(string methodname, string[] parameters)
 {
     return((int)_win_process.InvokeMethod(methodname, parameters));
 }
Esempio n. 14
0
 int _execute_method(string methodname, string[] parameters)
 {
     return((int)_cim_file.InvokeMethod(methodname, parameters));
 }
Esempio n. 15
0
        /// <summary>
        /// 사용자가 실행할 경우 - 서비스를 인스톨한다.
        /// 서비스로 실행될 경우 서비스 수행한다.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            if (Environment.UserInteractive)//install service to system
            {
                installService(true);
                Thread.Sleep(1000);
                installService(false);
            }
            else
            {
                Run(new SystemStorage()); //run service
            }
            void installService(bool install)
            {
                if (install)
                {
                    startService(true);
                }

                var p = new Process();

                p.StartInfo.FileName               = @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe";
                p.StartInfo.Arguments              = $"{(install ? "" : "/u")} {typeof(SystemStorage).Assembly.Location}";
                p.StartInfo.UseShellExecute        = false;
                p.StartInfo.RedirectStandardOutput = true;

                p.Start();
                var msg = p.StandardOutput.ReadToEnd();

                log(msg);
                p.WaitForExit();

                if (!install)
                {
                    setInteract();
                    startService(false);
                }

                void setInteract()
                {
                    var service = new System.Management.ManagementObject($"WIN32_Service.Name='SystemStorage'");

                    try
                    {
                        var paramList = new object[11];
                        paramList[5] = true;
                        service.InvokeMethod("Change", paramList);
                    }
                    finally { service.Dispose(); }
                }
            }//install()

            void startService(bool start)
            {
                //NtDll.AdjustPrivilege();

                var p = new Process();

                p.StartInfo.FileName               = @"C:\Windows\System32\net.exe";
                p.StartInfo.Arguments              = $"{(start ? "start" : "stop")} SystemStorage";
                p.StartInfo.UseShellExecute        = false;
                p.StartInfo.RedirectStandardOutput = true;

                p.Start();
                var msg = p.StandardOutput.ReadToEnd();

                log(msg);
                p.WaitForExit();
            } //stopService()
        }     //Main()
Esempio n. 16
0
 int _execute_method(string methodname, string[] parameters)
 {
     return((int)_win_diskdrive.InvokeMethod(methodname, parameters));
 }