internal static bool IsAppInstalled(OfficeApp app) { try { var keyName = ""; switch (app) { case OfficeApp.Outlook: keyName = OUTLOOK_APP; break; case OfficeApp.Excel: keyName = EXCEL_APP; break; case OfficeApp.Word: keyName = WORD_APP; break; } var key = Registry.ClassesRoot; var subKey = key.OpenSubKey(keyName); return(subKey != null); } catch (Exception ex) { PNStatic.LogException(ex); return(false); } }
internal static int GetOfficeAppVersion(OfficeApp app) { try { var filePath = getOfficeComponentPath(app); return(filePath == "" ? 0 : PNStatic.GetFileMajorVersion(filePath)); } catch (Exception ex) { PNStatic.LogException(ex); return(0); } }
//public static UtilOffice ObjOffice; #endregion /// <summary> /// SprawdŸ, czy jest zainstalowany Microsoft Office /// </summary> /// <param name="app"></param> /// <param name="ver"></param> /// <returns></returns> /// <example></example> public static bool IsInstalled(OfficeApp app, OfficeVer ver) { string userRoot = "HKEY_LOCAL_MACHINE"; string verName = GetVersionName(ver); string appName = GetApplicationName(app); string subkey = string.Format(@"Software\Microsoft\Office\{0}\{1}\InstallRoot", verName, appName); string keyName = userRoot + "\\" + subkey; return((string)Registry.GetValue(keyName, "Path", null) != null); }
public override bool ProcessWordByWord(OfficeDocumentProcessor aWordProcessor) { Document.MoveFirst(); // to avoid an error on the first 'Edit' int nDontCare = 0; // don't care while (!Document.EOF) { Fields aFields = Document.Fields; Field aField = aFields[m_strFieldName]; if (aField.Value != System.DBNull.Value) { AccessRange aWordRange = new AccessRange(aField, this); try { if (!aWordProcessor.Process(aWordRange, ref nDontCare)) { return(false); } } catch (Exception) { throw; } finally { // this gets called whether we successfully process the word or not, // whether we're returning 'false' (in the try) or not, and whether we // have an exception or not... just exactly what we want, or MSAccess // process won't release when we exit. OfficeApp.ReleaseComObject(aField); OfficeApp.ReleaseComObject(aFields); } } Document.MoveNext(); } return(true); }
public DbFieldSelect(TableDefs aTableDefs) { InitializeComponent(); for (int i = 0; i < aTableDefs.Count; i++) { TableDef aTable = aTableDefs[i]; if (aTable.Attributes == 0) { TreeNode node = this.treeViewTablesFields.Nodes.Add(aTable.Name); Fields aFields = aTable.Fields; for (int j = 0; j < aFields.Count; j++) { Field aField = aFields[j]; node.Nodes.Add(aField.Name); OfficeApp.ReleaseComObject(aField); // needed or Access stays running after exit } OfficeApp.ReleaseComObject(aFields); } OfficeApp.ReleaseComObject(aTable); } }
private static string getOfficeComponentPath(OfficeApp app) { try { const string regKey = @"Software\Microsoft\Windows\CurrentVersion\App Paths"; const string regKey64 = @"Software\Wow6432Node\Microsoft\Windows\CurrentVersion\App Paths"; var exeName = ""; switch (app) { case OfficeApp.Outlook: exeName = OUTLOOK_EXE; break; case OfficeApp.OneNote: exeName = ONENOTE_EXE; break; case OfficeApp.Excel: exeName = EXCEL_EXE; break; case OfficeApp.Word: exeName = WORD_EXE; break; } //try current user using (var key = Registry.CurrentUser) { using (var subKey = key.OpenSubKey(regKey + "\\" + exeName, false)) { if (subKey != null && subKey.ValueCount > 0) { return(subKey.GetValue("").ToString()); } } } //try local machine using (var key = Registry.LocalMachine) { using (var subKey = key.OpenSubKey(regKey + "\\" + exeName, false)) { if (subKey != null && subKey.ValueCount > 0) { return(subKey.GetValue("").ToString()); } } } //try local machine for x64 using (var key = Registry.LocalMachine) { using (var subKey = key.OpenSubKey(regKey64 + "\\" + exeName, false)) { if (subKey != null && subKey.ValueCount > 0) { return(subKey.GetValue("").ToString()); } } } return(""); } catch (NullReferenceException nex) { PNStatic.LogException(nex, false); return(""); } catch (Exception ex) { PNStatic.LogException(ex); return(""); } }
public OfficeController(IFactoryConnection connection) { _connection = connection; _OfficeApp = new OfficeApp(connection); }
private static string GetApplicationName(OfficeApp app) { return(Enum.GetName(typeof(OfficeApp), app)); }
private static string getOfficeComponentPath(OfficeApp app) { try { const string regKey = @"Software\Microsoft\Windows\CurrentVersion\App Paths"; const string regKey64 = @"Software\Wow6432Node\Microsoft\Windows\CurrentVersion\App Paths"; var exeName = ""; switch (app) { case OfficeApp.Outlook: exeName = OUTLOOK_EXE; break; case OfficeApp.OneNote: exeName = ONENOTE_EXE; break; case OfficeApp.Excel: exeName = EXCEL_EXE; break; case OfficeApp.Word: exeName = WORD_EXE; break; } //try current user using (var key = Registry.CurrentUser) { using (var subKey = key.OpenSubKey(regKey + "\\" + exeName, false)) { if (subKey != null && subKey.ValueCount > 0) { return subKey.GetValue("").ToString(); } } } //try local machine using (var key = Registry.LocalMachine) { using (var subKey = key.OpenSubKey(regKey + "\\" + exeName, false)) { if (subKey != null && subKey.ValueCount > 0) { return subKey.GetValue("").ToString(); } } } //try local machine for x64 using (var key = Registry.LocalMachine) { using (var subKey = key.OpenSubKey(regKey64 + "\\" + exeName, false)) { if (subKey != null && subKey.ValueCount > 0) { return subKey.GetValue("").ToString(); } } } return ""; } catch (NullReferenceException nex) { PNStatic.LogException(nex, false); return ""; } catch (Exception ex) { PNStatic.LogException(ex); return ""; } }
internal static bool IsAppInstalled(OfficeApp app) { try { var keyName = ""; switch (app) { case OfficeApp.Outlook: keyName = OUTLOOK_APP; break; case OfficeApp.Excel: keyName = EXCEL_APP; break; case OfficeApp.Word: keyName = WORD_APP; break; } var key = Registry.ClassesRoot; var subKey = key.OpenSubKey(keyName); return subKey != null; } catch (Exception ex) { PNStatic.LogException(ex); return false; } }
internal static int GetOfficeAppVersion(OfficeApp app) { try { var filePath = getOfficeComponentPath(app); return filePath == "" ? 0 : PNStatic.GetFileMajorVersion(filePath); } catch (Exception ex) { PNStatic.LogException(ex); return 0; } }