I can get the list if windows processes but I would also like to get the maker or manufacturer of the process. How to do that?
Printable View
I can get the list if windows processes but I would also like to get the maker or manufacturer of the process. How to do that?
What exactly do you mean by "maker or manufacturer of the process"?
Presumably the CompanyName field of the version information on an executable.
It's surprisingly difficult. There's GetFileVersionInfo/VerQueryValue, and that's a tall order to begin with and then you realize you've got to deal with multiple codepages and such... Unicode support is a little tricker.
For 99.99% of cases, the System.Company field of the property store would be fine. So the question then is, do you need to support XP? Because then Unicode support for this method is out.
An efficient, Unicode-aware method for Vista+ goes like this:
It's not exactly light on support code; requires my oleexp.tlb, and:Code:Dim sFile As String
sFile = "pathtoexeordll"
Dim pps As IPropertyStore
Dim pkcm As PROPERTYKEY
DEFINE_PROPERTYKEY pkcm, &HD5CDD502, &H2E9C, &H101B, &H93, &H97, &H8, &H0, &H2B, &H2C, &HF9, &HAE, 15 'System.Company
SHGetPropertyStoreFromParsingName StrPtr(sFile), ByVal 0&, GPS_DEFAULT, IID_IPropertyStore, pps
Dim lpcm As Long
Dim wppd As IPropertyDescription
PSGetPropertyDescription pkcm, IID_IPropertyDescription, wppd
PSFormatPropertyValue ObjPtr(pps), ObjPtr(wppd), PDFF_DEFAULT, lpcm
Debug.Print "Company Name: " & BStrFromLPWStr(lpcm)
Code:Public Declare Function SHGetPropertyStoreFromParsingName Lib "shell32" (ByVal pszPath As Long, pbc As Any, ByVal Flags As GETPROPERTYSTOREFLAGS, _
Public Declare Function PSGetPropertyDescription Lib "propsys.dll" (PropKey As PROPERTYKEY, riid As UUID, ppv As Any) As Long
Public Declare Function PSFormatPropertyValue Lib "propsys.dll" (ByVal pps As Long, ByVal ppd As Long, ByVal pdff As PROPDESC_FORMAT_FLAGS, ppszDisplay As Long) As Long
Public Declare Function SysReAllocString Lib "oleaut32.dll" (ByVal pBSTR As Long, Optional ByVal pszStrPtr As Long) As Long
Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal PV As Long) ' Frees memory allocated by the shell
Public Function BStrFromLPWStr(lpWStr As Long, Optional ByVal CleanupLPWStr As Boolean = True) As String
SysReAllocString VarPtr(BStrFromLPWStr), lpWStr
If CleanupLPWStr Then CoTaskMemFree lpWStr
End Function
Public Sub DEFINE_PROPERTYKEY(Name As PROPERTYKEY, L As Long, w1 As Integer, w2 As Integer, B0 As Byte, b1 As Byte, b2 As Byte, B3 As Byte, b4 As Byte, b5 As Byte, b6 As Byte, b7 As Byte, pid As Long)
With Name.fmtid
.Data1 = L
.Data2 = w1
.Data3 = w2
.Data4(0) = B0
.Data4(1) = b1
.Data4(2) = b2
.Data4(3) = B3
.Data4(4) = b4
.Data4(5) = b5
.Data4(6) = b6
.Data4(7) = b7
End With
Name.pid = pid
End Sub
Public Sub DEFINE_UUID(Name As UUID, L As Long, w1 As Integer, w2 As Integer, B0 As Byte, b1 As Byte, b2 As Byte, B3 As Byte, b4 As Byte, b5 As Byte, b6 As Byte, b7 As Byte)
With Name
.Data1 = L
.Data2 = w1
.Data3 = w2
.Data4(0) = B0
.Data4(1) = b1
.Data4(2) = b2
.Data4(3) = B3
.Data4(4) = b4
.Data4(5) = b5
.Data4(6) = b6
.Data4(7) = b7
End With
End Sub
Public Function IID_IPropertyDescription() As UUID
'(IID_IPropertyDescription, 0x6f79d558, 0x3e96, 0x4549, 0xa1,0xd1, 0x7d,0x75,0xd2,0x28,0x88,0x14
Static IID As UUID
If (IID.Data1 = 0) Then Call DEFINE_UUID(IID, &H6F79D558, CInt(&H3E96), CInt(&H4549), &HA1, &HD1, &H7D, &H75, &HD2, &H28, &H88, &H14)
IID_IPropertyDescription = IID
End Function
Public Function IID_IPropertyStore() As UUID
'DEFINE_GUID(IID_IPropertyStore,0x886d8eeb, 0x8cf2, 0x4446, 0x8d,0x02,0xcd,0xba,0x1d,0xbd,0xcf,0x99);
Static IID As UUID
If (IID.Data1 = 0) Then Call DEFINE_UUID(IID, &H886D8EEB, CInt(&H8CF2), CInt(&H4446), &H8D, &H2, &HCD, &HBA, &H1D, &HBD, &HCF, &H99)
IID_IPropertyStore = IID
End Function
fafalone, yes the companyname
I tried to use your code and used C:\Windows\System32\csrss.exe as sample for sFile but it always crash pointing to propsys.dll. Even if I catch the error, still it crashes.
I'm having a number of problems trying to do anything with that file from VB. That and roughly 25% of .exe files in that folder, VB can't "see" at all; not just this code, but trying to load it into my program via FindFirstFile or INamespaceWalk. This warrants serious further investigation but accessing that file seems to be a far larger issue.
Edit: This issue is even more serious than I thought... I can't even create a pidl for it with ILCreateFromPathW.