Exemplo n.º 1
0
 private static void FillShareByManagementObject(ManagementObject share, Share s)
 {
     foreach (PropertyData property in share.Properties)
     {
         switch (property.Name)
         {
             case "AccessMask":
                 s.AccessMask = ResolvePropertyValue(property);
                 break;
             case "MaximumAllowed":
                 s.MaximumAllowed = ResolvePropertyValue(property);
                 break;
             case "InstallDate":
                 s.InstallDate = ResolvePropertyValue(property);
                 break;
             case "Description":
                 s.Description = ResolvePropertyValue(property);
                 break;
             case "Caption":
                 s.Caption = ResolvePropertyValue(property);
                 break;
             case "AllowMaximum":
                 s.AllowMaximum = ResolvePropertyValue(property);
                 break;
             case "Name":
                 s.Name = ResolvePropertyValue(property);
                 break;
             case "Path":
                 s.Path = ResolvePropertyValue(property);
                 break;
             case "Status":
                 s.Status = ResolvePropertyValue(property);
                 break;
             case "Type":
                 s.TypeId = ResolvePropertyValue(property);
                 break;
         }
     }
 }
Exemplo n.º 2
0
        private void LoadShares(string Username, string Password, string Computer)
        {
            List<Share> shares = new List<Share>();
            System.Text.StringBuilder sb = new StringBuilder();
            string qry = "select * from win32_share";
            System.Management.ManagementObjectSearcher searcher;
            System.Management.ObjectQuery query = new System.Management.ObjectQuery(qry);

            if(Username != "" && Password != "" && Computer != "" && !Computer.StartsWith(@"\\localhost")) {
                System.Management.ConnectionOptions oConn = new System.Management.ConnectionOptions();
                oConn.Username = Username;
                oConn.Password = Password;
                if(!Computer.StartsWith(@"\\")) Computer = @"\\" + Computer;
                if(!Computer.ToLower().EndsWith(@"\root\cimv2")) Computer = Computer + @"\root\cimv2";
                System.Management.ManagementScope oMs = new System.Management.ManagementScope(Computer, oConn);

                searcher = new System.Management.ManagementObjectSearcher(oMs, query);
            } else {
                searcher = new System.Management.ManagementObjectSearcher(query);
            }

            foreach(System.Management.ManagementObject share in searcher.Get()) {
                Share s = new Share();
                foreach(System.Management.PropertyData p in share.Properties) {
                    switch(p.Name) {
                        case "AccessMask":
                            if(p.Value != null) s.AccessMask = p.Value.ToString();
                            break;
                        case "MaximumAllowed":
                            if(p.Value != null) s.MaximumAllowed = p.Value.ToString();
                            break;
                        case "InstallDate":
                            if(p.Value != null) s.InstallDate = p.Value.ToString();
                            break;
                        case "Description":
                            if(p.Value != null) s.Description = p.Value.ToString();
                            break;
                        case "Caption":
                            if(p.Value != null) s.Caption = p.Value.ToString();
                            break;
                        case "AllowMaximum":
                            if(p.Value != null) s.AllowMaximum = p.Value.ToString();
                            break;
                        case "Name":
                            if(p.Value != null) s.Name = p.Value.ToString();
                            break;
                        case "Path":
                            if(p.Value != null) s.Path = p.Value.ToString();
                            break;
                        case "Status":
                            if(p.Value != null) s.Status = p.Value.ToString();
                            break;
                        case "Type":
                            if(p.Value != null) s._Type = p.Value.ToString();
                            break;
                        default:
                            break;
                    }
                }
                shares.Add(s);
            }
            this.dataGridView1.DataSource = shares;
        }
Exemplo n.º 3
0
        private void LoadShares(string Username, string Password, string Computer)
        {
            List <Share> shares = new List <Share>();

            System.Text.StringBuilder sb = new StringBuilder();
            string qry = "select * from win32_share";

            System.Management.ManagementObjectSearcher searcher;
            System.Management.ObjectQuery query = new System.Management.ObjectQuery(qry);

            if (Username != "" && Password != "" && Computer != "" && !Computer.StartsWith(@"\\localhost"))
            {
                System.Management.ConnectionOptions oConn = new System.Management.ConnectionOptions();
                oConn.Username = Username;
                oConn.Password = Password;
                if (!Computer.StartsWith(@"\\"))
                {
                    Computer = @"\\" + Computer;
                }
                if (!Computer.ToLower().EndsWith(@"\root\cimv2"))
                {
                    Computer = Computer + @"\root\cimv2";
                }
                System.Management.ManagementScope oMs = new System.Management.ManagementScope(Computer, oConn);

                searcher = new System.Management.ManagementObjectSearcher(oMs, query);
            }
            else
            {
                searcher = new System.Management.ManagementObjectSearcher(query);
            }

            foreach (System.Management.ManagementObject share in searcher.Get())
            {
                Share s = new Share();
                foreach (System.Management.PropertyData p in share.Properties)
                {
                    switch (p.Name)
                    {
                    case "AccessMask":
                        if (p.Value != null)
                        {
                            s.AccessMask = p.Value.ToString();
                        }
                        break;

                    case "MaximumAllowed":
                        if (p.Value != null)
                        {
                            s.MaximumAllowed = p.Value.ToString();
                        }
                        break;

                    case "InstallDate":
                        if (p.Value != null)
                        {
                            s.InstallDate = p.Value.ToString();
                        }
                        break;

                    case "Description":
                        if (p.Value != null)
                        {
                            s.Description = p.Value.ToString();
                        }
                        break;

                    case "Caption":
                        if (p.Value != null)
                        {
                            s.Caption = p.Value.ToString();
                        }
                        break;

                    case "AllowMaximum":
                        if (p.Value != null)
                        {
                            s.AllowMaximum = p.Value.ToString();
                        }
                        break;

                    case "Name":
                        if (p.Value != null)
                        {
                            s.Name = p.Value.ToString();
                        }
                        break;

                    case "Path":
                        if (p.Value != null)
                        {
                            s.Path = p.Value.ToString();
                        }
                        break;

                    case "Status":
                        if (p.Value != null)
                        {
                            s.Status = p.Value.ToString();
                        }
                        break;

                    case "Type":
                        if (p.Value != null)
                        {
                            s._Type = p.Value.ToString();
                        }
                        break;

                    default:
                        break;
                    }
                }
                shares.Add(s);
            }
            this.dataGridView1.DataSource = shares;
        }
Exemplo n.º 4
0
        private static List<Share> TryLoadShares(string username, string password, string computer)
        {
            var shares = new List<Share>();
            ManagementObjectSearcher searcher = CreateSearcher(username, password, computer);

            foreach (ManagementObject share in searcher.Get())
            {
                var s = new Share();
                FillShareByManagementObject(share, s);
                shares.Add(s);
            }
            return shares;
        }