Page 2 of 3 FirstFirst 123 LastLast
Results 41 to 80 of 102

Thread: Example of how to get a list of installed programs (like Add and Remove Programs)

  1. #41

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    Probably this issue that I mentioned in the original post:
    64 bit
    The code seems to work perfectly fine on a 64 bit system if the code is built to target x64 (or AnyCpu) but if you set the code to target x86 then Windows hides/redirects one of the registry keys from the process and that key contains some of the installed programs - the end result being that not all programs may be displayed in this scenario. No such issues on 32 bit operating systems of course.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  2. #42
    Junior Member
    Join Date
    Aug 2005
    Posts
    16

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    I had considered that, but wouldn't your test app fail too then?

  3. #43

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    No because that targets AnyCpu
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  4. #44
    Junior Member
    Join Date
    Aug 2005
    Posts
    16

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    Oddly enough, I can't change the target platform. In your test app, I can't change it from "Active (Any CPU)" and in my app I can't change it from "Active (x86)"...

  5. #45

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    You're changing it in the wrong place then. Double click on the "My Project" node in the Solution Explorer tree on the right hand side, then go to the Compile tab on the left in the new window that opens, then depending on which version of VS you are using you may have to click the Advanced Compile Options button from there.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  6. #46
    Junior Member
    Join Date
    Aug 2005
    Posts
    16

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    Doesn't matter really, since the project I want to use this for can't use x64 as a target anyway...

    Anyway, you were thinking about including getting the application's icons as well. Is that still on the table?

  7. #47
    Junior Member
    Join Date
    Aug 2005
    Posts
    16

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    Quote Originally Posted by chris128 View Post
    You're changing it in the wrong place then. Double click on the "My Project" node in the Solution Explorer tree on the right hand side, then go to the Compile tab on the left in the new window that opens, then depending on which version of VS you are using you may have to click the Advanced Compile Options button from there.
    Yes I did that and it didn't work. What did work eventually, was going to Tools -> Options -> Projects and Solutions -> General, then tick "Always show solution". Then in the Solution Explorer, right click the solutions (which will now show) and click "Configuration Manager". There I first have to add a solution platform, then I can choose it as the active platform.

  8. #48

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    Quote Originally Posted by ClarkVent View Post
    Anyway, you were thinking about including getting the application's icons as well. Is that still on the table?
    I'm afraid not, but there's nothing to stop someone else adding that functionality. It would be relatively easy if you only ever want to run it on the local machine rather than running it remotely against other computers on the network.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  9. #49
    New Member
    Join Date
    Apr 2011
    Posts
    2

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    Well, I tested this. but it doesnt work with windows vista and windows 7.
    Am I Right?

  10. #50

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    Quote Originally Posted by etorreshn View Post
    Well, I tested this. but it doesnt work with windows vista and windows 7.
    Am I Right?
    No you are not right. Care to explain what exactly "doesnt work" ?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  11. #51
    Member
    Join Date
    Feb 2010
    Posts
    36

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    Chris,

    I'm getting a registry access denied error when I run this under certain users. I'm certain it's a permissions issue with those particular users, but do you have a good suggestion for where in your installedprograms class I can output what area of the registry it's being denied access to? i.e. where can I place a debug.writeline method in your class to output the current key.

    Thanks man, I can elaborate more on this if needed, just pressed for time.

    -Drew

  12. #52

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    The code attempts to read from the following registry locations (and subkeys under each one):
    HKEY_LOCAL_MACHINE\Software\Classes\Installer\Products
    HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall
    HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall
    HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Installer\UserData
    but then it also looks at each of the user subkeys under HKEY_USERS so that may be where you are getting the permissions error if its trying to read data from other user's registry keys that the current user does not have access to (though I've never had any such issues and no one else has reported that).
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  13. #53
    Member
    Join Date
    Feb 2010
    Posts
    36

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    Thanks for the reply & info,

    I believe I may have figured out what the problem is... This is just a hunch but it makes some sense.

    My exe is running on a login script when a user logs into a computer, it seems that when a user is already logged in to a computer (and the account is locked, i.e. the session is being switched without logging that user off) another user logs in and it attempts to query some reg key that is locked down from the other logged on user's session.

    I've been able to reproduce this, otherwise it works great...

  14. #54

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    Yeah that would explain why I have never come across this issue. Just change the code in my class so that it doesn't try to get the programs installed for other users as well then. If you look at the public function GetInstalledPrograms, you should see near the end of it there is a part where it loops through each of the keys in the HKEY_USERS key, just change that so that it only uses the HKEY_CURRENT_USER key instead (so get rid of the loop completely).
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  15. #55
    Member
    Join Date
    Feb 2010
    Posts
    36

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    Is there a particular spot in the code I could just place a try catch statement to catch that issue rather than removing the ability to search for other user programs?

    Thanks.

    -Drew

  16. #56

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    Quote Originally Posted by Drewster727 View Post
    Is there a particular spot in the code I could just place a try catch statement to catch that issue rather than removing the ability to search for other user programs?

    Thanks.

    -Drew
    Yeah you could just wrap each iteration of the loop through individual user's programs because if it fails for one item in that user's registry hive then it will fail for all of them so it doesn't make any sense to add the Try/Catch any further into the code.

    Just try replacing this:

    vb.net Code:
    1. Private Shared Function InternalGetInstalledPrograms(ByVal IncludeUpdates As Boolean, ByVal HklmPath As RegistryKey, ByVal HkuPath As RegistryKey) As List(Of InstalledProgram)
    2.         Dim ProgramList As New List(Of InstalledProgram)
    3.  
    4.         Dim ClassesKey As RegistryKey = HklmPath.OpenSubKey("Software\Classes\Installer\Products")
    5.  
    6.         '---Wow64 Uninstall key
    7.         Dim Wow64UninstallKey As RegistryKey = HklmPath.OpenSubKey("Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall")
    8.         ProgramList = GetUninstallKeyPrograms(Wow64UninstallKey, ClassesKey, ProgramList, IncludeUpdates)
    9.  
    10.         '---Standard Uninstall key
    11.         Dim StdUninstallKey As RegistryKey = HklmPath.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall")
    12.         ProgramList = GetUninstallKeyPrograms(StdUninstallKey, ClassesKey, ProgramList, IncludeUpdates)
    13.  
    14.         For Each UserSid As String In HkuPath.GetSubKeyNames
    15.             '---HKU Uninstall key
    16.             Dim CuUnInstallKey As RegistryKey = HkuPath.OpenSubKey(UserSid & "\Software\Microsoft\Windows\CurrentVersion\Uninstall")
    17.             ProgramList = GetUninstallKeyPrograms(CuUnInstallKey, ClassesKey, ProgramList, IncludeUpdates)
    18.             '---HKU Installer key
    19.             Dim CuInstallerKey As RegistryKey = HkuPath.OpenSubKey(UserSid & "\Software\Microsoft\Installer\Products")
    20.             ProgramList = GetUserInstallerKeyPrograms(CuInstallerKey, HklmPath, ProgramList)
    21.         Next
    22.  
    23.         'Close the registry keys
    24.         Try
    25.             HklmPath.Close()
    26.             HkuPath.Close()
    27.         Catch ex As Exception
    28.             Debug.WriteLine("Error closing registry key - " & ex.Message)
    29.         End Try
    30.  
    31.         'Sort the list alphabetically and return it to the caller
    32.         ProgramList.Sort()
    33.         Return ProgramList
    34.     End Function

    with this:

    vb.net Code:
    1. Private Shared Function InternalGetInstalledPrograms(ByVal IncludeUpdates As Boolean, ByVal HklmPath As RegistryKey, ByVal HkuPath As RegistryKey) As List(Of InstalledProgram)
    2.         Dim ProgramList As New List(Of InstalledProgram)
    3.  
    4.         Dim ClassesKey As RegistryKey = HklmPath.OpenSubKey("Software\Classes\Installer\Products")
    5.  
    6.         '---Wow64 Uninstall key
    7.         Dim Wow64UninstallKey As RegistryKey = HklmPath.OpenSubKey("Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall")
    8.         ProgramList = GetUninstallKeyPrograms(Wow64UninstallKey, ClassesKey, ProgramList, IncludeUpdates)
    9.  
    10.         '---Standard Uninstall key
    11.         Dim StdUninstallKey As RegistryKey = HklmPath.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall")
    12.         ProgramList = GetUninstallKeyPrograms(StdUninstallKey, ClassesKey, ProgramList, IncludeUpdates)
    13.  
    14.         For Each UserSid As String In HkuPath.GetSubKeyNames
    15.             Try
    16.                 '---HKU Uninstall key
    17.                 Dim CuUnInstallKey As RegistryKey = HkuPath.OpenSubKey(UserSid & "\Software\Microsoft\Windows\CurrentVersion\Uninstall")
    18.                 ProgramList = GetUninstallKeyPrograms(CuUnInstallKey, ClassesKey, ProgramList, IncludeUpdates)
    19.                 '---HKU Installer key
    20.                 Dim CuInstallerKey As RegistryKey = HkuPath.OpenSubKey(UserSid & "\Software\Microsoft\Installer\Products")
    21.                 ProgramList = GetUserInstallerKeyPrograms(CuInstallerKey, HklmPath, ProgramList)
    22.             Catch ex As Exception
    23.                 Debug.WriteLine("Error encountered in HKEY_USERS\" & UserSid & " : " & ex.Message)
    24.             End Try
    25.         Next
    26.  
    27.  
    28.         'Close the registry keys
    29.         Try
    30.             HklmPath.Close()
    31.             HkuPath.Close()
    32.         Catch ex As Exception
    33.             Debug.WriteLine("Error closing registry key - " & ex.Message)
    34.         End Try
    35.  
    36.         'Sort the list alphabetically and return it to the caller
    37.         ProgramList.Sort()
    38.         Return ProgramList
    39.     End Function

    let me know how it goes
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  17. #57
    Addicted Member
    Join Date
    Sep 2008
    Posts
    149

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    In registry under HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall I have keys which starts with "{some number" but application skip this keys and start with application name keys.
    I search through the code,but didn't notice how you did this.

  18. #58

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    Quote Originally Posted by Blagojce View Post
    In registry under HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall I have keys which starts with "{some number" but application skip this keys and start with application name keys.
    I search through the code,but didn't notice how you did this.
    Those programs are programs that have been installed by a Windows Installer (MSI) setup program. For each of the registry keys under that location you mentioned, my code checks to see if they have the WindowsInstaller value within them set to 1, if they do then we just get the name of the key (so{DJFHDFH34} for example) and pass it to our GetInstallerKeyNameFromGuid function which takes the name and works out the MSI installer ID for it (which is done by just moving some of the characters around, just look at the function to see exactly what it does). Then we look for that MSI installer ID in another part of the registry (HKEY_CLASSES_ROOT\MSI_installer_ID_here) to actually get the program name and other information.

    This is the part of the code that does it (within the GetUninstallKeyPrograms method):

    vb.net Code:
    1. If Not CInt(CurrentSubKey.GetValue("WindowsInstaller", 0)) = 1 Then
    2. '...
    3. '... irrelevent code here
    4. '...
    5. Else   'If WindowsInstaller
    6.      Dim ProgVersion As String = String.Empty
    7.      Dim Name As String = String.Empty
    8.      Dim FoundName As Boolean = False
    9.      Try
    10.            Dim MsiKeyName As String = GetInstallerKeyNameFromGuid(SubKeyName)
    11.            Dim CrGuidKey As RegistryKey = ClassesKey.OpenSubKey(MsiKeyName)
    12.            If Not CrGuidKey Is Nothing Then
    13.                   Name = CStr(CrGuidKey.GetValue("ProductName", String.Empty))
    14.            End If
    15.      Catch ex As Exception
    16.            Debug.WriteLine(SubKeyName & " - " & ex.Message)
    17.      End Try

    Hope that explains it - I know its not very straight forward, that's why it took me ages to figure it out and get this code working
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  19. #59
    Member
    Join Date
    Feb 2010
    Posts
    36

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    Quote Originally Posted by chris128 View Post
    Yeah you could just wrap each iteration of the loop through individual user's programs because if it fails for one item in that user's registry hive then it will fail for all of them so it doesn't make any sense to add the Try/Catch any further into the code.

    vb.net Code:
    1. Private Shared Function InternalGetInstalledPrograms(ByVal IncludeUpdates As Boolean, ByVal HklmPath As RegistryKey, ByVal HkuPath As RegistryKey) As List(Of InstalledProgram)
    2.         Dim ProgramList As New List(Of InstalledProgram)
    3.  
    4.         Dim ClassesKey As RegistryKey = HklmPath.OpenSubKey("Software\Classes\Installer\Products")
    5.  
    6.         '---Wow64 Uninstall key
    7.         Dim Wow64UninstallKey As RegistryKey = HklmPath.OpenSubKey("Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall")
    8.         ProgramList = GetUninstallKeyPrograms(Wow64UninstallKey, ClassesKey, ProgramList, IncludeUpdates)
    9.  
    10.         '---Standard Uninstall key
    11.         Dim StdUninstallKey As RegistryKey = HklmPath.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall")
    12.         ProgramList = GetUninstallKeyPrograms(StdUninstallKey, ClassesKey, ProgramList, IncludeUpdates)
    13.  
    14.         For Each UserSid As String In HkuPath.GetSubKeyNames
    15.             Try
    16.                 '---HKU Uninstall key
    17.                 Dim CuUnInstallKey As RegistryKey = HkuPath.OpenSubKey(UserSid & "\Software\Microsoft\Windows\CurrentVersion\Uninstall")
    18.                 ProgramList = GetUninstallKeyPrograms(CuUnInstallKey, ClassesKey, ProgramList, IncludeUpdates)
    19.                 '---HKU Installer key
    20.                 Dim CuInstallerKey As RegistryKey = HkuPath.OpenSubKey(UserSid & "\Software\Microsoft\Installer\Products")
    21.                 ProgramList = GetUserInstallerKeyPrograms(CuInstallerKey, HklmPath, ProgramList)
    22.             Catch ex As Exception
    23.                 Debug.WriteLine("Error encountered in HKEY_USERS\" & UserSid & " : " & ex.Message)
    24.             End Try
    25.         Next
    26.  
    27.  
    28.         'Close the registry keys
    29.         Try
    30.             HklmPath.Close()
    31.             HkuPath.Close()
    32.         Catch ex As Exception
    33.             Debug.WriteLine("Error closing registry key - " & ex.Message)
    34.         End Try
    35.  
    36.         'Sort the list alphabetically and return it to the caller
    37.         ProgramList.Sort()
    38.         Return ProgramList
    39.     End Function

    let me know how it goes
    worked like a charm chris, thanks a bunch.

    -Drew

  20. #60
    Lively Member cevem's Avatar
    Join Date
    Feb 2010
    Location
    Mars
    Posts
    78

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    That's great article.

    I have a question. How to find executable location of the programs? Thanks.

  21. #61

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    Quote Originally Posted by cevem View Post
    That's great article.

    I have a question. How to find executable location of the programs? Thanks.
    There isn't any way that I know of. I know we all like to think that an installed program has a "main" EXE file but at the end of the day an installed program can be any number of EXEs (maybe even none at all) so Windows does not have any relation between an entry in Add/Remove Programs and actual EXE's (other than the location of the uninstaller for that program). If anyone finds a way to do it I would be interested to hear how, but as far as I know it is not really possible.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  22. #62
    Addicted Member
    Join Date
    Sep 2008
    Posts
    149

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    Quote Originally Posted by chris128 View Post
    Those programs are programs that have been installed by a Windows Installer (MSI) setup program. For each of the registry keys under that location you mentioned, my code checks to see if they have the WindowsInstaller value within them set to 1, if they do then we just get the name of the key (so{DJFHDFH34} for example) and pass it to our GetInstallerKeyNameFromGuid function which takes the name and works out the MSI installer ID for it (which is done by just moving some of the characters around, just look at the function to see exactly what it does). Then we look for that MSI installer ID in another part of the registry (HKEY_CLASSES_ROOT\MSI_installer_ID_here) to actually get the program name and other information.

    This is the part of the code that does it (within the GetUninstallKeyPrograms method):

    vb.net Code:
    1. If Not CInt(CurrentSubKey.GetValue("WindowsInstaller", 0)) = 1 Then
    2. '...
    3. '... irrelevent code here
    4. '...
    5. Else   'If WindowsInstaller
    6.      Dim ProgVersion As String = String.Empty
    7.      Dim Name As String = String.Empty
    8.      Dim FoundName As Boolean = False
    9.      Try
    10.            Dim MsiKeyName As String = GetInstallerKeyNameFromGuid(SubKeyName)
    11.            Dim CrGuidKey As RegistryKey = ClassesKey.OpenSubKey(MsiKeyName)
    12.            If Not CrGuidKey Is Nothing Then
    13.                   Name = CStr(CrGuidKey.GetValue("ProductName", String.Empty))
    14.            End If
    15.      Catch ex As Exception
    16.            Debug.WriteLine(SubKeyName & " - " & ex.Message)
    17.      End Try

    Hope that explains it - I know its not very straight forward, that's why it took me ages to figure it out and get this code working
    Now it is clarified, Thanks!

  23. #63
    Member
    Join Date
    Feb 2010
    Posts
    36

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    Chris,

    I know that in the sub-directories in the following paths most programs have an 'installdate' key associated with them:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
    HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall

    Would you be able to give me some instructions on how to query the 'installdate' reg key and return that as well (similar to calling program.displayname & program.version? i.e. so I can return program.installdate

    What parts of the code do I need to add to in order to be able to grab that?

    I would find this very useful.

    Thanks in advance, your help is always appreciated!

    -Drew

  24. #64
    Member
    Join Date
    Feb 2010
    Posts
    36

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    well, I think I figured it out, was easier than I thought.
    Last edited by Drewster727; Jun 9th, 2011 at 11:26 AM.

  25. #65
    Frenzied Member
    Join Date
    Sep 2006
    Location
    UK / East Sussex
    Posts
    1,054

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    Hi Chris128, Thanks for this example works brilliantly, My code was only getting half of the apps.

    I have chopped out alot of code as I didn't require it for this project as its an automated program to get details from the local machine (no updates).

    It all works brilliantly I have the Target cpu set to Active (any CPU) however one small problem which isn't a big deal is the duplication of the odd few programs.

    This is not a problem for us and I noticed someone else mentioned it but also mentioned it worked fine after they set it to Any CPU.

    Not a problem just thought I would bring it up. But well done on the great coding :-)
    M.Carpenter

    Server Admin for Wurm Online
    Wurm Online - A very unique and original MMO from Code Club AB
    https://www.youtube.com/watch?v=YQlYar2uHWAWurm Trailor


  26. #66

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    Thanks surprised to hear you are getting duplicats though when you are compiling to AnyCPU as I've been using this code for months on loads of machines and not found any machines where it does not produce an identical list to Add/Remove Programs. Are you sure you didn't change something when you were chopping out the bits that you don't need? Or maybe these machines have multiple versions of these programs installed?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  27. #67
    Lively Member elielCT's Avatar
    Join Date
    Jun 2011
    Posts
    89

    Thumbs up Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    This is really awsome..
    I was using my own script, with additional scripts found elsewhere, but this handles it all!!

    Very nice..

  28. #68

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    Thanks
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  29. #69
    Lively Member elielCT's Avatar
    Join Date
    Jun 2011
    Posts
    89

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    ok everyone seems to be asking about the icon thing...
    its really cake to do, and I wanted that feature as well so I put it in...
    now as perfect as this solution seemed (unghhhhh!), it wasnt really what i wanted after all.. but chris u definately put me in the right path.. like sum1 mentioned B4, what i really wanted was the path to the executables, and didnt want bundles (such as office, or adobe cs3), but rather an itemized account of the exe's in those bundles (word, excel, ect.).. so using your structure (nicely done with the Ienum, i guess i dont know as much as i thought i did) i will search the start menu, and program files folder, and possibly system32 for any & all exe. when i finish, following tradition, i will post in new thread. Now for the icon matter this is how i did it:


    in the properties region add:
    vb Code:
    1. Private _IconPath As String = String.Empty
    2.     ''' <summary>
    3.     ''' If this program specifies an icon file, it's path will be returned
    4.     ''' </summary>
    5.     Public Property IconPath() As String
    6.         Get
    7.             Return _IconPath
    8.         End Get
    9.         Set(ByVal value As String)
    10.             _IconPath = value
    11.         End Set
    12.     End Property


    in the constructors region change second sub to:

    vb Code:
    1. Public Sub New(ByVal ProgramDisplayName As String, ByVal ProgramParentDisplayName As String, ByVal IsProgramUpdate As Boolean, ByVal ProgramVersion As String, ByVal ProgramIconPath As String)
    2.         Me.DisplayName = ProgramDisplayName
    3.         Me.ParentDisplayName = ProgramParentDisplayName
    4.         Me.IsUpdate = IsProgramUpdate
    5.         Me.Version = ProgramVersion
    6.         Me.IconPath = ProgramIconPath
    7.     End Sub


    in the GetUserInstallerKeyPrograms function edit to the following:

    vb Code:
    1. If Not CInt(UserDataProgramKey.GetValue("SystemComponent", 0)) = 1 Then
    2.                                         Dim Name As String = CStr(CuInstallerKey.OpenSubKey(CuProductGuid).GetValue("ProductName", String.Empty))
    3.                                         Dim ProgVersion As String = String.Empty
    4.                                         Dim ProgIcon As String = String.Empty
    5.                                         Try
    6.                                             ProgVersion = CStr(UserDataProgramKey.GetValue("DisplayVersion", String.Empty))
    7.                                             ProgIcon = CStr(UserDataProgramKey.GetValue("DisplayIcon", String.Empty))
    8.                                         Catch ex As Exception
    9.                                             Debug.WriteLine(ex.Message)
    10.                                         End Try
    11.                                         If Not Name = String.Empty AndAlso Not IsProgramInList(Name, ExistingProgramList) Then
    12.                                             ExistingProgramList.Add(New InstalledProgram(Name))
    13.                                             ProductFound = True
    14.                                         End If
    15.                                     End If


    in the GetUninstallKeyPrograms function edit to the following:

    vb Code:
    1. If IncludeUpdates Then
    2.                                     'Add the program to our list if we are including updates in this search
    3.                                     Dim Name As String = CStr(CurrentSubKey.GetValue("DisplayName", String.Empty))
    4.                                     Dim IconP As String = CStr(CurrentSubKey.GetValue("DisplayIcon", String.Empty))
    5.                                     If Not Name = String.Empty AndAlso Not IsProgramInList(Name, ExistingProgramList) Then
    6.                                         ExistingProgramList.Add(New InstalledProgram(Name, CStr(CurrentSubKey.GetValue("ParentDisplayName", String.Empty)), True, ProgVersion, IconP))
    7.                                     End If
    8.                                 End If


    and still in the GetUninstallKeyPrograms function edit to the following:

    vb Code:
    1. If UninstallStringExists Then
    2.                                     Dim Name As String = CStr(CurrentSubKey.GetValue("DisplayName", String.Empty))
    3.                                     Dim IconP As String = CStr(CurrentSubKey.GetValue("DisplayIcon", String.Empty))
    4.                                     If Not Name = String.Empty AndAlso Not IsProgramInList(Name, ExistingProgramList) Then
    5.                                         If Not IconP = String.Empty Then
    6.                                         End If
    7.                                         ExistingProgramList.Add(New InstalledProgram(Name, CStr(CurrentSubKey.GetValue("ParentDisplayName", String.Empty)), False, ProgVersion, IconP))
    8.  
    9.                                     End If
    10.                                 End If


    and still in the GetUninstallKeyPrograms function edit to the following:

    vb Code:
    1. Else 'If WindowsInstaller
    2.                             Dim ProgVersion As String = String.Empty
    3.                             Dim Name As String = String.Empty
    4.                             Dim FoundName As Boolean = False
    5.                             Dim IconP As String = String.Empty
    6.                             Try
    7.                                 Dim MsiKeyName As String = GetInstallerKeyNameFromGuid(SubKeyName)
    8.                                 Dim CrGuidKey As RegistryKey = ClassesKey.OpenSubKey(MsiKeyName)
    9.                                 If Not CrGuidKey Is Nothing Then
    10.                                     Name = CStr(CrGuidKey.GetValue("ProductName", String.Empty))
    11.                                     IconP = CStr(CrGuidKey.GetValue("DisplayIcon", String.Empty))
    12.                                 End If
    13.                             Catch ex As Exception
    14.                                 Debug.WriteLine(SubKeyName & " - " & ex.Message)
    15.                             End Try
    16.                             Try
    17.                                 ProgVersion = CStr(CurrentSubKey.GetValue("DisplayVersion", String.Empty))
    18.                                 IconP = CStr(CurrentSubKey.GetValue("DisplayIcon", String.Empty))
    19.                             Catch ex As Exception
    20.                                 Debug.WriteLine(ex.Message)
    21.                             End Try
    22.                             If Not Name = String.Empty AndAlso Not IsProgramInList(Name, ExistingProgramList) Then
    23.                                 ExistingProgramList.Add(New InstalledProgram(Name, CStr(CurrentSubKey.GetValue("ParentDisplayName", String.Empty)), False, ProgVersion, IconP))
    24.                             End If
    25.                         End If


    Now in your form get the icons as follows:

    vb Code:
    1. Private Sub GetProgramsFinished(ByVal InstalledPrograms As List(Of InstalledProgram))
    2.         If Not InstalledPrograms Is Nothing Then
    3.             For i As Integer = 0 To InstalledPrograms.Count - 1
    4.                 If InstalledPrograms(i).IsUpdate = False Then
    5.                     Dim theIcon As Icon
    6.                     Dim theIconPath As String
    7.                     Try
    8.                         If Not InstalledPrograms(i).IconPath = Nothing Then
    9.                             If InstalledPrograms(i).IconPath.IndexOf(",") > 0 Then
    10.                                 theIconPath = InstalledPrograms(i).IconPath.Substring(0, InstalledPrograms(i).IconPath.IndexOf(","))
    11.                             Else
    12.                                 theIconPath = InstalledPrograms(i).IconPath
    13.                             End If
    14.                             theIcon = System.Drawing.Icon.ExtractAssociatedIcon(theIconPath)
    15.                         Else
    16.                             theIcon = My.Resources.error_icon1
    17.                         End If
    18.                     Catch ex As Exception
    19.                         theIcon = My.Resources.error_icon1
    20.                     End Try
    21.  
    22.                     ProgDataGridView.Rows.Add("", theIcon, InstalledPrograms(i).DisplayName)
    23.                     Me.ProgDataGridView.Refresh()
    24.                 End If
    25.             Next
    26.         End If
    27.         Me.Enabled = True
    28.         If ProgDataGridView.Rows.Count = 1 Then
    29.             MessageBox.Show("No programs were found - this could be because there were no programs installed on the computer (that is not very likely really though is it)." & vbNewLine & _
    30.                             "Try again... ", "Ooops", MessageBoxButtons.OK, MessageBoxIcon.Warning)
    31.         Else
    32.         End If
    33.     End Sub

    this will get u almost all icons, and puts one in its place where it didnt find an icon. Im not going to perfect this, as im going a slightly different route based on chris's solution... but should help point yall in the right direction...
    Last edited by elielCT; Jun 26th, 2011 at 01:29 PM.

  30. #70

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    Cool thanks for posting that, I'm sure it will help others out The only reason I didn't add the icons originally is because this is intended to be usable against remote PCs and in that situation your code (which is the same as how I would have done it) wont work. If you only ever intend for this code to get programs from the machine it is running on then obviously that is not an issue

    Oh and you said it gets almost all icons - are there any that it doesn't get that do actually appear in Add/Remove Programs? I'm assuming there is and that these are icons where the file pointed to by the DisplayIcon registry value contains more than one icon, as you are just using ExtractAssociatedIcon which doesn't have any option to get a specific icon from the file. If you are bothered about this, you might want to try using the NativeIcon.GetIconAtIndex method from my Windows API library (download link in my signature) as this will let you get an icon at a specific index from the specified file (I believe the DisplayIcon registry values specify the index number of the icon that should be used after the file name)
    Last edited by chris128; Jun 26th, 2011 at 01:49 PM.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  31. #71
    Lively Member elielCT's Avatar
    Join Date
    Jun 2011
    Posts
    89

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    gotcha...

    yea thats not the case with me....

    the reason for me gettin involved in this whole mess is due to the development of a small app that requires list of installed progs in local pc, but the path of itemized exe's is an integral and essential part..

    thanks again for sharin... a little moddin and i devote more time to the rest of the app instead...

  32. #72
    Lively Member elielCT's Avatar
    Join Date
    Jun 2011
    Posts
    89

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    some.. 7zip icon does not show in either, but clipmagic icon shows in add/remove...
    ur edit should do the trick.. and while using ur edit the user should remove/alter the line that i used to search for icons with index values, and remove the index.. utorrent didnt seem to care and the icon displays, but the others wont..

  33. #73

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    Ah yeah, you mean this bit:
    Code:
    If InstalledPrograms(i).IconPath.IndexOf(",") > 0 Then
                                    theIconPath = InstalledPrograms(i).IconPath.Substring(0, InstalledPrograms(i).IconPath.IndexOf(","))
                                Else
                                    theIconPath = InstalledPrograms(i).IconPath
                                End If
    Anyway, glad the code helped you out a bit even if it wasn't 100&#37; what you were looking for
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  34. #74
    New Member
    Join Date
    Aug 2011
    Posts
    3

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    I am new to vb and I love your code, it looks awesome and I want to know how can I also pull the system information from the remote pc. Things like computer type ram, hard disk, ect. I want to put it on the same page. Can you assist?

  35. #75
    Frenzied Member
    Join Date
    Sep 2006
    Location
    UK / East Sussex
    Posts
    1,054

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    You should be starting a new thread not replying to this one.

    This is exactly what I am working on at the moment for our Internal Asset Management system. There are two ways to go about it:

    1: (The route we are taking): Have a client peice of software on each machine that collects details and sends back to a central server. Useful if you just want a database of machines with details - this method can also get alot of information.

    2: Use Remote WMI to get the information you want. Note you will need permissions to access the other machine. I have used remote WMI but only within a Domain Environment and I have Domain Admin rights.

    There is probably other methods but these are the two ones that jump out at me.

    Hope this helps. If you want to discuss it further create a new thread in the vb.net forum.
    M.Carpenter

    Server Admin for Wurm Online
    Wurm Online - A very unique and original MMO from Code Club AB
    https://www.youtube.com/watch?v=YQlYar2uHWAWurm Trailor


  36. #76
    New Member
    Join Date
    Aug 2011
    Posts
    3

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    Thanks I posted a new thread to show you what I am looking for.

  37. #77

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    Quote Originally Posted by max_carpenter View Post
    2: Use Remote WMI to get the information you want. Note you will need permissions to access the other machine. I have used remote WMI but only within a Domain Environment and I have Domain Admin rights.
    Yeah WMI can be a little unreliable because a lot of admins don't allow it through their workstation's firewalls or simply disable the WMI service.

    The other method that I have used in the past is a variation on your first method - rather than having a piece of software actually installed and always running on the workstations, we just run the program from a network share via logon script that is assigned to all users. This way it runs whenever anyone logs on to a PC (so we also get a record of when anyone logged on and which PC they logged on to) and updates the general system info in a central SQL database
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  38. #78
    Frenzied Member
    Join Date
    Sep 2006
    Location
    UK / East Sussex
    Posts
    1,054

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    That is similar to what I have built (and currently rebuilding) at my place although it doesnt run with logon scripts.

    My old package ran as a windows service on each local machine and got all the information I required including last logged on user and lots of WMI information then compiled an XML sent it back to the server for a server service to read the xml and enter it into the database.

    The new one is slightly differnts its a windows forms app that runs on startup for every user, still collects all the same information but then connects to the server using sockets to send all the info back. The reason its a windows forms app because italso acts as a server monitor for users to see status of all our services and for us to display messages to the user etc.
    M.Carpenter

    Server Admin for Wurm Online
    Wurm Online - A very unique and original MMO from Code Club AB
    https://www.youtube.com/watch?v=YQlYar2uHWAWurm Trailor


  39. #79

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    Yeah I do like the idea of having an app like that, that we could send messages to the users through or send it the path to a script/program to execute, but I always wonder about the security risks. I mean if you have an app that accepts incoming connections that give it commands to execute, it would be very easy for an attacker to exploit and make it do whatever they wanted, if you didn't have some decent security built in (more than just a hard coded password because someone could just decompile your client side app to see what the password is that it checks for). I know the probability of anyone actually trying to exploit a bespoke app you've written is very slim but I just think if it ever did happen I would be in so much trouble if someone found out my application had put every user's computers at risk (and therefore the entire company's data) that its just not worth it. Plus, we use MS SCCM now so we can just use that to push out apps and scripts etc and it collects a fair bit of information from the workstations too, even down to when they last ran each EXE on their PC which comes in handy for identifying who isn't using software that we pay for licenses for so that we can redistribute that license instead of having to buy a new one
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  40. #80
    Frenzied Member
    Join Date
    Sep 2006
    Location
    UK / East Sussex
    Posts
    1,054

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    That does sound handy.

    As for the bespoke app not only as you mention is it very very slim that someone will exploit it especially as its not out in the public for anyone to find but with our one it only accepts pre-programmend commands and not scripts or windows commands etc.

    For instance it is programmed to accept the commands

    SCAN
    LOCATE
    UPATE
    AVSCAN
    MESSAGE

    etc

    But I couldn't say run the following:

    C:\tmp\MyScript.bat

    My program would just see that as an error and disconnect the session.
    M.Carpenter

    Server Admin for Wurm Online
    Wurm Online - A very unique and original MMO from Code Club AB
    https://www.youtube.com/watch?v=YQlYar2uHWAWurm Trailor


Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width