6

How to remove the Start menu shortcut using C #

 2 years ago
source link: https://www.codesd.com/item/how-to-remove-the-start-menu-shortcut-using-c.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to remove the Start menu shortcut using C #

advertisements

How can I remove a shortcut folder from Startmenu in Windows using C#, I know how to do that using this code:

    private void RemoveShortCutFolder(string folder)
    {
        folder = folder.Replace("\"  ", "");
        folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), folder);
        try
        {
            if (System.IO.Directory.Exists(folder))
            {
                System.IO.Directory.Delete(folder, true);
            }
            else
            {
            }
        }
        catch (Exception)
        {
        }
    }

But the problem that I need to remove one shortcut folder in ALL USERS folder, not the current logged user. Environment.SpecialFolder.StartMenu gives me the current user not all users folder.

Any idea,

Thanks,


If you don't mind a little Win32, you can use SHGetSpecialFolderPath.

[DllImport("shell32.dll")]
static extern bool SHGetSpecialFolderPath(IntPtr hwndOwner, StringBuilder lpszPath, CSIDL nFolder, bool fCreate);

enum CSIDL
{
  COMMON_STARTMENU = 0x0016,
  COMMON_PROGRAMS = 0x0017
}

static void Main(string[] args)
{
  StringBuilder allUsersStartMenu = new StringBuilder(255);
  SHGetSpecialFolderPath(IntPtr.Zero, allUsersStartMenu, CSIDL.COMMON_PROGRAMS, false);
  Console.WriteLine("All Users' Start Menu is in {0}", allUsersStartMenu.ToString());
}

Tags windows

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK