예제 #1
0
        private void toolStripButtonEdit_Click(object sender, EventArgs e)
        {
            if (this.treeViewAdv1.SelectedNodes.Count > 0)
            {
                StartupManagerNode node = this.treeViewAdv1.SelectedNode.Tag as StartupManagerNode;

                if (!node.IsLeaf)
                {
                    return;
                }

                string strSection = (node.Parent as StartupManagerNode).Section;

                EditRunItem frmEditRunItem = new EditRunItem(node.Item, strSection, node.Path, node.Args);
                if (frmEditRunItem.ShowDialog(this) == DialogResult.OK)
                {
                    LoadStartupFiles();
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Loads startup folder into tree view
        /// </summary>
        private void AddStartupFolder(string strFolder)
        {
            try
            {
                ComponentResourceManager res = new ComponentResourceManager(typeof(StartupManager));

                if (string.IsNullOrEmpty(strFolder) || !Directory.Exists(strFolder))
                {
                    return;
                }

                StartupManagerNode nodeRoot = new StartupManagerNode(strFolder);

                if (Utils.GetSpecialFolderPath(Utils.CSIDL_STARTUP) == strFolder)
                {
                    nodeRoot.Image = this.imageList.Images["Users"];
                }
                else
                {
                    nodeRoot.Image = this.imageList.Images["User"];
                }

                foreach (string strShortcut in Directory.GetFiles(strFolder))
                {
                    string strShortcutName = Path.GetFileName(strShortcut);
                    string strFilePath, strFileArgs;

                    if (Path.GetExtension(strShortcut) == ".lnk")
                    {
                        if (!Utils.ResolveShortcut(strShortcut, out strFilePath, out strFileArgs))
                        {
                            continue;
                        }

                        StartupManagerNode node = new StartupManagerNode();
                        node.Item = strShortcutName;
                        node.Path = strFilePath;
                        node.Args = strFileArgs;

                        Icon ico = Utils.ExtractIcon(strFilePath);
                        if (ico != null)
                        {
                            node.Image = (Image)ico.ToBitmap().Clone();
                        }
                        else
                        {
                            node.Image = (Image)res.GetObject("treeViewAdvApp");
                        }

                        nodeRoot.Nodes.Add(node);
                    }
                }

                if (nodeRoot.Nodes.Count <= 0)
                {
                    return;
                }

                this.treeModel.Nodes.Add(nodeRoot);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
예제 #3
0
        private void toolStripButtonDelete_Click(object sender, EventArgs e)
        {
            if (this.treeViewAdv1.SelectedNodes.Count > 0)
            {
                if (MessageBox.Show(this, Properties.Resources.smRemove, Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    StartupManagerNode node = this.treeViewAdv1.SelectedNode.Tag as StartupManagerNode;

                    bool bFailed = false;

                    if (!node.IsLeaf)
                    {
                        return;
                    }

                    string strSection = (node.Parent as StartupManagerNode).Section;

                    if (Directory.Exists(strSection))
                    {
                        // Startup folder
                        string strPath = Path.Combine(strSection, node.Item);

                        try
                        {
                            if (File.Exists(strPath))
                            {
                                File.Delete(strPath);
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(this, ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            bFailed = true;
                        }
                    }
                    else
                    {
                        // Registry key
                        string      strMainKey = strSection.Substring(0, strSection.IndexOf('\\'));
                        string      strSubKey  = strSection.Substring(strSection.IndexOf('\\') + 1);
                        RegistryKey rk         = Utils.RegOpenKey(strMainKey, strSubKey);

                        try
                        {
                            if (rk != null)
                            {
                                rk.DeleteValue(node.Item);
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(this, ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            bFailed = true;
                        }

                        rk.Close();
                    }

                    if (!bFailed)
                    {
                        MessageBox.Show(this, Properties.Resources.smRemoved, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }

            LoadStartupFiles();
        }
예제 #4
0
        /// <summary>
        /// Loads registry sub key into tree view
        /// </summary>
        private void LoadRegistryAutoRun(RegistryKey regKey)
        {
            ComponentResourceManager res = new ComponentResourceManager(typeof(StartupManager));

            if (regKey == null)
            {
                return;
            }

            if (regKey.ValueCount <= 0)
            {
                return;
            }

            StartupManagerNode nodeRoot = new StartupManagerNode(regKey.Name);

            if (regKey.Name.Contains(Registry.CurrentUser.ToString()))
            {
                nodeRoot.Image = this.imageList.Images["User"];
            }
            else
            {
                nodeRoot.Image = this.imageList.Images["Users"];
            }

            foreach (string strItem in regKey.GetValueNames())
            {
                string strFilePath = regKey.GetValue(strItem) as string;

                if (!string.IsNullOrEmpty(strFilePath))
                {
                    // Get file arguments
                    string strFile = "", strArgs = "";

                    if (Utils.FileExists(strFilePath))
                    {
                        strFile = strFilePath;
                    }
                    else
                    {
                        if (!Utils.ExtractArguments(strFilePath, out strFile, out strArgs))
                        {
                            if (!Utils.ExtractArguments2(strFilePath, out strFile, out strArgs))
                            {
                                // If command line cannot be extracted, set file path to command line
                                strFile = strFilePath;
                            }
                        }
                    }

                    StartupManagerNode node = new StartupManagerNode();

                    node.Item = strItem;
                    node.Path = strFile;
                    node.Args = strArgs;

                    Icon ico = Utils.ExtractIcon(strFile);
                    if (ico != null)
                    {
                        node.Image = (Image)ico.ToBitmap().Clone();
                    }
                    else
                    {
                        node.Image = (Image)res.GetObject("treeViewAdvApp");
                    }

                    nodeRoot.Nodes.Add(node);
                }
            }

            this.treeModel.Nodes.Add(nodeRoot);
        }