![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | ProgID of a exe Is it possible to get the ProgID of an executable whose path is known? For example, I want to get InternetExplorer.Application if I pass iexplore.exe (full path)... Regards, Mugunth |
My System Specs![]() |
| | #2 (permalink) |
| | Re: ProgID of a exe On Sep 14, 2:54 pm, Mugunth <mugunth.ku...@xxxxxx> wrote: Quote: > Is it possible to get the ProgID of an executable whose path is > known? > For example, I want to get > InternetExplorer.Application if I pass iexplore.exe (full path)... > > Regards, > Mugunth with: ## Get-ProgId.ps1 param( [string]$filePath = $( throw "You must provide a path to a COM server." ), [switch]$ShowProgress ) if ( !( Test-Path "$( Get-Location)\PathShortener.dll" ) ) { $code = @' using System; using System.Text; using System.Runtime.InteropServices; public class PathShortener { [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern int GetShortPathName( [MarshalAs( UnmanagedType.LPTStr )] string lpszLongPath, [MarshalAs( UnmanagedType.LPTStr )] StringBuilder lpszShortPath, uint cchBuffer); public static string GetShortPath( string longPath ) { string shortPath = longPath; StringBuilder shortPathBuilder = new StringBuilder(260); int result = GetShortPathName( longPath, shortPathBuilder, (uint)shortPathBuilder.Capacity ); if ( result > 0 ) { shortPath = shortPathBuilder.ToString(); } return shortPath; } } '@ $cSharpCodeProvider = New-Object Microsoft.CSharp.CSharpCodeProvider $parameters = New-Object System.CodeDom.Compiler.CompilerParameters $parameters.GenerateInMemory = $true $parameters.GenerateExecutable = $false $parameters.OutputAssembly = "$( Get-Location)\PathShortener.dll" $compilerResults = $cSharpCodeProvider.CompileAssemblyFromSource( $parameters, $code ) if ( $results.Errors.Count -gt 0 ) { Throw "Could not compile PathShortener class" } } [System.Reflection.Assembly]::LoadFile( "$( Get-Location) \PathShortener.dll" ) | Out-Null $longPath = $filePath.ToLower() $shortPath = [PathShortener]::GetShortPath( $filePath ).ToLower() if ( ( New-Object System.IO.FileInfo $longPath ).Extension.ToLower() - eq ".exe" ) { $serverKeys = Get-Item HKLM:\SOFTWARE\Classes\CLSID\* \LocalServer32 } else { $serverKeys = Get-Item HKLM:\SOFTWARE\Classes\CLSID\* \InProcServer32 } $serverCount = $serverKeys.Length $serverProgress = 0; foreach ( $serverKey in $serverKeys ) { if ( $ShowProgress ) { Write-Progress -Activity "Searching servers for '$filePath'..." ` -Status "Progress:" ` -PercentComplete ( ( $serverProgress++ / $serverCount ) * 100 ) } if ( $serverKey.GetValue( "" ) ) { $foundPath = $serverKey.GetValue( "" ).ToLower() -replace '"' if ( $foundPath -eq $longPath -or $foundPath -eq $shortPath ) { if ( $serverKey.PSPath -match "\\([^\\]+)\\[^\\]+$" ) { $clsid = $matches[ 1 ].ToLower() $clsidKeys = Get-Item HKLM:\SOFTWARE\Classes\*\CLSID $clsidCount = $clsidKeys.Length $clsidProgress = 0 foreach ( $clsidKey in $clsidKeys ) { if ( $ShowProgress ) { Write-Progress -Activity "Searching CLSIDs for '$clsid'..." ` -Status "Progress:" ` -PercentComplete ( ( $clsidProgress++ / $clsidCount ) * 100 )` -Id 1 } if ( $clsidKey.GetValue( "" ) -and $clsidKey.GetValue( "" ).ToLower() -eq $clsid ) { if ( $clsidKey.PSPath -match "\\([^\\]+)\\CLSID $" ) { $matches[ 1 ] } } } } } } } ## Get-ProgId.ps1 Use it like this: PSH$ .\Get-ProgId.ps1 'C:\Program Files\Internet Explorer \iexplore.exe' -ShowProgress This attempts to list all ProgIds associated with the file passed in as a parameter. I say "attempts" because I am sure I missed something. I had to put the GetShortPathName call in because short paths are used quite often in the registry. It is really slow, but it seems to do the trick. I added a switch parameter that determines whether progress is displayed, since Write-Progress calls slow it down so much more. Jeff |
My System Specs![]() |
| | #3 (permalink) |
| | RE: ProgID of a exe Since I've started playing with WMI I've found that there is a class which will list literally ANYTHING which is on a machine. get-WMIObject Win32_ClassicCOMClassSetting | ? {$_.ProgId -like "*expl*"} will get you started. This class has all the properites you need. The hard part of course if _finding_ which class to use. This appears to take experience and looking through the doc's. get-WMIObject -list | ? {$.name -like "*<sub string of the thing your after>*" can help. Good luck bob "Mugunth" wrote: Quote: > Is it possible to get the ProgID of an executable whose path is > known? > For example, I want to get > InternetExplorer.Application if I pass iexplore.exe (full path)... > > Regards, > Mugunth > > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: ProgID of a exe "Mugunth" <mugunth.kumar@xxxxxx> wrote in message news:1189756456.365177.238200@xxxxxx Quote: > Is it possible to get the ProgID of an executable whose path is > known? > For example, I want to get > InternetExplorer.Application if I pass iexplore.exe (full path)... > > Regards, > Mugunth > PS C:\> Get-Process | ?{$_.path -eq 'C:\Program Files\Alcohol Soft\Alcohol 120\StarWind\StarWindService.exe'} | %{$_.id} Tao Ma Best wishes! |
My System Specs![]() |
| | #5 (permalink) |
| | RE: ProgID of a exe Slick! To narrow down the returned results, use the get-WMIObject -filter parameter Quote: Quote: >> get-WMIObject Win32_ClassicCOMClassSetting -filter 'LocalServer32 like InternetExplorer.Application.1 Shay http://scriptolog.blogspot.com Quote: > Since I've started playing with WMI I've found that there is a class > which will list literally ANYTHING which is on a machine. > > get-WMIObject Win32_ClassicCOMClassSetting | ? {$_.ProgId -like > "*expl*"} > > will get you started. This class has all the properites you need. > > The hard part of course if _finding_ which class to use. This appears > to take experience and looking through the doc's. > > get-WMIObject -list | ? {$.name -like "*<sub string of the thing your > after>> Quote: > can help. > > Good luck > bob > "Mugunth" wrote: > Quote: >> Is it possible to get the ProgID of an executable whose path is >> known? >> For example, I want to get >> InternetExplorer.Application if I pass iexplore.exe (full path)... >> Regards, >> Mugunth |
My System Specs![]() |
| | #6 (permalink) |
| | Re: ProgID of a exe sorry, this is wrong answer... "Tao Ma" <feng_eden@xxxxxx> wrote in message news:ED919A5B-F372-404A-82DD-176CDF9C7B61@xxxxxx Quote: > "Mugunth" <mugunth.kumar@xxxxxx> wrote in message > news:1189756456.365177.238200@xxxxxx Quote: >> Is it possible to get the ProgID of an executable whose path is >> known? >> For example, I want to get >> InternetExplorer.Application if I pass iexplore.exe (full path)... >> >> Regards, >> Mugunth >> > I hope this trivial code may help you. > > PS C:\> Get-Process | ?{$_.path -eq 'C:\Program Files\Alcohol Soft\Alcohol > 120\StarWind\StarWindService.exe'} | %{$_.id} > > > Tao Ma > Best wishes! |
My System Specs![]() |
| | #7 (permalink) |
| | RE: ProgID of a exe You can also try Quote: Quote: >> get-WMIObject Win32_ClassicCOMClassSetting -filter 'LocalServer32 like InternetExplorer.Application Shay http://scriptolog.blogspot.com Quote: > Slick! > > To narrow down the returned results, use the get-WMIObject -filter > parameter > Quote: Quote: >>> get-WMIObject Win32_ClassicCOMClassSetting -filter 'LocalServer32 >>> like >>> > InternetExplorer.Application.1 > Shay > http://scriptolog.blogspot.com Quote: >> Since I've started playing with WMI I've found that there is a class >> which will list literally ANYTHING which is on a machine. >> >> get-WMIObject Win32_ClassicCOMClassSetting | ? {$_.ProgId -like >> "*expl*"} >> >> will get you started. This class has all the properites you need. >> >> The hard part of course if _finding_ which class to use. This appears >> to take experience and looking through the doc's. >> >> get-WMIObject -list | ? {$.name -like "*<sub string of the thing >> your >> after>>> Quote: Quote: >> can help. >> >> Good luck >> bob >> "Mugunth" wrote: Quote: >>> Is it possible to get the ProgID of an executable whose path is >>> known? >>> For example, I want to get >>> InternetExplorer.Application if I pass iexplore.exe (full path)... >>> Regards, >>> Mugunth |
My System Specs![]() |
| | #8 (permalink) |
| | RE: ProgID of a exe Just to clarify ![]() % = foreach-object Shay http://scriptolog.blogspot.com Quote: > You can also try > Quote: Quote: >>> get-WMIObject Win32_ClassicCOMClassSetting -filter 'LocalServer32 >>> like >>> > InternetExplorer.Application > > Shay > http://scriptolog.blogspot.com Quote: >> Slick! >> >> To narrow down the returned results, use the get-WMIObject -filter >> parameter >> Quote: >>>> get-WMIObject Win32_ClassicCOMClassSetting -filter 'LocalServer32 >>>> like >>>> >> InternetExplorer.Application.1 >> Shay >> http://scriptolog.blogspot.com Quote: >>> Since I've started playing with WMI I've found that there is a class >>> which will list literally ANYTHING which is on a machine. >>> >>> get-WMIObject Win32_ClassicCOMClassSetting | ? {$_.ProgId -like >>> "*expl*"} >>> >>> will get you started. This class has all the properites you need. >>> >>> The hard part of course if _finding_ which class to use. This >>> appears to take experience and looking through the doc's. >>> >>> get-WMIObject -list | ? {$.name -like "*<sub string of the thing >>> your >>> after>>>> Quote: Quote: Quote: >>> can help. >>> >>> Good luck >>> bob >>> "Mugunth" wrote: >>>> Is it possible to get the ProgID of an executable whose path is >>>> known? >>>> For example, I want to get >>>> InternetExplorer.Application if I pass iexplore.exe (full path)... >>>> Regards, >>>> Mugunth |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| ProgID or CLSID )GUID) for Windows Mail ? | Vista mail | |||