简体   繁体   English

如何使用C#查找ms word安装路径

[英]how to find ms word installation path using C#

I am trying to get the installation path of ms word through my code so that I can put its icon in my excel sheet generated through my c# code. 我试图通过我的代码获取ms字的安装路径,以便我可以将其图标放在我的ccel代码生成的excel表中。

Tried this but no luck. 试过这个,但没有运气。

Here I am trying to get the icon using the whole word installation oath which I know in my device but I want to generalize it. 在这里,我试图使用我在设备中知道的全字安装誓言获取图标,但我想概括它。

worksheet.Shapes.AddOLEObject(Filename: @"C:\\Users\\BJS\\Desktop\\POC\\wordFile.docx", Height: 80, Width: 90, DisplayAsIcon: true, IconFileName: @"C:\\Program Files (x86)\\Microsoft Office\\Office12\\WINWORD.EXE", IconIndex: 2, IconLabel: "WordFile", Top: _rng.Top, Left: _rng.Left); worksheet.Shapes.AddOLEObject(文件名:@“C:\\ Users \\ BJS \\ Desktop \\ POC \\ wordFile.docx”,高度:80,宽度:90,DisplayAsIcon:true,IconFileName:@“C:\\ Program Files(x86) \\ Microsoft Office \\ Office12 \\ WINWORD.EXE“,IconIndex:2,IconLabel:”WordFile“,Top:_rng.Top,Left:_rng.Left);

Generalize the path which will work for all users 概括将适用于所有用户的路径

I think you can archieve that with the registryeditor. 我认为你可以通过注册管理机构来实现这一目标。 Open the key HKEY_Classes_Root\\Word.Application\\CLSID and save the Key Value. 打开密钥HKEY_Classes_Root\\Word.Application\\CLSID并保存密钥值。 Search it in HKEY_Classes_Root\\WOW6432Node\\CLSID\\{your_value}\\Localserver32 (that's works for x64 systems, for x32 if i remmember right the path is "System" and not "WOW6432Node"). HKEY_Classes_Root\\WOW6432Node\\CLSID\\{your_value}\\Localserver32 (这适用于x64系统,对于x32,如果我正确地重新路由该路径是“系统”而不是“WOW6432Node”)。

For how to read a registrykey in c# you can follow that SO link 有关如何在c#中读取注册表项,您可以关注该SO链接

As @Slai Say, that Will work only if you are Talking of server word Path and not browser user path 正如@Slai Say所说,只有在谈论服务器字路径而不是浏览器用户路径时才能工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM