Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - ProgID of a exe

Reply
 
Old 09-14-2007   #1 (permalink)
Mugunth


 
 

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 SpecsSystem Spec
Old 09-14-2007   #2 (permalink)
Jeff


 
 

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
I'm sure there is a better way to do this, but this is what I came up
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 SpecsSystem Spec
Old 09-14-2007   #3 (permalink)
Bob Landau


 
 

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 SpecsSystem Spec
Old 09-14-2007   #4 (permalink)
Tao Ma


 
 

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
>
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 SpecsSystem Spec
Old 09-14-2007   #5 (permalink)
Shay Levi


 
 

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
"%iexplore.exe%"' | % {$_.progID}
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>> *"
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 SpecsSystem Spec
Old 09-14-2007   #6 (permalink)
Tao Ma


 
 

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 SpecsSystem Spec
Old 09-14-2007   #7 (permalink)
Shay Levi


 
 

RE: ProgID of a exe

You can also try
Quote:
Quote:

>> get-WMIObject Win32_ClassicCOMClassSetting -filter 'LocalServer32 like
"%iexplore.exe%"' | % {$_.VersionIndependentProgId}
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
>>>
> "%iexplore.exe%"' | % {$_.progID}
> 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>>> *"
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 SpecsSystem Spec
Old 09-14-2007   #8 (permalink)
Shay Levi


 
 

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
>>>
> "%iexplore.exe%"' | % {$_.VersionIndependentProgId}
> 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
>>>>
>> "%iexplore.exe%"' | % {$_.progID}
>> 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>>>> *"
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 SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
ProgID or CLSID )GUID) for Windows Mail ? Vista mail


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46