private void frmUpgradeBuilder_Load(object sender, EventArgs e) { #region 自动注册文件类型 if (!FileTypeRegister.FileTypeRegistered(".upb")) { FileTypeRegInfo fileTypeRegInfo = new FileTypeRegInfo(".upb"); fileTypeRegInfo.Description = "IRAP 自动更新工程文件"; fileTypeRegInfo.ExePath = Application.ExecutablePath.Replace('/', '\\'); fileTypeRegInfo.ExtendName = ".upb"; fileTypeRegInfo.IcoPath = Application.ExecutablePath.Replace('/', '\\'); FileTypeRegister.RegisterFileType(fileTypeRegInfo); } #endregion WindowState = FormWindowState.Maximized; #region 检查当前应用是否以管理员权限运行 WindowsIdentity identity = WindowsIdentity.GetCurrent(); WindowsPrincipal principal = new WindowsPrincipal(identity); bool isRunasAdmin = principal.IsInRole(WindowsBuiltInRole.Administrator); #endregion btnRegisterApp.Enabled = isRunasAdmin; if (!btnRegisterApp.Enabled) { btnRegisterApp.SuperTip = new SuperToolTip(); btnRegisterApp.SuperTip.Items.Add("当前功能需要程序具有管理员权限才能使用!"); } }
private void btnRegisterApp_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { FileTypeRegInfo fileTypeRegInfo = new FileTypeRegInfo(".upb"); fileTypeRegInfo.Description = "IRAP 自动更新工程文件"; fileTypeRegInfo.ExePath = Application.ExecutablePath.Replace('/', '\\'); fileTypeRegInfo.ExtendName = ".upb"; fileTypeRegInfo.IcoPath = Application.ExecutablePath.Replace('/', '\\'); FileTypeRegister.RegisterFileType(fileTypeRegInfo); }
private void 设置文件关联ToolStripMenuItem_Click(object sender, EventArgs e) { FileTypeRegInfo pbox = new FileTypeRegInfo(); pbox.ExtendName = ".pbox"; pbox.Description = "私密箱"; pbox.IcoPath = AppDomain.CurrentDomain.BaseDirectory + "PrivateBox.ico"; pbox.ExePath = AppDomain.CurrentDomain.BaseDirectory + "PrivateBox.exe"; FileTypeRegister.RegisterFileType(pbox); SHChangeNotify(0x8000000, 0, IntPtr.Zero, IntPtr.Zero); MessageBoxEx.Show("设置完毕! ", "设置文件关联"); }
/// <summary> /// 绑定扩展名 /// </summary> private void BindingExtend() { if (!FileTypeRegister.FileTypeRegistered(SystemCommon.Extension)) { FileTypeRegInfo fileTypeRegInfo = new FileTypeRegInfo(SystemCommon.Extension); fileTypeRegInfo.Description = SystemCommon.SystemName + "缓存文件"; fileTypeRegInfo.ExePath = SystemCommon.ApplicationName; fileTypeRegInfo.ExtendName = SystemCommon.Extension; fileTypeRegInfo.IconPath = SystemCommon.ApplicationName; // 注册 //FileTypeRegister fileTypeRegister = new FileTypeRegister(); FileTypeRegister.RegisterFileType(fileTypeRegInfo); } }
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 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); } }
/// <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 }