public static RegistryKey CreateSubKey(this RegistryKey mainKey, string name, WOW_Mode mode) { SafeRegistryHandle resultingKey; RegResult regResult; RegSAM sam = RegSAM.Write | RegSAM.Read | RegSAM.QueryValue; if (mode == WOW_Mode.Reg32) sam |= RegSAM.WOW64_32Key; else if (mode == WOW_Mode.Reg64) sam |= RegSAM.WOW64_64Key; Advapi32Func.RegCreateKeyEx( mainKey.Handle, name, 0, null, RegOption.NonVolatile, sam, IntPtr.Zero, out resultingKey, out regResult); return RegistryKey.FromHandle(resultingKey); }
private void Unregister(RegistryKey rootKey, WOW_Mode wowMode) { var keySW = rootKey.CreateSubKey("Software", wowMode); var keyCR = keySW.CreateSubKey("Classes", wowMode); var keyCLSID = keyCR.CreateSubKey("CLSID", wowMode); var keyApp = keyCR.CreateSubKey("AppID", wowMode); keyCR.DeleteSubKeyTree(".axoprj", false); keyCR.DeleteSubKeyTree("Altaxo.Project", false); keyCLSID.DeleteSubKeyTree(typeof(ProjectFileComObject).GUID.ToString("B").ToUpperInvariant(), false); keyCR.DeleteSubKeyTree(GraphDocumentEmbeddedComObject.USER_TYPE, false); keyCLSID.DeleteSubKeyTree(typeof(GraphDocumentEmbeddedComObject).GUID.ToString("B").ToUpperInvariant(), false); keyApp.DeleteSubKeyTree(typeof(GraphDocumentEmbeddedComObject).GUID.ToString("B").ToUpperInvariant(), false); if (null != keyApp) { keyApp.Close(); } if (null != keyCLSID) { keyCLSID.Close(); } if (null != keyCR) { keyCR.Close(); } if (null != keySW) { keySW.Close(); } }
private void Register(RegistryKey rootKey, WOW_Mode wowMode) { RegistryKey keySW = null; RegistryKey keyCR = null; RegistryKey keyCLSID = null; RegistryKey key1 = null; RegistryKey key2 = null; RegistryKey key3 = null; RegistryKey key4 = null; RegistryValueKind applicationFileNameKind = RegistryValueKind.String; string applicationFileName = System.Reflection.Assembly.GetEntryAssembly().Location; if (wowMode == WOW_Mode.Reg32) { var p = System.IO.Path.GetFileNameWithoutExtension(applicationFileName); applicationFileName = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(applicationFileName), p + "32.exe"); } string programFilesPath = System.Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); if (applicationFileName.ToUpperInvariant().StartsWith(programFilesPath.ToUpperInvariant())) { applicationFileNameKind = RegistryValueKind.ExpandString; applicationFileName = "%ProgramFiles%" + applicationFileName.Substring(programFilesPath.Length); } try { keySW = rootKey.CreateSubKey("Software", wowMode); keyCR = keySW.CreateSubKey("Classes", wowMode); keyCLSID = keyCR.CreateSubKey("CLSID", wowMode); { // Register the project file extension key1 = keyCR.CreateSubKey(".axoprj", wowMode); key1.SetValue(null, "Altaxo.Project"); } { // Register the project file Com object key1 = keyCR.CreateSubKey("Altaxo.Project", wowMode); // set ProgID key1.SetValue("DefaultIcon", string.Format("{0},0", applicationFileName), applicationFileNameKind); key2 = key1.CreateSubKey("NotInsertable"); key2 = key1.CreateSubKey("CLSID"); var fileComObject_IID = typeof(ProjectFileComObject).GUID.ToString("B").ToUpperInvariant(); key2.SetValue(null, fileComObject_IID); key2 = key1.CreateSubKey("shell"); key3 = key2.CreateSubKey("open"); key4 = key3.CreateSubKey("command"); key4.SetValue(null, string.Format("\"{0}\" \"%1\"", applicationFileName), applicationFileNameKind); } { // publish CLSID of file Com object and associate it with the application key1 = keyCLSID.CreateSubKey(typeof(ProjectFileComObject).GUID.ToString("B").ToUpperInvariant(), wowMode); key1.SetValue(null, "Altaxo project"); key2 = key1.CreateSubKey("LocalServer32"); key2.SetValue(null, applicationFileName, applicationFileNameKind); } { key1 = keyCR.CreateSubKey("AppID", wowMode); key2 = key1.CreateSubKey(typeof(GraphDocumentEmbeddedComObject).GUID.ToString("B").ToUpperInvariant(), wowMode); key2.SetValue(null, GraphDocumentEmbeddedComObject.USER_TYPE); key2.SetValue("PreferredServerBitness", 3, RegistryValueKind.DWord); } { // register the Graph document embedded object (note that this is an Altaxo mini project) key1 = keyCR.CreateSubKey(GraphDocumentEmbeddedComObject.USER_TYPE, wowMode); key1.SetValue(null, GraphDocumentEmbeddedComObject.USER_TYPE_LONG); key2 = key1.CreateSubKey("CLSID"); key2.SetValue(null, typeof(GraphDocumentEmbeddedComObject).GUID.ToString("B").ToUpperInvariant()); key2 = key1.CreateSubKey("Insertable"); } { // publish CLSID of file GraphDocumentEmbeddedObject and associate it with the application key1 = keyCLSID.CreateSubKey(typeof(GraphDocumentEmbeddedComObject).GUID.ToString("B").ToUpperInvariant(), wowMode); key1.SetValue(null, GraphDocumentEmbeddedComObject.USER_TYPE_LONG); key2 = key1.CreateSubKey("LocalServer32"); key2.SetValue(null, applicationFileName, applicationFileNameKind); key2 = key1.CreateSubKey("InprocHandler32"); key2.SetValue(null, "OLE32.DLL"); // The entry InprocHandler32 is neccessary! Without this entry Word does not start the server. (Brockschmidt Inside Ole 2nd ed. says that it isn't neccessary). key2 = key1.CreateSubKey("ProgID"); key2.SetValue(null, GraphDocumentEmbeddedComObject.USER_TYPE); key2 = key1.CreateSubKey("VersionIndependentProgID"); key2.SetValue(null, "Altaxo.Graph"); key2 = key1.CreateSubKey("Insertable"); key2 = key1.CreateSubKey("DataFormats"); key3 = key2.CreateSubKey("GetSet"); key4 = key3.CreateSubKey("0"); key4.SetValue(null, "14,9,64,1"); // EnhMetafile on ENHMF in get-direction key4 = key3.CreateSubKey("1"); key4.SetValue(null, "2,9,1,1"); // Bitmap on HGlobal in get-direction key2 = key1.CreateSubKey("DefaultIcon"); key2.SetValue(null, string.Format("{0},0", applicationFileName), applicationFileNameKind); key2 = key1.CreateSubKey("verb"); key3 = key2.CreateSubKey("0"); key3.SetValue(null, "&Edit,0,2"); key3 = key2.CreateSubKey("-1"); key3.SetValue(null, "Show,0,0"); key3 = key2.CreateSubKey("-2"); key3.SetValue(null, "Open,0,0"); key3 = key2.CreateSubKey("-3"); key3.SetValue(null, "Hide,0,1"); key2 = key1.CreateSubKey("AuxUserType"); key3 = key2.CreateSubKey("2"); key3.SetValue(null, "Altaxo"); key3 = key2.CreateSubKey("3"); key3.SetValue(null, "Altaxo Graph Document"); key2 = key1.CreateSubKey("MiscStatus"); // see Brockschmidt, Inside Ole 2nd ed. page 832 key2.SetValue(null, ((int)(OLEMISC.OLEMISC_CANTLINKINSIDE)).ToString(System.Globalization.CultureInfo.InvariantCulture)); // DEFAULT: OLEMISC_CANTLINKINSIDE key3 = key2.CreateSubKey(((int)DVASPECT.DVASPECT_CONTENT).ToString(System.Globalization.CultureInfo.InvariantCulture)); // For DVASPECT_CONTENT key3.SetValue(null, ((int)(OLEMISC.OLEMISC_CANTLINKINSIDE | OLEMISC.OLEMISC_RENDERINGISDEVICEINDEPENDENT)).ToString(System.Globalization.CultureInfo.InvariantCulture)); // OLEMISC_RECOMPOSEONRESIZE | OLEMISC_CANTLINKINSIDE } } catch (Exception ex) { MessageBox.Show("Error while registering the server:\n" + ex.ToString()); throw; } finally { if (key4 != null) key4.Close(); if (key3 != null) key3.Close(); if (key2 != null) key2.Close(); if (key1 != null) key1.Close(); if (null != keyCLSID) keyCLSID.Close(); if (keyCR != null) keyCR.Close(); if (keySW != null) keySW.Close(); } }
private void Unregister(RegistryKey rootKey, WOW_Mode wowMode) { var keySW = rootKey.CreateSubKey("Software", wowMode); var keyCR = keySW.CreateSubKey("Classes", wowMode); var keyCLSID = keyCR.CreateSubKey("CLSID", wowMode); var keyApp = keyCR.CreateSubKey("AppID", wowMode); keyCR.DeleteSubKeyTree(".axoprj", false); keyCR.DeleteSubKeyTree("Altaxo.Project", false); keyCLSID.DeleteSubKeyTree(typeof(ProjectFileComObject).GUID.ToString("B").ToUpperInvariant(), false); keyCR.DeleteSubKeyTree(GraphDocumentEmbeddedComObject.USER_TYPE, false); keyCLSID.DeleteSubKeyTree(typeof(GraphDocumentEmbeddedComObject).GUID.ToString("B").ToUpperInvariant(), false); keyApp.DeleteSubKeyTree(typeof(GraphDocumentEmbeddedComObject).GUID.ToString("B").ToUpperInvariant(), false); if (null != keyApp) keyApp.Close(); if (null != keyCLSID) keyCLSID.Close(); if (null != keyCR) keyCR.Close(); if (null != keySW) keySW.Close(); }
private void Register(RegistryKey rootKey, WOW_Mode wowMode) { RegistryKey keySW = null; RegistryKey keyCR = null; RegistryKey keyCLSID = null; RegistryKey key1 = null; RegistryKey key2 = null; RegistryKey key3 = null; RegistryKey key4 = null; RegistryValueKind applicationFileNameKind = RegistryValueKind.String; string applicationFileName = System.Reflection.Assembly.GetEntryAssembly().Location; if (wowMode == WOW_Mode.Reg32) { var p = System.IO.Path.GetFileNameWithoutExtension(applicationFileName); applicationFileName = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(applicationFileName), p + "32.exe"); } string programFilesPath = System.Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); if (applicationFileName.ToUpperInvariant().StartsWith(programFilesPath.ToUpperInvariant())) { applicationFileNameKind = RegistryValueKind.ExpandString; applicationFileName = "%ProgramFiles%" + applicationFileName.Substring(programFilesPath.Length); } try { keySW = rootKey.CreateSubKey("Software", wowMode); keyCR = keySW.CreateSubKey("Classes", wowMode); keyCLSID = keyCR.CreateSubKey("CLSID", wowMode); { // Register the project file extension key1 = keyCR.CreateSubKey(".axoprj", wowMode); key1.SetValue(null, "Altaxo.Project"); } { // Register the project file Com object key1 = keyCR.CreateSubKey("Altaxo.Project", wowMode); // set ProgID key1.SetValue("DefaultIcon", string.Format("{0},0", applicationFileName), applicationFileNameKind); key2 = key1.CreateSubKey("NotInsertable"); key2 = key1.CreateSubKey("CLSID"); var fileComObject_IID = typeof(ProjectFileComObject).GUID.ToString("B").ToUpperInvariant(); key2.SetValue(null, fileComObject_IID); key2 = key1.CreateSubKey("shell"); key3 = key2.CreateSubKey("open"); key4 = key3.CreateSubKey("command"); key4.SetValue(null, string.Format("\"{0}\" \"%1\"", applicationFileName), applicationFileNameKind); } { // publish CLSID of file Com object and associate it with the application key1 = keyCLSID.CreateSubKey(typeof(ProjectFileComObject).GUID.ToString("B").ToUpperInvariant(), wowMode); key1.SetValue(null, "Altaxo project"); key2 = key1.CreateSubKey("LocalServer32"); key2.SetValue(null, applicationFileName, applicationFileNameKind); } { key1 = keyCR.CreateSubKey("AppID", wowMode); key2 = key1.CreateSubKey(typeof(GraphDocumentEmbeddedComObject).GUID.ToString("B").ToUpperInvariant(), wowMode); key2.SetValue(null, GraphDocumentEmbeddedComObject.USER_TYPE); key2.SetValue("PreferredServerBitness", 3, RegistryValueKind.DWord); } { // register the Graph document embedded object (note that this is an Altaxo mini project) key1 = keyCR.CreateSubKey(GraphDocumentEmbeddedComObject.USER_TYPE, wowMode); key1.SetValue(null, GraphDocumentEmbeddedComObject.USER_TYPE_LONG); key2 = key1.CreateSubKey("CLSID"); key2.SetValue(null, typeof(GraphDocumentEmbeddedComObject).GUID.ToString("B").ToUpperInvariant()); key2 = key1.CreateSubKey("Insertable"); } { // publish CLSID of file GraphDocumentEmbeddedObject and associate it with the application key1 = keyCLSID.CreateSubKey(typeof(GraphDocumentEmbeddedComObject).GUID.ToString("B").ToUpperInvariant(), wowMode); key1.SetValue(null, GraphDocumentEmbeddedComObject.USER_TYPE_LONG); key2 = key1.CreateSubKey("LocalServer32"); key2.SetValue(null, applicationFileName, applicationFileNameKind); key2 = key1.CreateSubKey("InprocHandler32"); key2.SetValue(null, "OLE32.DLL"); // The entry InprocHandler32 is neccessary! Without this entry Word does not start the server. (Brockschmidt Inside Ole 2nd ed. says that it isn't neccessary). key2 = key1.CreateSubKey("ProgID"); key2.SetValue(null, GraphDocumentEmbeddedComObject.USER_TYPE); key2 = key1.CreateSubKey("VersionIndependentProgID"); key2.SetValue(null, "Altaxo.Graph"); key2 = key1.CreateSubKey("Insertable"); key2 = key1.CreateSubKey("DataFormats"); key3 = key2.CreateSubKey("GetSet"); key4 = key3.CreateSubKey("0"); key4.SetValue(null, "14,9,64,1"); // EnhMetafile on ENHMF in get-direction key4 = key3.CreateSubKey("1"); key4.SetValue(null, "2,9,1,1"); // Bitmap on HGlobal in get-direction key2 = key1.CreateSubKey("DefaultIcon"); key2.SetValue(null, string.Format("{0},0", applicationFileName), applicationFileNameKind); key2 = key1.CreateSubKey("verb"); key3 = key2.CreateSubKey("0"); key3.SetValue(null, "&Edit,0,2"); key3 = key2.CreateSubKey("-1"); key3.SetValue(null, "Show,0,0"); key3 = key2.CreateSubKey("-2"); key3.SetValue(null, "Open,0,0"); key3 = key2.CreateSubKey("-3"); key3.SetValue(null, "Hide,0,1"); key2 = key1.CreateSubKey("AuxUserType"); key3 = key2.CreateSubKey("2"); key3.SetValue(null, "Altaxo"); key3 = key2.CreateSubKey("3"); key3.SetValue(null, "Altaxo Graph Document"); key2 = key1.CreateSubKey("MiscStatus"); // see Brockschmidt, Inside Ole 2nd ed. page 832 key2.SetValue(null, ((int)(OLEMISC.OLEMISC_CANTLINKINSIDE)).ToString(System.Globalization.CultureInfo.InvariantCulture)); // DEFAULT: OLEMISC_CANTLINKINSIDE key3 = key2.CreateSubKey(((int)DVASPECT.DVASPECT_CONTENT).ToString(System.Globalization.CultureInfo.InvariantCulture)); // For DVASPECT_CONTENT key3.SetValue(null, ((int)(OLEMISC.OLEMISC_CANTLINKINSIDE | OLEMISC.OLEMISC_RENDERINGISDEVICEINDEPENDENT)).ToString(System.Globalization.CultureInfo.InvariantCulture)); // OLEMISC_RECOMPOSEONRESIZE | OLEMISC_CANTLINKINSIDE } } catch (Exception ex) { MessageBox.Show("Error while registering the server:\n" + ex.ToString()); throw; } finally { if (key4 != null) { key4.Close(); } if (key3 != null) { key3.Close(); } if (key2 != null) { key2.Close(); } if (key1 != null) { key1.Close(); } if (null != keyCLSID) { keyCLSID.Close(); } if (keyCR != null) { keyCR.Close(); } if (keySW != null) { keySW.Close(); } } }
public static RegistryKey CreateSubKey(this RegistryKey mainKey, string name, WOW_Mode mode) { RegSAM sam = RegSAM.Write | RegSAM.Read | RegSAM.QueryValue; if (mode == WOW_Mode.Reg32) { sam |= RegSAM.WOW64_32Key; } else if (mode == WOW_Mode.Reg64) { sam |= RegSAM.WOW64_64Key; } Advapi32Func.RegCreateKeyEx( mainKey.Handle, name, 0, null, RegOption.NonVolatile, sam, IntPtr.Zero, out var resultingKey, out var regResult); return(RegistryKey.FromHandle(resultingKey)); }