论坛风格切换切换到宽版
  • 2735阅读
  • 7回复

请教老虎版主获取路径问题? [复制链接]

上一主题 下一主题
离线546242502
 

发帖
332
金钱
-3060
威望
-306
只看楼主 倒序阅读 0 发表于: 2015-09-21
用户被禁言,该主题自动屏蔽!
离线gnatix

发帖
7696
金钱
-8279
威望
-828
只看该作者 1 发表于: 2015-09-21
你的函数搞得很乱,请标明哪个函数是读取哪个软件的(MW Office 或者 WPS)。
GetPath 读取 MS Office 安装路径?
Getversion 读取 MS Office 版本?
GetPathII 读取 WPS 安装路径?

WPS 我从来没有安装过,不知道注册表里面的具体内容。但是 MS Office 在注册表里面好像不是使用 InstallLocation 键。请仔细检查一下你的代码。
离线gnatix

发帖
7696
金钱
-8279
威望
-828
只看该作者 2 发表于: 2015-09-21
  1. function GetPath(Param: String): String;        // 读取 MS Office 安装路径
  2. var
  3. i, j: Integer;
  4. strPath: String;
  5. subkeynames1, subkeynames2: TArrayOfString;
  6. begin
  7.   strPath:=ExpandConstant('LH-U');
  8.   if RegGetSubkeyNames(HKLM32, 'SOFTWARE\Microsoft\Office', subkeynames1) then
  9.     for i:= 0 to GetArrayLength(subkeynames1)-1 do
  10.      if RegGetSubkeyNames(HKLM32, 'SOFTWARE\Microsoft\Office\'+subkeynames1[i], subkeynames2) then
  11.         for j:= 0 to  GetArrayLength(subkeynames2)-1 do
  12.           if RegQueryStringValue(HKLM32, 'SOFTWARE\Microsoft\Office\'+subkeynames1[i]+'\'+subkeynames2[j]+'\InstallRoot', 'Path', strPath) then
  13.             strPath:=strPath;
  14.   if RegGetSubkeyNames(HKLM64, 'SOFTWARE\Microsoft\Office', subkeynames1) then
  15.     for i:= 0 to GetArrayLength(subkeynames1)-1 do
  16.      if RegGetSubkeyNames(HKLM64, 'SOFTWARE\Microsoft\Office\'+subkeynames1[i], subkeynames2) then
  17.         for j:= 0 to  GetArrayLength(subkeynames2)-1 do
  18.           if RegQueryStringValue(HKLM64, 'SOFTWARE\Microsoft\Office\'+subkeynames1[i]+'\'+subkeynames2[j]+'\InstallRoot', 'Path', strPath) then
  19.             strPath:=strPath;
  20.   Result:= strPath;
  21. end;
  22. function Getversion(Param: String): String;   // // 读取 MS Office 版本
  23. var
  24. i, j: Integer;
  25. oversion: String;
  26. subkeynames1, subkeynames2: TArrayOfString;
  27. begin
  28. oversion := ExpandConstant('LH-U');
  29. if RegKeyExists(HKLM32, 'SOFTWARE\Microsoft\Office') then
  30. begin
  31. if RegGetSubkeyNames(HKLM32, 'SOFTWARE\Microsoft\Office', subkeynames1) then
  32.     for i:= 0 to GetArrayLength(subkeynames1)-1 do
  33.      if RegGetSubkeyNames(HKLM32, 'SOFTWARE\Microsoft\Office\'+subkeynames1[i], subkeynames2) then
  34.         for j:= 0 to  GetArrayLength(subkeynames2)-1 do
  35.           if RegQueryStringValue(HKLM32, 'SOFTWARE\Microsoft\Office\'+subkeynames1[i]+'\'+subkeynames2[j]+'\ProductVersion', 'LastProduct', oversion) then
  36.             oversion:=copy(oversion,1,pos('.', oversion)-1);
  37. end;
  38. if RegKeyExists(HKLM64, 'SOFTWARE\Microsoft\Office') then
  39. begin
  40. if RegGetSubkeyNames(HKLM64, 'SOFTWARE\Microsoft\Office', subkeynames1) then
  41.     for i:= 0 to GetArrayLength(subkeynames1)-1 do
  42.      if RegGetSubkeyNames(HKLM64, 'SOFTWARE\Microsoft\Office\'+subkeynames1[i], subkeynames2) then
  43.         for j:= 0 to  GetArrayLength(subkeynames2)-1 do
  44.           if RegQueryStringValue(HKLM64, 'SOFTWARE\Microsoft\Office\'+subkeynames1[i]+'\'+subkeynames2[j]+'\ProductVersion', 'LastProduct', oversion) then
  45.             oversion:=copy(oversion,1,pos('.', oversion)-1);
  46. end;
  47. Result:= oversion;
  48. end;


离线546242502

发帖
332
金钱
-3060
威望
-306
只看该作者 3 发表于: 2015-09-21
用户被禁言,该主题自动屏蔽!
离线gnatix

发帖
7696
金钱
-8279
威望
-828
只看该作者 4 发表于: 2015-09-22
WPS 信息最好从 HKEY_LOCAL_MACHINE\SOFTWARE\Kingsoft\Office\x.x\common 读取。
  1. function GetPath(Param: String): String;        // 读取 MS Office 安装路径
  2. var
  3.   i: Integer;
  4.   strPath: String;
  5.   subkeynames1: TArrayOfString;
  6. begin
  7.   strPath:=ExpandConstant('LH-U');
  8.   if RegGetSubkeyNames(HKLM32, 'SOFTWARE\Microsoft\Office', subkeynames1) then
  9.     for i:= 0 to GetArrayLength(subkeynames1)-1 do
  10.       if RegKeyExists(HKLM32, 'SOFTWARE\Microsoft\Office\'+subkeynames1[i]+'\common\InstallRoot') then
  11.         if RegQueryStringValue(HKLM32, 'SOFTWARE\Microsoft\Office\'+subkeynames1[i]++'\common\InstallRoot', 'Path', strPath) then
  12.           strPath:=strPath;
  13.   if RegGetSubkeyNames(HKLM64, 'SOFTWARE\Microsoft\Office', subkeynames1) then
  14.     for i:= 0 to GetArrayLength(subkeynames1)-1 do
  15.       if RegKeyExists(HKLM64, 'SOFTWARE\Microsoft\Office\'+subkeynames1[i]+'\common\InstallRoot') then
  16.         if RegQueryStringValue(HKLM64, 'SOFTWARE\Microsoft\Office\'+subkeynames1[i]++'\common\InstallRoot', 'Path', strPath) then
  17.           strPath:=strPath;
  18.   Result:= strPath;
  19. end;
  20. function Getversion(Param: String): String;   //读取 MS Office 主版本号
  21. var
  22.   i: Integer;
  23.   oversion: String;
  24.   subkeynames1: TArrayOfString;
  25. begin
  26.   oversion := ExpandConstant('LH-U');
  27.   if RegKeyExists(HKLM32, 'SOFTWARE\Microsoft\Office') then
  28.     begin
  29.       if RegGetSubkeyNames(HKLM32, 'SOFTWARE\Microsoft\Office', subkeynames1) then
  30.         for i:= 0 to GetArrayLength(subkeynames1)-1 do
  31.           if RegKeyExists(HKLM32, 'SOFTWARE\Microsoft\Office\'+subkeynames1[i]+'\common\ProductVersion') then
  32.             if RegQueryStringValue(HKLM32, 'SOFTWARE\Microsoft\Office\'+subkeynames1[i]+'\common\ProductVersion', 'LastProduct', oversion) then
  33.               oversion:=copy(oversion,1,pos('.', oversion)-1);
  34.     end;
  35.   if RegKeyExists(HKLM64, 'SOFTWARE\Microsoft\Office') then
  36.     begin
  37.       if RegGetSubkeyNames(HKLM64, 'SOFTWARE\Microsoft\Office', subkeynames1) then
  38.         for i:= 0 to GetArrayLength(subkeynames1)-1 do
  39.           if RegKeyExists(HKLM64, 'SOFTWARE\Microsoft\Office\'+subkeynames1[i]+'\common\ProductVersion') then
  40.             if RegQueryStringValue(HKLM64, 'SOFTWARE\Microsoft\Office\'+subkeynames1[i]+'\common\ProductVersion', 'LastProduct', oversion) then
  41.               oversion:=copy(oversion,1,pos('.', oversion)-1);
  42.     end;
  43.   Result:= oversion;
  44. end;
  45. function GetPathII(Param: String): String;       //读取 WPS Office 安装路径
  46. var
  47.   i: Integer;
  48.   strPath: String;
  49.   subkeynames1: TArrayOfString;
  50. begin
  51.   strPath:=ExpandConstant('LH-U');
  52.   if RegGetSubkeyNames(HKLM32, 'SOFTWARE\Kingsoft\Office', subkeynames1) then
  53.     for i:= 0 to GetArrayLength(subkeynames1)-1 do
  54.       if RegKeyExists(HKLM32, 'SOFTWARE\Microsoft\Office\'+subkeynames1[i]+'\common') then
  55.         if RegQueryStringValue(HKLM32, 'SOFTWARE\Kingsoft\Office\'+subkeynames1[i]+'\common', 'InstallRoot', strPath) then
  56.             strPath:=strPath;
  57.   if RegGetSubkeyNames(HKLM64, 'SOFTWARE\Kingsoft\Office', subkeynames1) then
  58.     for i:= 0 to GetArrayLength(subkeynames1)-1 do
  59.       if RegKeyExists(HKLM64, 'SOFTWARE\Kingsoft\Office\'+subkeynames1[i]+'\common') then
  60.         if RegQueryStringValue(HKLM64, 'SOFTWARE\Kingsoft\Office\'+subkeynames1[i]+'\common', 'InstallRoot', strPath) then
  61.             strPath:=strPath;
  62.   Result:= strPath;
  63. end;
  64. function GetversionII(Param: String): String;       //读取 WPS Office 主版本号
  65. var
  66.   i: Integer;
  67.   oversion: String;
  68.   subkeynames1: TArrayOfString;
  69. begin
  70.   oversion:=ExpandConstant('LH-U');
  71.   if RegGetSubkeyNames(HKLM32, 'SOFTWARE\Kingsoft\Office', subkeynames1) then
  72.     for i:= 0 to GetArrayLength(subkeynames1)-1 do
  73.       if RegKeyExists(HKLM32, 'SOFTWARE\Kingsoft\Office\'+subkeynames1[i]+'\common') then
  74.         if RegQueryStringValue(HKLM32, 'SOFTWARE\Kingsoft\Office\'+subkeynames1[i]+'\common', 'Version', oversion) then
  75.             oversion:=copy(oversion,1,pos('.', oversion)-1);
  76.   if RegGetSubkeyNames(HKLM64, 'SOFTWARE\Kingsoft\Office', subkeynames1) then
  77.     for i:= 0 to GetArrayLength(subkeynames1)-1 do
  78.       if RegKeyExists(HKLM64, 'SOFTWARE\Kingsoft\Office\'+subkeynames1[i]+'\common') then
  79.         if RegQueryStringValue(HKLM64, 'SOFTWARE\Kingsoft\Office\'+subkeynames1[i]+'\common', 'Version', oversion) then
  80.             oversion:=copy(oversion,1,pos('.', oversion)-1);
  81.   Result:= oversion;
  82. end;



离线546242502

发帖
332
金钱
-3060
威望
-306
只看该作者 5 发表于: 2015-09-22
用户被禁言,该主题自动屏蔽!
离线gnatix

发帖
7696
金钱
-8279
威望
-828
只看该作者 6 发表于: 2015-09-23
就凭 WPS 在注册表里面写东西的乱哄劲,只能说这种垃圾东西不用也罢。
如果 WPS 也是往 MS 里面写东西,那么你只能先假设是 MS,然后检查相应的程序文件是否存在,再假设是 WPS,然后检查相应的程序文件是否存在。

离线546242502

发帖
332
金钱
-3060
威望
-306
只看该作者 7 发表于: 2015-09-24
用户被禁言,该主题自动屏蔽!