示例#1
0
文件: Main.cs 项目: mamcer/soulstone
        private void bwDomains_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            CompEnum ce = NSearcher.GetDomainNames();

            cmbDomains.Invoke(new MethodInvoker(delegate() { cmbDomains.Items.Clear(); }));
            foreach (CompEnum.NetworkComputers nc in ce)
            {
                cmbDomains.Invoke(new MethodInvoker(delegate() { cmbDomains.Items.Add(nc.Name); }));
            }
            lnkConfiguration.Invoke(new MethodInvoker(delegate() { lnkConfiguration.Enabled = true; }));
        }
示例#2
0
        private void bwNetworkExceptions_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            CompEnum ce = NetworkSearcher.Instance.GetComputersOnDomain(ConfigInfo.NetworkName);

            chklbNetworkExceptions.Invoke(new MethodInvoker(delegate() { chklbNetworkExceptions.Items.Clear(); }));
            foreach (CompEnum.NetworkComputers nc in ce)
            {
                chklbNetworkExceptions.Invoke(new MethodInvoker(delegate() { chklbNetworkExceptions.Items.Add(nc.Name); }));
                _hostCache.Add(nc.Name);
            }
        }
示例#3
0
文件: Main.cs 项目: mamcer/soulstone
        private void bwComputers_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            string hostName;

            _totalFileFound = 0;
            try
            {
                //Computers on Domain
                CompEnum computers = NSearcher.GetComputersOnDomain(_selectedNetwork);
                _totalTime = DateTime.Now;
                int      currentComputer = 1;
                DateTime hostScanTime;
                int      totalComputerCount = computers.Length;
                if (_configurationInfo.SelectedHostList != null && _configurationInfo.SelectedHostList.Count > 0)
                {
                    totalComputerCount = _configurationInfo.SelectedHostList.Count;
                }
                foreach (CompEnum.NetworkComputers nc in computers)
                {
                    hostName     = nc.Name;
                    hostScanTime = DateTime.Now;
                    if (_configurationInfo.SelectedHostList == null || _configurationInfo.SelectedHostList.Count == 0 || _configurationInfo.SelectedHostList.Contains(hostName))
                    {
                        if (!_configurationInfo.ScanOnlyNewHosts || (_configurationInfo.ScanOnlyNewHosts && !DBLayer.HostExists(hostName)))
                        {
                            lblHostProgress.Invoke(new MethodInvoker(delegate() { lblHostProgress.Text = string.Format("{0} of {1}", currentComputer++, totalComputerCount); }));
                            lbConsole.Invoke(new MethodInvoker(delegate() { lbConsole.Items.Add(string.Format("{0} - {1} scan started", hostScanTime.ToShortTimeString(), hostName)); }));
                            txtCurrentHost.Invoke(new MethodInvoker(delegate(){ txtCurrentHost.Text = hostName; }));
                            DBLayer.CreateHost(hostName);
                            string sharePath;
                            //Shares for computer
                            foreach (Share s in NSearcher.GetSharesForComputer(hostName))
                            {
                                if (s.ShareType == ShareType.Device || s.ShareType == ShareType.Disk)
                                {
                                    sharePath = s.Root.FullName;
                                    ScanFolder(sharePath, "   ", hostName, sharePath, 1);
                                }
                            }
                            TimeSpan hostScanSpan = DateTime.Now.Subtract(hostScanTime);
                            lbConsole.Invoke(new MethodInvoker(delegate() { lbConsole.Items.Add(string.Format("{0} - {1} scan finished, took {2} minutes {3} seconds {4} milliseconds", DateTime.Now.ToShortTimeString(), hostName, hostScanSpan.Minutes, hostScanSpan.Seconds, hostScanSpan.Milliseconds)); }));
                        }
                    }
                }
                TimeSpan totalTimeSpan = DateTime.Now.Subtract(_totalTime);
                lbConsole.Invoke(new MethodInvoker(delegate() { lbConsole.Items.Add(string.Format("Total: {0} files, took {1} minutes, {2} seconds, {3} milliseconds", _totalFileFound, totalTimeSpan.Minutes, totalTimeSpan.Seconds, totalTimeSpan.Milliseconds)); }));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.InnerException + ex.StackTrace);
            }
            gbSearch.Invoke(new MethodInvoker(delegate() { gbSearch.Enabled = true; }));
            lbConsole.Invoke(new MethodInvoker(delegate() { lbConsole.Items.Add(string.Format("Scan finished")); }));
        }
