using System;using System.IO;using Microsoft.Win32;using Newtonsoft.Json;namespace AutoTask{public class Tools : Singleton<Tools>{/// <summary>/// 保存设置/// </summary>/// <param name="fileName"></param>/// <param name="obj"></param>public void SaveJsonSetting(string fileName, object obj){string json = JsonConvert.SerializeObject(obj);File.WriteAllText(fileName, json);}/// <summary>/// 获取/// </summary>/// <typeparam name="T"></typeparam>/// <param name="fileName"></param>/// <returns></returns>public T GetJsonSetting<T>(string fileName) where T:class,new(){string json = "";if (!File.Exists(fileName))File.CreateText(fileName);elsejson= File.ReadAllText(fileName);if (string.IsNullOrEmpty(json))return new T();elsereturn JsonConvert.DeserializeObject<T>(json);}/// <summary>/// 设置应用程序开机自动运行/// </summary>/// <param name="fileName">应用程序的文件名</param>/// <param name="isAutoRun">是否自动运行,为false时,取消自动运行</param>/// <exception cref="System.Exception">设置不成功时抛出异常</exception>public void SetAutoRun(string fileName, bool isAutoRun){RegistryKey reg = null;try{fileName = Path.GetFullPath(fileName);if (!System.IO.File.Exists(fileName))throw new Exception("该文件不存在!");String name = fileName.Substring(fileName.LastIndexOf(@"\") + 1);reg = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);if (reg == null)reg = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");if (isAutoRun)reg.SetValue(name, fileName);elsereg.SetValue(name, false);}catch (Exception ex){throw new Exception(ex.ToString());}finally{if (reg != null)reg.Close();}}public void SendMail(){}}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。