OpenOffice安装路径 [英] OpenOffice Installed path

查看:133
本文介绍了OpenOffice安装路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我想用c/c ++编写一个程序,该程序将找到OpenOffice.org的安装位置,然后将该位置设置为Windows注册表中的path环境变量.
我在c#中完成了此操作,但由于它是新手,因此无法弄清楚如何在c/c ++中执行此操作.

任何帮助将不胜感激.

thx
阿尔夫

你好,约翰!以下是C#代码:

string SoftwareKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
RegistryKey rk = Registry.LocalMachine.OpenSubKey(SoftwareKey, true);

//Go through the registry keys and get OpenOffice.org
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");// get env. path
Pathvalue = Pathvalue + ";" + path; // append office path to env path

RegistryKey regkey;
regkey= Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment", true);
try
{
   //Set path variable to value
   regkey.SetValue("Path", Pathvalue);
   regkey.Close();
}
catch (Exception ex)
{
}


这样做的原因:
我们正在使用内部构建的软件,需要在环境路径和UNO路径中设置开放式办公室,这样它才能正常工作.我不想为每台客户端PC设置此路径,这会很麻烦.

因此,我需要一种自动执行此操作的方法,这就是为什么我要为此编写程序的原因.
使用c#程序的问题在于,所有客户端计算机都必须至少具有.net Framework 3,才能执行c#.exe.

我正在使用installjammer安装程序来自动运行c#.exe,但首先要检查PC是否已安装.netFramework,否则,installjammer将首先安装框架,然后运行c#.exe.

我的老板告诉我把它报废,并使用简单的东西.他说,仅安装.netFramework来完成设置路径的简单任务没有任何意义.

谢谢

SA,

非常感谢.您的观点很清楚.唯一的问题是我无法避免设置路径. Open Office需要设置UNO路径才能正常工作,并且我们的应用程序与Open Office完全集成.修改开放式办公室源代码使其能够做到这一点确实很痛苦且很耗时,其次我不想手动进行此操作.作为开发人员,您的担心是可以理解的,但是我们的应用程序中有一个卸载程序,该卸载程序可以在卸载后对其进行处理.

解决方案

//for open office 2
OO2Path = "SOFTWARE\\OpenOffice.org\\UNO\\InstallPath";
OO2Key = "";
//for open office 3
OO3Path = "SOFTWARE\\OpenOffice.org\\Layers\\OpenOffice.org\\3";
OO3Key = "OFFICEINSTALLLOCATION";


您可以使用这些字符串并从注册表中检索它们的值,它将包含安装Open-Office的目录的位置...
如果不返回任何内容,则表示未安装OO.
有关读取注册表值的信息,请参见: @ MSDN [


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

//for open office 2
OO2Path = "SOFTWARE\\OpenOffice.org\\UNO\\InstallPath";
OO2Key = "";
//for open office 3
OO3Path = "SOFTWARE\\OpenOffice.org\\Layers\\OpenOffice.org\\3";
OO3Key = "OFFICEINSTALLLOCATION";


You can use these strings and retrieve their values from registry and it will contain location of directory where open-office is installed...
if it returns nothing, that means OO is not installed.. :(

For reading registry values see :
@ MSDN[]

Hope this may help you!!! :)


This is one alternative to using Environment variable:

You can find out where OpenOffice is — you do it already as I understand. After this is done, your installation should run some code creating the application configuration file with a custom parameter showing where OpenOffice is, deploy it through installation. You can have this procedure as a utility, a part of your appliacation, in case the user wants to reinstall OpenOffice. The application should read this configuration file and run having the path to OpenOffice in place.

Please understand that adding Environment variable is discouraged. Who will remove it if your software is uninstalled? There are too many software products contaminated the Registry.

Of course, my advice will not work if you already have a legacy product which uses some Environment variable conventions and you don''t have access to its source code. Should you have any chance to change is — do it as soon as you can, get rid of dirty practices.

—SA


Show us the C# code you use (it shouldn''t be a lot of code).


这篇关于OpenOffice安装路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