示例#4
0
        private void bwComputers_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            gbSearch.Enabled = false;
            lbConsole.Items.Clear();
            string hostName;

            _totalFileFound = 0;
            //CompEnum ce = NSearcher.GetComputersOnDomain(cmbDomains.SelectedItem.ToString());
            try
            {
                CompEnum computers       = NSearcher.GetComputersOnDomain(cmbDomains.SelectedItem.ToString());
                int      currentComputer = 1;
                foreach (CompEnum.NetworkComputers nc in computers)
                {
                    lblHostProgress.Text = string.Format("{0} of {1}", currentComputer++, computers.Length);
                    hostName             = nc.Name;
                    lbConsole.Invoke(new MethodInvoker(delegate() { lbConsole.Items.Add(hostName); }));
                    txtCurrentHost.Text = hostName;
                    DBLayer.CreateOrUpdateHost(hostName);
                    string sharePath;
                    foreach (Share s in NSearcher.GetSharesForComputer(hostName))
                    {
                        if (s.ShareType == ShareType.Device || s.ShareType == ShareType.Disk)
                        {
                            sharePath = s.Root.FullName;
                            DBLayer.CreateOrUpdateHostShare(hostName, sharePath);
                            ScanFolder(sharePath, "   ", hostName, sharePath);
                        }
                    }
                }
                lbConsole.Invoke(new MethodInvoker(delegate() { lbConsole.Items.Add(string.Format("Total:{0}", _totalFileFound)); }));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            gbSearch.Enabled = true;
        }
示例#5
0
			internal NetworkComputers(CompEnum.SERVER_INFO_101 info)
			{
				_computerinfo = info;
			}
