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); }
/// <summary> /// 卸载时删除已注册的CAP文件 /// 同时删除CAD 文件 /// </summary> /// <param name="savedState"></param> public override void Uninstall(IDictionary savedState) { base.Uninstall(savedState); #region 卸载已注册的CAP文件 RegistryKey capReg = Registry.ClassesRoot.OpenSubKey(".cap"); RegistryKey capFileTypeReg = Registry.ClassesRoot.OpenSubKey(".CA_FileType"); if (capReg != null) { Registry.ClassesRoot.DeleteSubKeyTree(".cap"); } if (capFileTypeReg != null) { Registry.ClassesRoot.DeleteSubKeyTree(".CA_FileType"); } #endregion /// 重置AutoCAD菜单 FileTypeRegister.ResetAutoCADMenu(); #region 除Solidworks插件 try { Microsoft.Win32.RegistryKey hklm = Microsoft.Win32.Registry.LocalMachine; Microsoft.Win32.RegistryKey hkcu = Microsoft.Win32.Registry.CurrentUser; string keyname = "SOFTWARE\\SolidWorks\\Addins\\{2eff6d31-932a-4191-ad00-1d705e27a64f}"; hklm.DeleteSubKey(keyname); keyname = "Software\\SolidWorks\\AddInsStartup\\{2eff6d31-932a-4191-ad00-1d705e27a64f}"; hkcu.DeleteSubKey(keyname); } catch (System.NullReferenceException nl) { } catch (System.Exception e) { } #endregion }
public void CreatRegData() { if (!FileTypeRegister.FileTypeRegistered(filetype)) { Debug.LogFormat("文件类型 {0} 注册中!",filetype); FileTypeRegInfo fileTypeRegInfo = new FileTypeRegInfo(filetype) { Description = "测试自定义文件系统", ExePath = System.Environment.GetCommandLineArgs()[0], ExtendName = filetype, IconPath = Path.Combine(UnityEngine.Application.streamingAssetsPath, string.Format("{0}.ico", iconName)) }; // 注册 FileTypeRegister fileTypeRegister = new FileTypeRegister(); FileTypeRegister.RegisterFileType(fileTypeRegInfo); } else { Debug.LogFormat("文件类型 {0} 已经存在中!", filetype); } }
private void Start() { if (FileTypeRegister.FileTypeRegistered(filetype)) { Debug.Log("文件类型已经存在~-"+filetype); FileTypeRegInfo regInfo =FileTypeRegister.GetFileTypeRegInfo(filetype); if (!File.Exists(regInfo.ExePath)||regInfo.ExePath!=executePath) { DialogResult dialogResult= MessageBox.Show(string.Format("文件系统{0}丢失打开方式,是否修复?", filetype),"警告:文件系统异常",MessageBoxButtons.OKCancel); if (dialogResult==DialogResult.OK) { regInfo.ExePath = executePath; regInfo.IconPath = Path.Combine(UnityEngine.Application.streamingAssetsPath, string.Format("{0}.ico", iconName)); FileTypeRegister.UpdateFileTypeRegInfo(regInfo); } } } else { Debug.LogWarning("文件类型不存在~-" + filetype); MessageBox.Show("文件系统尚未创建!"); } }
/// <summary> /// 安装时注册CAP文件 /// </summary> /// <param name="savedState"></param> public override void Install(IDictionary stateSaver) { base.Install(stateSaver); string currentInstallPath = this.Context.Parameters["targetdir"]; currentInstallPath = currentInstallPath.Replace("\\/", "\\"); #region 注册CAP FileTypeRegInfo reginfo = new FileTypeRegInfo(".cap"); reginfo.ExePath = currentInstallPath; //Application.ExecutablePath; reginfo.Description = "CAPP程序"; reginfo.IcoPath = currentInstallPath + @"Resources\cap.ico"; try { FileTypeRegister.RegisterFileType(reginfo); } catch { } #endregion #region 修改CAD默认菜单 /// 判断是否已经注册AutoCAD if (!FileTypeRegister.IsRegeditExit()) { try { FileTypeRegister.RegisterAutoCADPlugIn(currentInstallPath); } catch { } } /// 增加工艺简图菜单到AutoCAD 中 FileTypeRegister.UpdateAutoCADMenu(currentInstallPath); #endregion #region 注册Solidworks 插件 try { Microsoft.Win32.RegistryKey hklm = Microsoft.Win32.Registry.LocalMachine; Microsoft.Win32.RegistryKey hkcu = Microsoft.Win32.Registry.CurrentUser; string keyname = "SOFTWARE\\SolidWorks\\Addins\\{2eff6d31-932a-4191-ad00-1d705e27a64f}"; Microsoft.Win32.RegistryKey addinkey = hklm.CreateSubKey(keyname); addinkey.SetValue(null, 0); addinkey.SetValue("Description", "Solidworks AddIn Description"); addinkey.SetValue("Title", "Routing"); keyname = "Software\\SolidWorks\\AddInsStartup\\{2eff6d31-932a-4191-ad00-1d705e27a64f}"; addinkey = hkcu.CreateSubKey(keyname); addinkey.SetValue(null, true, Microsoft.Win32.RegistryValueKind.DWord); } catch (System.NullReferenceException nl) { Console.WriteLine("There was a problem registering this dll: SWattr is null. \n\"" + nl.Message + "\""); } #endregion #region 解决 Win7不能操作注册表问题 /** * 当前用户是管理员的时候,直接启动应用程序 * 如果不是管理员,则使用启动对象启动程序,以确保使用管理员身份运行 */ //获得当前登录的Windows用户标示 //System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent(); //System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity); ////判断当前登录用户是否为管理员 //if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator)) //{ // //如果是管理员,则直接运行 // if (string.IsNullOrEmpty(MainFrm.FilePath)) // { // var login = new LoginFrm(); // if (login.ShowDialog() == DialogResult.OK) // { // Application.Run(new MainFrm()); // } // } // else // { // Application.Run(new MainFrm()); // } //} //else //{ // //创建启动对象 // System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); // //设置运行文件 // startInfo.FileName = System.Windows.Forms.Application.ExecutablePath; // //设置启动参数 // startInfo.Arguments = String.Join(" ", args); // //设置启动动作,确保以管理员身份运行 // startInfo.Verb = "runas"; // //如果不是管理员,则启动UAC // System.Diagnostics.Process.Start(startInfo); // //退出 // System.Windows.Forms.Application.Exit(); //} #endregion }
public void UnRigisterData() { FileTypeRegister.UnRegisterFileType(filetype); }