Beispiel #1
0
        void listviewStartup_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            try
            {
                if (e.IsSelected)
                {
                    // Get command and file path stored in listview and make available panel wide.
                    string command = listviewStartup.Items[e.ItemIndex].SubItems[(int)ListCol.Command].Text;
                    string filePath = listviewStartup.Items[e.ItemIndex].SubItems[(int)ListCol.Path].Text;

                    // Display the file information.
                    if (filePath.Contains("cmd.exe"))
                    {
                        // Since this is a command window, we will not be able to resolve any properties.
                        labelCompany.Text = "";
                        labelProductName.Text = "";
                        labelDescription.Text = "";
                        labelFileVersion.Text = "";
                        labelCommand.Text = command;

                        // Only display arguments for shortcuts.
                        labelArguments.Visible = false;
                        labelArgumentsDesc.Visible = false;
                        labelArguments.Text = "";
                    }
                    else if (Path.GetExtension(filePath) == ".lnk")
                    {
                        // Resolve the shortcut.
                        ShortcutClass sc = new ShortcutClass(filePath);

                        // Get the file version information.
                        FileVersionInfo selectedFileVersionInfo =
                            FileVersionInfo.GetVersionInfo(sc.Path);

                        // Display the resolved shortcut properties.
                        labelCompany.Text = selectedFileVersionInfo.CompanyName;
                        labelProductName.Text = selectedFileVersionInfo.ProductName;
                        labelDescription.Text = selectedFileVersionInfo.FileDescription;
                        labelFileVersion.Text = selectedFileVersionInfo.FileVersion;
                        labelCommand.Text = sc.Path;

                        // Display arguments for shortcuts, but only if present.
                        if (string.IsNullOrEmpty(sc.Arguments))
                        {
                            labelArgumentsDesc.Visible = false;
                            labelArguments.Visible = false;
                        }
                        else
                        {
                            labelArguments.Visible = true;
                            labelArgumentsDesc.Visible = true;
                            labelArguments.Text = sc.Arguments;
                        }
                    }
                    else
                    {
                        // Get the file version information.
                        FileVersionInfo selectedFileVersionInfo =
                            FileVersionInfo.GetVersionInfo(filePath);

                        // Display the file properties.
                        labelCompany.Text = selectedFileVersionInfo.CompanyName;
                        labelProductName.Text = selectedFileVersionInfo.ProductName;
                        labelDescription.Text = selectedFileVersionInfo.FileDescription;
                        labelFileVersion.Text = selectedFileVersionInfo.FileVersion;
                        labelCommand.Text = command;

                        // Only display arguments for shortcuts.
                        labelArguments.Visible = false;
                        labelArgumentsDesc.Visible = false;
                        labelArguments.Text = "";
                    }
                }
            }
            catch (Exception) { }
        }
Beispiel #2
0
        void DisplayStartupShortcuts(string type)
        {
            bool disabled;
            string command;
            string filePath;
            string folder;

            if (type == StartupUser)
            {
                // Current users startup folder.
                folder = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
            }
            else
            {
                // All users startup folder.
                folder = Environment.ExpandEnvironmentVariables("%AllUsersProfile%") + @"\Start Menu\Programs\Startup";
            }
            try
            {

                foreach (string shortcut in Directory.GetFiles(folder, "*.*"))
                {
                    // Only process shortcuts or executible files.
                    if (Path.GetExtension(shortcut) == ".lnk" || Path.GetExtension(shortcut) == ".exe")
                    {
                        // Reset disabled flag.
                        disabled = false;

                        // Save complete command.
                        command = shortcut;

                        //if (Path.GetExtension(shortcut) == ".lnk")
                        //  {
                        //       ShortcutClass scut = new ShortcutClass(shortcut);
                        //       command = scut.Path;
                        //   }

                        // Save file path.
                        filePath = ReturnFilePath(command);

                        // Resolve the shortcut.

                        ShortcutClass sc = new ShortcutClass(filePath);

                        // Attempt to get application image (icon).
                        if (sc.Icon != null)
                        {
                            // First try getting icon from shortcut.
                            StartupImageList.Images.Add(sc.Icon);
                        }
                        else if (native.GetIcon(sc.Path) != null)
                        {
                            // Then try getting icon from the resolved path.
                            StartupImageList.Images.Add(native.GetIcon(sc.Path));
                        }
                        else
                        {
                            // If both methods fail, display a blank icon.
                            StartupImageList.Images.Add((System.Drawing.Image)ResourceManager.GetObject("Blank"));
                        }

                        // Add entry description to listview.
                        listviewStartup.Items.Add(Path.GetFileNameWithoutExtension(shortcut), i);

                        // Add file name (without path) to listview.
                        listviewStartup.Items[i].SubItems.Add(Path.GetFileName(filePath));

                        // Add type information to listview.
                        if (type == StartupUser)
                        {
                            listviewStartup.Items[i].SubItems.Add(StartupUser);
                        }
                        else
                        {
                            listviewStartup.Items[i].SubItems.Add(StartupAllUsers);
                        }

                        // Add status information.
                        if (disabled)
                        {
                            listviewStartup.Items[i].SubItems.Add(rm.GetString("startupprogs_disabled"));
                        }
                        else
                        {
                            listviewStartup.Items[i].SubItems.Add(rm.GetString("startupprogs_enabled"));
                        }

                        // Add command.
                        listviewStartup.Items[i].SubItems.Add(command);

                        // Add file path.
                        listviewStartup.Items[i].SubItems.Add(filePath);

                        i++;

                    }

                }
            }
            catch (Exception e)
            {
                string exp = e.Message;
                //Directory may not exist
            }
        }