HI!
I want to write a program in c/c++ that will find the installed location of OpenOffice.org and then set that location to the path environment variable in windows registry.
I did this in c# but cannot figure out how to do it in c/c++ since am new to it.
Any help will highly be appreciated.
thx
alfu
Hi John! Below is the c# code:
string SoftwareKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
RegistryKey rk = Registry.LocalMachine.OpenSubKey(SoftwareKey, true);
foreach (string skName in rk.GetSubKeyNames())
{
RegistryKey sk = rk.OpenSubKey(skName);
try
{
if (Regex.IsMatch((sk.GetValue("DisplayName")).ToString(), "OpenOffice.org", RegexOptions.IgnoreCase))
{
path = "" + sk.GetValue("InstallLocation") + sk.GetValue("DisplayName");
}
}
catch (Exception ex)
{
}
string Pathvalue = "";
Pathvalue = Environment.GetEnvironmentVariable("Path");
Pathvalue = Pathvalue + ";" + path;
RegistryKey regkey;
regkey= Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment", true);
try
{
regkey.SetValue("Path", Pathvalue);
regkey.Close();
}
catch (Exception ex)
{
}
Reason for doing this:
We are using a software that we build in house that needs open office to be set in the environment path and UNO path, so that it can work. What I do not want to do is to set this path for each client PC which will be painful.
Therefore, I need a way to do it automatically and this is why I want to write a program for it.
The problem with using the c# program is that all client machines must have .net framework 3 atleast for the c# .exe to execute.
I am using the installjammer installer to automatically run the c# .exe but I first check if the PC has .netFramework installed, and if not, installjammer will first install the framework and then run the c# .exe.
My boss told me to scrap it and use something simple. He said it doesnt make sense to install .netFramework just for achieving a simple task of setting a path.
Thanks
SA,
Many thanks. Your point is well noted. The only problem is I cannot avoid setting the path. Open Office needs UNO path to be set inorder for it to work and our application fully integrates with Open Office. It will a real pain and time consuming to modify the open office source code for it to be able to do that and second I dont want to be doing this manually. Your concern is understandable as a developer, but our application has an uninstaller which takes care of that once it is uninstalled