-1

Following the code in this MSDN blog, i have come up with the following code in C#

using Shell32; //Browse to C:\Windows\System32\shell32.dll

private void GetInstalledPrograms()
{            
    Shell shell = new Shell();
    Shell objShell = shell.Application;
    string folderName = @"::{26EE0668-A00A-44D7-9371-BEB064C98683}\8\" +
                        "::{7B81BE6A-CE2B-4676-A29E-EB907A5126C5}";
    var objProgramList = objShell.NameSpace(folderName);
    if (objProgramList != null)
    {
        MessageBox.Show(objProgramList.Items().ToString());
    }
    else
    {
        MessageBox.Show("Null");
    }            
}

For what ever reason, objProgramList is null. The odd thing is, with the following powershell code, I get exactly what I'm looking for! I don't know what I'm doing wrong. To me, both examples of my code are identical...

$Shell = New-Object -ComObject Shell.Application
$folderName = "::{26EE0668-A00A-44D7-9371-BEB064C98683}\8\::{7B81BE6A-CE2B-4676-A29E-     EB907A5126C5}"
$folder = $Shell.NameSpace($folderName)    
if($folder)
{
   $folder.Items()  
}    
Axel
  • 3,331
  • 11
  • 35
  • 58
HiTech
  • 913
  • 1
  • 16
  • 34
  • Your folder names aren't exactly identical. In the powershell there is a big whitespace in the path. Was this a typo? Also, try condensing the C# `folderName` into a single string instead of adding them. – DLeh Apr 01 '14 at 20:43
  • @DLeh The big whitespace is a formating issue with SO and Powershell code. foldername was seperated due to formating issues with SO. MY current code doesn't have a split string. – HiTech Apr 02 '14 at 00:13

2 Answers2

0

Any chance you are using Window 8? According to this answer, creating a shell like that doesn't work in Window 8.

Community
  • 1
  • 1
DLeh
  • 23,806
  • 16
  • 84
  • 128
0

This answer is too late but it might help others with the same problem.

Basically, the problem on your code was the shell command:

string folderName = @"::{26EE0668-A00A-44D7-9371-BEB064C98683}\8\" +
    "::{7B81BE6A-CE2B-4676-A29E-EB907A5126C5}";

It should contain "shell:" in the beginning of the command, it should look like this:

string folderName = @"shell:::{26EE0668-A00A-44D7-9371-BEB064C98683}\8\::{7B81BE6A-CE2B-4676-A29E-EB907A5126C5}"

And to get info about the programs like the Name, Publisher, Installed On and etc, try this code that will enumerate all the available fields:

List<string> arrHeaders = new List<string>();
for (int i = 0; i < short.MaxValue; i++)
{
    string header = list.GetDetailsOf(null, i);
    if (String.IsNullOrEmpty(header))
        break;
    arrHeaders.Add(header);
}

foreach (Shell32.FolderItem2 item in list.Items())
{
    for (int i = 0; i < arrHeaders.Count; i++)
    {
        //I used listbox to show the fields
        listBox1.Items.Add(string.Format("{0}\t{1}: {2}", i, arrHeaders[i], list.GetDetailsOf(item, i)));
    }
}
Carlito
  • 1
  • 1