-
Feb 16th, 2011, 10:00 AM
#41
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.
-
Feb 16th, 2011, 11:28 AM
#42
Junior Member
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?
-
Feb 16th, 2011, 11:36 AM
#43
Re: Example of how to get a list of installed programs (like Add and Remove Programs)
No because that targets AnyCpu
-
Feb 16th, 2011, 06:06 PM
#44
Junior Member
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)"...
-
Feb 16th, 2011, 06:32 PM
#45
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.
-
Feb 16th, 2011, 06:38 PM
#46
Junior Member
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?
-
Feb 16th, 2011, 06:42 PM
#47
Junior Member
Re: Example of how to get a list of installed programs (like Add and Remove Programs)
Originally Posted by chris128
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.
-
Feb 17th, 2011, 03:40 AM
#48
Re: Example of how to get a list of installed programs (like Add and Remove Programs)
Originally Posted by ClarkVent
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.
-
May 3rd, 2011, 11:24 AM
#49
New Member
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?
-
May 3rd, 2011, 11:53 AM
#50
Re: Example of how to get a list of installed programs (like Add and Remove Programs)
Originally Posted by etorreshn
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" ?
-
May 3rd, 2011, 08:28 PM
#51
Member
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
-
May 4th, 2011, 04:50 AM
#52
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).
-
May 5th, 2011, 12:39 AM
#53
Member
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...
-
May 5th, 2011, 04:11 AM
#54
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).
-
May 5th, 2011, 01:42 PM
#55
Member
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
-
May 5th, 2011, 02:35 PM
#56
Re: Example of how to get a list of installed programs (like Add and Remove Programs)
Originally Posted by Drewster727
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:
Private Shared Function InternalGetInstalledPrograms(ByVal IncludeUpdates As Boolean, ByVal HklmPath As RegistryKey, ByVal HkuPath As RegistryKey) As List(Of InstalledProgram)
Dim ProgramList As New List(Of InstalledProgram)
Dim ClassesKey As RegistryKey = HklmPath.OpenSubKey("Software\Classes\Installer\Products")
'---Wow64 Uninstall key
Dim Wow64UninstallKey As RegistryKey = HklmPath.OpenSubKey("Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall")
ProgramList = GetUninstallKeyPrograms(Wow64UninstallKey, ClassesKey, ProgramList, IncludeUpdates)
'---Standard Uninstall key
Dim StdUninstallKey As RegistryKey = HklmPath.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall")
ProgramList = GetUninstallKeyPrograms(StdUninstallKey, ClassesKey, ProgramList, IncludeUpdates)
For Each UserSid As String In HkuPath.GetSubKeyNames
'---HKU Uninstall key
Dim CuUnInstallKey As RegistryKey = HkuPath.OpenSubKey(UserSid & "\Software\Microsoft\Windows\CurrentVersion\Uninstall")
ProgramList = GetUninstallKeyPrograms(CuUnInstallKey, ClassesKey, ProgramList, IncludeUpdates)
'---HKU Installer key
Dim CuInstallerKey As RegistryKey = HkuPath.OpenSubKey(UserSid & "\Software\Microsoft\Installer\Products")
ProgramList = GetUserInstallerKeyPrograms(CuInstallerKey, HklmPath, ProgramList)
Next
'Close the registry keys
Try
HklmPath.Close()
HkuPath.Close()
Catch ex As Exception
Debug.WriteLine("Error closing registry key - " & ex.Message)
End Try
'Sort the list alphabetically and return it to the caller
ProgramList.Sort()
Return ProgramList
End Function
with this:
vb.net Code:
Private Shared Function InternalGetInstalledPrograms(ByVal IncludeUpdates As Boolean, ByVal HklmPath As RegistryKey, ByVal HkuPath As RegistryKey) As List(Of InstalledProgram)
Dim ProgramList As New List(Of InstalledProgram)
Dim ClassesKey As RegistryKey = HklmPath.OpenSubKey("Software\Classes\Installer\Products")
'---Wow64 Uninstall key
Dim Wow64UninstallKey As RegistryKey = HklmPath.OpenSubKey("Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall")
ProgramList = GetUninstallKeyPrograms(Wow64UninstallKey, ClassesKey, ProgramList, IncludeUpdates)
'---Standard Uninstall key
Dim StdUninstallKey As RegistryKey = HklmPath.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall")
ProgramList = GetUninstallKeyPrograms(StdUninstallKey, ClassesKey, ProgramList, IncludeUpdates)
For Each UserSid As String In HkuPath.GetSubKeyNames
Try
'---HKU Uninstall key
Dim CuUnInstallKey As RegistryKey = HkuPath.OpenSubKey(UserSid & "\Software\Microsoft\Windows\CurrentVersion\Uninstall")
ProgramList = GetUninstallKeyPrograms(CuUnInstallKey, ClassesKey, ProgramList, IncludeUpdates)
'---HKU Installer key
Dim CuInstallerKey As RegistryKey = HkuPath.OpenSubKey(UserSid & "\Software\Microsoft\Installer\Products")
ProgramList = GetUserInstallerKeyPrograms(CuInstallerKey, HklmPath, ProgramList)
Catch ex As Exception
Debug.WriteLine("Error encountered in HKEY_USERS\" & UserSid & " : " & ex.Message)
End Try
Next
'Close the registry keys
Try
HklmPath.Close()
HkuPath.Close()
Catch ex As Exception
Debug.WriteLine("Error closing registry key - " & ex.Message)
End Try
'Sort the list alphabetically and return it to the caller
ProgramList.Sort()
Return ProgramList
End Function
let me know how it goes
-
May 6th, 2011, 01:46 PM
#57
Addicted Member
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.
-
May 6th, 2011, 02:13 PM
#58
Re: Example of how to get a list of installed programs (like Add and Remove Programs)
Originally Posted by Blagojce
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:
If Not CInt(CurrentSubKey.GetValue("WindowsInstaller", 0)) = 1 Then
'...
'... irrelevent code here
'...
Else 'If WindowsInstaller
Dim ProgVersion As String = String.Empty
Dim Name As String = String.Empty
Dim FoundName As Boolean = False
Try
Dim MsiKeyName As String = GetInstallerKeyNameFromGuid(SubKeyName)
Dim CrGuidKey As RegistryKey = ClassesKey.OpenSubKey(MsiKeyName)
If Not CrGuidKey Is Nothing Then
Name = CStr(CrGuidKey.GetValue("ProductName", String.Empty))
End If
Catch ex As Exception
Debug.WriteLine(SubKeyName & " - " & ex.Message)
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
-
May 6th, 2011, 09:22 PM
#59
Member
Re: Example of how to get a list of installed programs (like Add and Remove Programs)
Originally Posted by chris128
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:
Private Shared Function InternalGetInstalledPrograms(ByVal IncludeUpdates As Boolean, ByVal HklmPath As RegistryKey, ByVal HkuPath As RegistryKey) As List(Of InstalledProgram)
Dim ProgramList As New List(Of InstalledProgram)
Dim ClassesKey As RegistryKey = HklmPath.OpenSubKey("Software\Classes\Installer\Products")
'---Wow64 Uninstall key
Dim Wow64UninstallKey As RegistryKey = HklmPath.OpenSubKey("Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall")
ProgramList = GetUninstallKeyPrograms(Wow64UninstallKey, ClassesKey, ProgramList, IncludeUpdates)
'---Standard Uninstall key
Dim StdUninstallKey As RegistryKey = HklmPath.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall")
ProgramList = GetUninstallKeyPrograms(StdUninstallKey, ClassesKey, ProgramList, IncludeUpdates)
For Each UserSid As String In HkuPath.GetSubKeyNames
Try
'---HKU Uninstall key
Dim CuUnInstallKey As RegistryKey = HkuPath.OpenSubKey(UserSid & "\Software\Microsoft\Windows\CurrentVersion\Uninstall")
ProgramList = GetUninstallKeyPrograms(CuUnInstallKey, ClassesKey, ProgramList, IncludeUpdates)
'---HKU Installer key
Dim CuInstallerKey As RegistryKey = HkuPath.OpenSubKey(UserSid & "\Software\Microsoft\Installer\Products")
ProgramList = GetUserInstallerKeyPrograms(CuInstallerKey, HklmPath, ProgramList)
Catch ex As Exception
Debug.WriteLine("Error encountered in HKEY_USERS\" & UserSid & " : " & ex.Message)
End Try
Next
'Close the registry keys
Try
HklmPath.Close()
HkuPath.Close()
Catch ex As Exception
Debug.WriteLine("Error closing registry key - " & ex.Message)
End Try
'Sort the list alphabetically and return it to the caller
ProgramList.Sort()
Return ProgramList
End Function
let me know how it goes
worked like a charm chris, thanks a bunch.
-Drew
-
May 7th, 2011, 10:11 AM
#60
Lively Member
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.
-
May 7th, 2011, 12:43 PM
#61
Re: Example of how to get a list of installed programs (like Add and Remove Programs)
Originally Posted by cevem
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.
-
May 7th, 2011, 01:26 PM
#62
Addicted Member
Re: Example of how to get a list of installed programs (like Add and Remove Programs)
Originally Posted by chris128
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:
If Not CInt(CurrentSubKey.GetValue("WindowsInstaller", 0)) = 1 Then
'...
'... irrelevent code here
'...
Else 'If WindowsInstaller
Dim ProgVersion As String = String.Empty
Dim Name As String = String.Empty
Dim FoundName As Boolean = False
Try
Dim MsiKeyName As String = GetInstallerKeyNameFromGuid(SubKeyName)
Dim CrGuidKey As RegistryKey = ClassesKey.OpenSubKey(MsiKeyName)
If Not CrGuidKey Is Nothing Then
Name = CStr(CrGuidKey.GetValue("ProductName", String.Empty))
End If
Catch ex As Exception
Debug.WriteLine(SubKeyName & " - " & ex.Message)
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!
-
Jun 9th, 2011, 10:29 AM
#63
Member
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
-
Jun 9th, 2011, 10:45 AM
#64
Member
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.
-
Jun 24th, 2011, 09:11 AM
#65
Frenzied Member
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 :-)
-
Jun 24th, 2011, 11:53 AM
#66
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?
-
Jun 25th, 2011, 08:30 PM
#67
Lively Member
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..
-
Jun 26th, 2011, 03:33 AM
#68
Re: Example of how to get a list of installed programs (like Add and Remove Programs)
Thanks
-
Jun 26th, 2011, 01:26 PM
#69
Lively Member
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:
Private _IconPath As String = String.Empty
''' <summary>
''' If this program specifies an icon file, it's path will be returned
''' </summary>
Public Property IconPath() As String
Get
Return _IconPath
End Get
Set(ByVal value As String)
_IconPath = value
End Set
End Property
in the constructors region change second sub to:
vb Code:
Public Sub New(ByVal ProgramDisplayName As String, ByVal ProgramParentDisplayName As String, ByVal IsProgramUpdate As Boolean, ByVal ProgramVersion As String, ByVal ProgramIconPath As String)
Me.DisplayName = ProgramDisplayName
Me.ParentDisplayName = ProgramParentDisplayName
Me.IsUpdate = IsProgramUpdate
Me.Version = ProgramVersion
Me.IconPath = ProgramIconPath
End Sub
in the GetUserInstallerKeyPrograms function edit to the following:
vb Code:
If Not CInt(UserDataProgramKey.GetValue("SystemComponent", 0)) = 1 Then
Dim Name As String = CStr(CuInstallerKey.OpenSubKey(CuProductGuid).GetValue("ProductName", String.Empty))
Dim ProgVersion As String = String.Empty
Dim ProgIcon As String = String.Empty
Try
ProgVersion = CStr(UserDataProgramKey.GetValue("DisplayVersion", String.Empty))
ProgIcon = CStr(UserDataProgramKey.GetValue("DisplayIcon", String.Empty))
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
If Not Name = String.Empty AndAlso Not IsProgramInList(Name, ExistingProgramList) Then
ExistingProgramList.Add(New InstalledProgram(Name))
ProductFound = True
End If
End If
in the GetUninstallKeyPrograms function edit to the following:
vb Code:
If IncludeUpdates Then
'Add the program to our list if we are including updates in this search
Dim Name As String = CStr(CurrentSubKey.GetValue("DisplayName", String.Empty))
Dim IconP As String = CStr(CurrentSubKey.GetValue("DisplayIcon", String.Empty))
If Not Name = String.Empty AndAlso Not IsProgramInList(Name, ExistingProgramList) Then
ExistingProgramList.Add(New InstalledProgram(Name, CStr(CurrentSubKey.GetValue("ParentDisplayName", String.Empty)), True, ProgVersion, IconP))
End If
End If
and still in the GetUninstallKeyPrograms function edit to the following:
vb Code:
If UninstallStringExists Then
Dim Name As String = CStr(CurrentSubKey.GetValue("DisplayName", String.Empty))
Dim IconP As String = CStr(CurrentSubKey.GetValue("DisplayIcon", String.Empty))
If Not Name = String.Empty AndAlso Not IsProgramInList(Name, ExistingProgramList) Then
If Not IconP = String.Empty Then
End If
ExistingProgramList.Add(New InstalledProgram(Name, CStr(CurrentSubKey.GetValue("ParentDisplayName", String.Empty)), False, ProgVersion, IconP))
End If
End If
and still in the GetUninstallKeyPrograms function edit to the following:
vb Code:
Else 'If WindowsInstaller
Dim ProgVersion As String = String.Empty
Dim Name As String = String.Empty
Dim FoundName As Boolean = False
Dim IconP As String = String.Empty
Try
Dim MsiKeyName As String = GetInstallerKeyNameFromGuid(SubKeyName)
Dim CrGuidKey As RegistryKey = ClassesKey.OpenSubKey(MsiKeyName)
If Not CrGuidKey Is Nothing Then
Name = CStr(CrGuidKey.GetValue("ProductName", String.Empty))
IconP = CStr(CrGuidKey.GetValue("DisplayIcon", String.Empty))
End If
Catch ex As Exception
Debug.WriteLine(SubKeyName & " - " & ex.Message)
End Try
Try
ProgVersion = CStr(CurrentSubKey.GetValue("DisplayVersion", String.Empty))
IconP = CStr(CurrentSubKey.GetValue("DisplayIcon", String.Empty))
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
If Not Name = String.Empty AndAlso Not IsProgramInList(Name, ExistingProgramList) Then
ExistingProgramList.Add(New InstalledProgram(Name, CStr(CurrentSubKey.GetValue("ParentDisplayName", String.Empty)), False, ProgVersion, IconP))
End If
End If
Now in your form get the icons as follows:
vb Code:
Private Sub GetProgramsFinished(ByVal InstalledPrograms As List(Of InstalledProgram))
If Not InstalledPrograms Is Nothing Then
For i As Integer = 0 To InstalledPrograms.Count - 1
If InstalledPrograms(i).IsUpdate = False Then
Dim theIcon As Icon
Dim theIconPath As String
Try
If Not InstalledPrograms(i).IconPath = Nothing Then
If InstalledPrograms(i).IconPath.IndexOf(",") > 0 Then
theIconPath = InstalledPrograms(i).IconPath.Substring(0, InstalledPrograms(i).IconPath.IndexOf(","))
Else
theIconPath = InstalledPrograms(i).IconPath
End If
theIcon = System.Drawing.Icon.ExtractAssociatedIcon(theIconPath)
Else
theIcon = My.Resources.error_icon1
End If
Catch ex As Exception
theIcon = My.Resources.error_icon1
End Try
ProgDataGridView.Rows.Add("", theIcon, InstalledPrograms(i).DisplayName)
Me.ProgDataGridView.Refresh()
End If
Next
End If
Me.Enabled = True
If ProgDataGridView.Rows.Count = 1 Then
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 & _
"Try again... ", "Ooops", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
End If
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.
-
Jun 26th, 2011, 01:46 PM
#70
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.
-
Jun 26th, 2011, 01:54 PM
#71
Lively Member
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...
-
Jun 26th, 2011, 01:59 PM
#72
Lively Member
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..
-
Jun 26th, 2011, 03:14 PM
#73
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% what you were looking for
-
Aug 9th, 2011, 06:36 AM
#74
New Member
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?
-
Aug 10th, 2011, 01:50 AM
#75
Frenzied Member
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.
-
Aug 10th, 2011, 07:35 AM
#76
New Member
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.
-
Aug 10th, 2011, 08:07 AM
#77
Re: Example of how to get a list of installed programs (like Add and Remove Programs)
Originally Posted by max_carpenter
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
-
Aug 10th, 2011, 12:24 PM
#78
Frenzied Member
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.
-
Aug 10th, 2011, 02:31 PM
#79
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
-
Aug 11th, 2011, 01:26 AM
#80
Frenzied Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|