/// <summary> /// Update infomation of the file type /// </summary> public static bool UpdateFileTypeRegInfo(FileTypeRegInfo regInfo) { String relationName = regInfo.ExtendName.Substring(1, regInfo.ExtendName.Length - 1).ToUpper(); RegistryKey relationKey = Registry.ClassesRoot.OpenSubKey(relationName, true); relationKey.SetValue("", regInfo.Description); RegistryKey iconKey = relationKey.OpenSubKey("DefaultIcon", true); iconKey.SetValue("", String.Format("\"{0}\"", regInfo.IcoPath)); RegistryKey shellKey = relationKey.OpenSubKey("Shell"); RegistryKey openKey = shellKey.OpenSubKey("Open"); RegistryKey commandKey = openKey.OpenSubKey("Command", true); commandKey.SetValue("", String.Format("\"{0}\" %1", regInfo.ExePath)); relationKey.Close(); return(true); }
/// <summary> /// Get infomation of the file type /// </summary> public static FileTypeRegInfo GetFileTypeRegInfo(string extendName) { if (!IsFileTypeRegistered(extendName)) { return(null); } else { FileTypeRegInfo regInfo = new FileTypeRegInfo(extendName); String relationName = extendName.Substring(1, extendName.Length - 1).ToUpper() + "_FileType"; RegistryKey relationKey = Registry.ClassesRoot.OpenSubKey(relationName); regInfo.Description = relationKey.GetValue("").ToString(); RegistryKey iconKey = relationKey.OpenSubKey("DefaultIcon"); regInfo.IcoPath = iconKey.GetValue("").ToString(); RegistryKey shellKey = relationKey.OpenSubKey("Shell"); RegistryKey openKey = shellKey.OpenSubKey("Open"); RegistryKey commandKey = openKey.OpenSubKey("Command"); string temp = commandKey.GetValue("").ToString(); regInfo.ExePath = temp.Substring(0, temp.Length - 3); return(regInfo); } }
/// <summary> /// Get infomation of the file type /// </summary> public static FileTypeRegInfo GetFileTypeRegInfo( string extendName ) { if ( !IsFileTypeRegistered( extendName ) ) { return null; } else { FileTypeRegInfo regInfo = new FileTypeRegInfo( extendName ); String relationName = extendName.Substring( 1 , extendName.Length - 1 ).ToUpper() + "_FileType"; RegistryKey relationKey = Registry.ClassesRoot.OpenSubKey( relationName ); regInfo.Description = relationKey.GetValue( "" ).ToString(); RegistryKey iconKey = relationKey.OpenSubKey( "DefaultIcon" ); regInfo.IcoPath = iconKey.GetValue( "" ).ToString(); RegistryKey shellKey = relationKey.OpenSubKey( "Shell" ); RegistryKey openKey = shellKey.OpenSubKey( "Open" ); RegistryKey commandKey = openKey.OpenSubKey( "Command" ); string temp = commandKey.GetValue( "" ).ToString(); regInfo.ExePath = temp.Substring( 0 , temp.Length - 3 ); return regInfo; } }
public static void RegisterFileType(FileTypeRegInfo regInfo) { if (IsFileTypeRegistered(regInfo.ExtendName)) { UpdateFileTypeRegInfo(regInfo); } else { String relationName = regInfo.ExtendName.Substring(1, regInfo.ExtendName.Length - 1).ToUpper(); RegistryKey fileTypeKey = Registry.ClassesRoot.CreateSubKey(regInfo.ExtendName); fileTypeKey.SetValue("", relationName); fileTypeKey.Close(); RegistryKey relationKey = Registry.ClassesRoot.CreateSubKey(relationName); relationKey.SetValue("", regInfo.Description); RegistryKey iconKey = relationKey.CreateSubKey("DefaultIcon"); iconKey.SetValue("", String.Format("\"{0}\"", regInfo.IcoPath)); RegistryKey shellKey = relationKey.CreateSubKey("Shell"); RegistryKey openKey = shellKey.CreateSubKey("Open"); RegistryKey commandKey = openKey.CreateSubKey("Command"); commandKey.SetValue("", String.Format("\"{0}\"", regInfo.ExePath) + " %1"); relationKey.Close(); } }
private void Init_RegisterFileType() { if ( !System.IO.Directory.Exists( AppSetting.ApplicationData_SecuruStikPath ) ) { Directory.CreateDirectory( AppSetting.ApplicationData_SecuruStikPath ); } File.Copy( AppSetting.App_Downloader , AppSetting.AppDataFolder_DownloaderFullPath ,true ); File.Copy( AppSetting.App_IconPath , AppSetting.AppDatafolder_Icon , true ); FileTypeRegInfo fileTypeRegInfo = new FileTypeRegInfo(); fileTypeRegInfo.Description = "SecuruStik share info file"; fileTypeRegInfo.ExePath = AppSetting.AppDataFolder_DownloaderFullPath; fileTypeRegInfo.ExtendName = AppSetting.ShareInfoFileExtension; fileTypeRegInfo.IcoPath = AppSetting.AppDatafolder_Icon; FileTypeRegister.RegisterFileType( fileTypeRegInfo ); }
public static void RegisterFileType( FileTypeRegInfo regInfo ) { if ( IsFileTypeRegistered( regInfo.ExtendName ) ) { UpdateFileTypeRegInfo( regInfo ); } else { String relationName = regInfo.ExtendName.Substring( 1 , regInfo.ExtendName.Length - 1 ).ToUpper(); RegistryKey fileTypeKey = Registry.ClassesRoot.CreateSubKey( regInfo.ExtendName ); fileTypeKey.SetValue( "" , relationName ); fileTypeKey.Close(); RegistryKey relationKey = Registry.ClassesRoot.CreateSubKey( relationName ); relationKey.SetValue( "" , regInfo.Description ); RegistryKey iconKey = relationKey.CreateSubKey( "DefaultIcon" ); iconKey.SetValue( "" , String.Format( "\"{0}\"" , regInfo.IcoPath ) ); RegistryKey shellKey = relationKey.CreateSubKey( "Shell" ); RegistryKey openKey = shellKey.CreateSubKey( "Open" ); RegistryKey commandKey = openKey.CreateSubKey( "Command" ); commandKey.SetValue( "" , String.Format( "\"{0}\"" , regInfo.ExePath ) + " %1" ); relationKey.Close(); } }
/// <summary> /// Update infomation of the file type /// </summary> public static bool UpdateFileTypeRegInfo( FileTypeRegInfo regInfo ) { String relationName = regInfo.ExtendName.Substring( 1 , regInfo.ExtendName.Length - 1 ).ToUpper(); RegistryKey relationKey = Registry.ClassesRoot.OpenSubKey( relationName , true ); relationKey.SetValue( "" , regInfo.Description ); RegistryKey iconKey = relationKey.OpenSubKey( "DefaultIcon" , true ); iconKey.SetValue( "" , String.Format( "\"{0}\"" , regInfo.IcoPath ) ); RegistryKey shellKey = relationKey.OpenSubKey( "Shell" ); RegistryKey openKey = shellKey.OpenSubKey( "Open" ); RegistryKey commandKey = openKey.OpenSubKey( "Command" , true ); commandKey.SetValue( "" , String.Format( "\"{0}\" %1" , regInfo.ExePath ) ); relationKey.Close(); return true; }