示例#6
0
        private void GoDownTheDrain(TreeNode anyNode)
        {
            CompEnum cEnum;

            Cursor.Current = Cursors.WaitCursor;
            string theTag = anyNode.Tag.ToString().PadRight(3).Substring(0, 3);

            try
            {
                switch (theTag)
                {
                case TAG_ROOTNODE:
                    SetPleaseWait(anyNode);
                    cEnum = new CompEnum(CompEnum.ServerType.SV_TYPE_DOMAIN_ENUM, null);
                    ClearPleaseWait(anyNode);
                    treeSourceFiles.SelectedNode = anyNode;
                    for (int i = 0; i < cEnum.Length; i++)
                    {
                        NodeInsert(TAG_DOMAIN, cEnum[i].Name, ICON_NETWORK);
                    }
                    treeSourceFiles.SelectedNode = anyNode;
                    break;

                case TAG_DOMAIN:
                    // Only look for machines that have a SQL server running
                    SetPleaseWait(anyNode);
                    cEnum = new CompEnum((uint)CompEnum.ServerType.SV_TYPE_SQLSERVER,
                                         anyNode.Tag.ToString().Substring(3));
                    ClearPleaseWait(anyNode);
                    treeSourceFiles.SelectedNode = anyNode;
                    for (int i = 0; i < cEnum.Length; i++)
                    {
                        NodeInsert(TAG_COMPUTER, cEnum[i].Name, ICON_COMPUTER);
                    }
                    treeSourceFiles.SelectedNode = anyNode.Parent;
                    break;

                case TAG_SERVER:
                case TAG_COMPUTER:
                    SqlConnection con = null;
                    try
                    {
                        SqlConnectionStringBuilder bldr = new SqlConnectionStringBuilder();
                        string computer = anyNode.Tag.ToString().Substring(3);
                        if (computer == SystemInformation.ComputerName)
                        {
                            computer = "(local)";                                     // A bit faster, presumably.
                        }
                        bldr.DataSource     = computer + @"\SILFW";
                        bldr.InitialCatalog = "master";
                        bldr.Password       = "******";
                        bldr.UserID         = "sa";
                        //bldr.IntegratedSecurity = false;
                        //bldr.UserInstance = true;
                        string conStr = bldr.ToString();
                        con = new SqlConnection(conStr);
                        con.Open();
                        using (SqlCommand cmd = con.CreateCommand())
                        {
                            cmd.CommandText = "exec master..sp_GetFWDBs";
                            //cmd.CommandType = CommandType.StoredProcedure; // It is, but that doesn't work
                            cmd.CommandType    = CommandType.Text;                       // Plain text works.
                            cmd.CommandTimeout = 10;                                     // Default is 30, but that makes it take forever.
                            using (SqlDataReader reader = cmd.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    string dbName = reader.GetString(0);
                                    NodeInsert(TAG_SQL + @"^" + bldr.DataSource + "^", dbName, ICON_FW);
                                }
                            }
                        }
                    }
                    catch
                    {
                        // Eat exceptions.
                    }
                    finally
                    {
                        if (con != null)
                        {
                            con.Close();
                        }
                    }
                    break;

                case TAG_SQL:
                    break;

                case TAG_DRIVE:
                case TAG_ADMIN:
                case TAG_SHARE:
                case TAG_DIRECTORY:
                    if (showDirs)
                    {
                        string fullPath = GetFullPath(anyNode);
                        SetPleaseWait(anyNode);
                        try
                        {
                            DirectoryInfo   dirInfo = new DirectoryInfo(fullPath);
                            DirectoryInfo[] Flds    = dirInfo.GetDirectories();
                            for (int i = 0; i < Flds.Length; i++)
                            {
                                NodeInsert(TAG_DIRECTORY, Flds[i].Name, ICON_CLOSEDFOLDER);
                            }
                            if (showFiles)
                            {
                                FileInfo[] Fils = dirInfo.GetFiles();
                                for (int i = 0; i < Fils.Length; i++)
                                {
                                    NodeInsert(TAG_FILE, Fils[i].Name, ICON_FILE);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Sorry, could not search for directories in this share. The " +
                                            "reason for the error was:\n\n" + ex.Message, "Can't go further",
                                            System.Windows.Forms.MessageBoxButtons.OK,
                                            System.Windows.Forms.MessageBoxIcon.Information);
                        }
                        ClearPleaseWait(anyNode);
                    }
                    break;
                }
                if (anyNode != RootNode)
                {
                    anyNode.Collapse();
                }
                else
                {
                    anyNode.Expand();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("I'm sorry, it's impossible to go further down. The error that was " +
                                "returned, is:\n\n" + ex.Message, "Can't go further down",
                                System.Windows.Forms.MessageBoxButtons.OK,
                                System.Windows.Forms.MessageBoxIcon.Warning);
            }
            Cursor.Current = Cursors.Default;
        }
示例#7
0
		private void GoDownTheDrain(TreeNode anyNode)
		{
			CompEnum cEnum;

			Cursor.Current = Cursors.WaitCursor;
			string theTag = anyNode.Tag.ToString().PadRight(3).Substring(0,3);
			try
			{
				switch (theTag)
				{
					case TAG_ROOTNODE:
						SetPleaseWait(anyNode);
						cEnum = new CompEnum(CompEnum.ServerType.SV_TYPE_DOMAIN_ENUM,null);
						ClearPleaseWait(anyNode);
						treeSourceFiles.SelectedNode = anyNode;
						for (int i=0;i<cEnum.Length;i++)
							NodeInsert(TAG_DOMAIN,cEnum[i].Name,ICON_NETWORK);
						treeSourceFiles.SelectedNode = anyNode;
						break;
					case TAG_DOMAIN:
						// Only look for machines that have a SQL server running
						SetPleaseWait(anyNode);
						cEnum = new CompEnum((uint)CompEnum.ServerType.SV_TYPE_SQLSERVER,
							anyNode.Tag.ToString().Substring(3));
						ClearPleaseWait(anyNode);
						treeSourceFiles.SelectedNode = anyNode;
						for (int i=0;i<cEnum.Length;i++)
							NodeInsert(TAG_COMPUTER,cEnum[i].Name,ICON_COMPUTER);
						treeSourceFiles.SelectedNode = anyNode.Parent;
						break;
					case TAG_SERVER:
					case TAG_COMPUTER:
						SqlConnection con = null;
						try
						{
							SqlConnectionStringBuilder bldr = new SqlConnectionStringBuilder();
							string computer = anyNode.Tag.ToString().Substring(3);
							if (computer == SystemInformation.ComputerName)
								computer = "(local)"; // A bit faster, presumably.
							bldr.DataSource = computer + @"\SILFW";
							bldr.InitialCatalog = "master";
							bldr.Password = "******";
							bldr.UserID = "sa";
							//bldr.IntegratedSecurity = false;
							//bldr.UserInstance = true;
							string conStr = bldr.ToString();
							con = new SqlConnection(conStr);
							con.Open();
							using (SqlCommand cmd = con.CreateCommand())
							{
								cmd.CommandText = "exec master..sp_GetFWDBs";
								//cmd.CommandType = CommandType.StoredProcedure; // It is, but that doesn't work
								cmd.CommandType = CommandType.Text; // Plain text works.
								cmd.CommandTimeout = 10; // Default is 30, but that makes it take forever.
								using (SqlDataReader reader = cmd.ExecuteReader())
								{
									while (reader.Read())
									{
										string dbName = reader.GetString(0);
										NodeInsert(TAG_SQL + @"^" + bldr.DataSource + "^", dbName, ICON_FW);
									}
								}
							}
						}
						catch
						{
							// Eat exceptions.
						}
						finally
						{
							if (con != null)
								con.Close();
						}
						break;
					case TAG_SQL:
						break;
					case TAG_DRIVE:
					case TAG_ADMIN:
					case TAG_SHARE:
					case TAG_DIRECTORY:
						if (showDirs)
						{
							string fullPath = GetFullPath(anyNode);
							SetPleaseWait(anyNode);
							try
							{
								DirectoryInfo dirInfo = new DirectoryInfo(fullPath);
								DirectoryInfo[] Flds = dirInfo.GetDirectories();
								for (int i=0; i < Flds.Length; i++)
									NodeInsert(TAG_DIRECTORY,Flds[i].Name,ICON_CLOSEDFOLDER);
								if (showFiles)
								{
									FileInfo[] Fils = dirInfo.GetFiles();
									for (int i=0; i < Fils.Length; i++)
										NodeInsert(TAG_FILE,Fils[i].Name,ICON_FILE);
								}
							}
							catch (Exception ex)
							{
								MessageBox.Show("Sorry, could not search for directories in this share. The " +
									"reason for the error was:\n\n" + ex.Message, "Can't go further",
									System.Windows.Forms.MessageBoxButtons.OK,
									System.Windows.Forms.MessageBoxIcon.Information);
							}
							ClearPleaseWait(anyNode);
						}
						break;
				}
				if (anyNode != RootNode)
					anyNode.Collapse();
				else
					anyNode.Expand();
			}
			catch (Exception ex)
			{
				MessageBox.Show("I'm sorry, it's impossible to go further down. The error that was " +
					"returned, is:\n\n" + ex.Message,"Can't go further down",
					System.Windows.Forms.MessageBoxButtons.OK,
					System.Windows.Forms.MessageBoxIcon.Warning);
			}
			Cursor.Current = Cursors.Default;
		}