473,414 Members | 1,677 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

how do I Locate an installed applications path the "proper" way from C#?

I am trying to locate an installed application, and I so far have been
unable to do so programattically. There does not appear to be a way to do so
directly from the .NET framework, either 1.1 or 2.0 beta.
Therefore I have tried to use C# and the DllImport attribute to call
MsiGetProductInfo, however it doesnt seem to do anything. I might be using
it incorrectly, can someone check this and/or offer suggestions on something
else to try?
I don't want to just scan the local drives to find the file I am looking
for. call it a pride thing. or a not wanting to get fired for hack-like
code, which the below is already approaching.

/// Dllimport piece:
[DllImport("msi.dll", SetLastError=true, CharSet=CharSet.Auto)]
public static extern uint MsiGetProductInfo(
[MarshalAs(UnmanagedType.LPTStr)] String szProduct,
[MarshalAs(UnmanagedType.LPTStr)] String szProperty,
StringBuilder lpValueBuf,
ref Int32 pcchValueBuf);

////the part that calls MsiGetProductInfo:
public string GetInstallLocation(string ProductCode)
{
Int32 iSize = 256;
StringBuilder sb = new StringBuilder(iSize);
try
{
LogMsg("sizeof iSize is " + iSize.ToString());
MsiGetProductInfo(ProductCode, "INSTALLPROPERTY_INSTALLLOCATION", sb, ref
iSize);
sb.EnsureCapacity(iSize);
LogMsg("sizeof iSize is " + iSize.ToString());
MsiGetProductInfo(ProductCode, "INSTALLPROPERTY_INSTALLLOCATION", sb, ref
iSize);
LogMsg("contents of sb is " + sb.ToString());
}
catch (Exception e)
{
DumpException(e);
}
return sb.ToString();
}

//// the output:
/// sizeof iSize is 256
/// sizeof iSize is 256
/// contents of sb is
Nov 17 '05 #1
1 5472
I think there is a way, however you will still search your drives.
Albeit in a targetted way.

The registry key
MyComputer/HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Installer/Folders
has as sub keys all of the folders where software has been installed.
Of course this assumes that your software was installed using the
Microsoft Windows installer.

Hope this helps...

Christian Gross

seanick wrote:
I am trying to locate an installed application, and I so far have been
unable to do so programattically. There does not appear to be a way to do so
directly from the .NET framework, either 1.1 or 2.0 beta.
Therefore I have tried to use C# and the DllImport attribute to call
MsiGetProductInfo, however it doesnt seem to do anything. I might be using
it incorrectly, can someone check this and/or offer suggestions on something
else to try?
I don't want to just scan the local drives to find the file I am looking
for. call it a pride thing. or a not wanting to get fired for hack-like
code, which the below is already approaching.

/// Dllimport piece:
[DllImport("msi.dll", SetLastError=true, CharSet=CharSet.Auto)]
public static extern uint MsiGetProductInfo(
[MarshalAs(UnmanagedType.LPTStr)] String szProduct,
[MarshalAs(UnmanagedType.LPTStr)] String szProperty,
StringBuilder lpValueBuf,
ref Int32 pcchValueBuf);

////the part that calls MsiGetProductInfo:
public string GetInstallLocation(string ProductCode)
{
Int32 iSize = 256;
StringBuilder sb = new StringBuilder(iSize);
try
{
LogMsg("sizeof iSize is " + iSize.ToString());
MsiGetProductInfo(ProductCode, "INSTALLPROPERTY_INSTALLLOCATION", sb, ref
iSize);
sb.EnsureCapacity(iSize);
LogMsg("sizeof iSize is " + iSize.ToString());
MsiGetProductInfo(ProductCode, "INSTALLPROPERTY_INSTALLLOCATION", sb, ref
iSize);
LogMsg("contents of sb is " + sb.ToString());
}
catch (Exception e)
{
DumpException(e);
}
return sb.ToString();
}

//// the output:
/// sizeof iSize is 256
/// sizeof iSize is 256
/// contents of sb is

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: DKode | last post by:
I have created an application that will be used for my IT depts. Tasks. I believe I have created the correct architecture but it doesn't feel correct. Could I get opionions if I am headed in the...
1
by: Rick Brown | last post by:
I'm trying to scan a barcode that contains the text string "BPWOT08762" into a textbox for use in a DLookup or query grid. I want to look thru a table's field that contains the last 6 characters...
1
by: Bill Woodruff | last post by:
As an exercise I wrote a small C# program to download several hundred text files of guitar tab music by parsing the home page of the site and retrieving all the links to the music text files and...
7
by: mwt | last post by:
Is there a function in python that does what "locate" does in a bash shell? I know I could do it by using os.popen('locate'), but I'm curious if there's a Python "native" way to go about it....
14
by: noridotjabi | last post by:
Two questions. 1)Is there any way that I can read from an executable and then execute what I have read. EXAMPLE: text text this is more text
7
by: Erik Funkenbusch | last post by:
I've been thinking about different ways to address this problem, and I figured i'd just toss this out and see if anyone has a good solution. I've got database field of type char(1), this field...
1
by: MJR | last post by:
Could anyone please help me change data in uppercase to data in propercase in MS Access?
15
by: Richard | last post by:
Can anyone recommend a good online resource listing all C keywords, standard system calls, defines etc in a "flat" hierarchy. I wish to set up some bindings in order to bring up "hints and tips"...
0
by: Russell Warren | last post by:
I'm running python 2.5.1 and it seems that SimpleXmlRpcServer is not setup to support the base datetime module in the same way xmlrpclib has been with "use_datetime". I see that someone (Virgil...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.