WinForm开机启动禁用开启任务管理器图片压缩常用函数.docx
《WinForm开机启动禁用开启任务管理器图片压缩常用函数.docx》由会员分享,可在线阅读,更多相关《WinForm开机启动禁用开启任务管理器图片压缩常用函数.docx(8页珍藏版)》请在冰豆网上搜索。
![WinForm开机启动禁用开启任务管理器图片压缩常用函数.docx](https://file1.bdocx.com/fileroot1/2023-2/26/d5beeae9-21ed-4412-b7cd-b1f7aa50b56d/d5beeae9-21ed-4412-b7cd-b1f7aa50b56d1.gif)
WinForm开机启动禁用开启任务管理器图片压缩常用函数
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
usingMicrosoft.Win32;
usingSystem.Diagnostics;
usingSystem.Runtime.InteropServices;
usingSystem.Windows.Forms;
usingSystem.Drawing;
namespaceEcan
{
publicclassEcanSystem
{
///
///设置程序开机运行
///
///是否开机运行
///要运行的EXE程序名称(不要拓展名)
///要运行的EXE程序路径
///成功返回真,否则返回假
publicboolrunWhenStart(boolstarted,stringexeName,stringpath)
{
RegistryKeykey=Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",true);//打开注册表子项
if(key==null)//如果该项不存在的话,则创建该子项
{
key=Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
}
if(started==true)
{
try
{
key.SetValue(exeName,path);//设置为开机启动
key.Close();
}
catch
{
returnfalse;
}
}
else
{
try
{
key.DeleteValue(exeName);//取消开机启动
key.Close();
}
catch
{
returnfalse;
}
}
returntrue;
}
///
///解禁任务管理器
///
///成功返回真,否则返回假
publicboolenableTaskmgr()
{
RegistryKeykey=Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\policies\\system",true);//打开注册表子项
if(key==null)//如果该项不存在的话,则创建该子项
{
key=Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\policies\\system");
}
try
{
key.SetValue("disabletaskmgr",0,RegistryValueKind.DWord);
key.Close();
returntrue;
}
catch
{
returnfalse;
}
}
///
///禁用任务管理器
///
///成功返回真,否则返回假
publicboolnotEnableTaskmgr()
{
RegistryKeykey=Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\policies\\system",true);//打开注册表子项
if(key==null)//如果该项不存在的话,则创建该子项
{
key=Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\policies\\system");
}
try
{
key.SetValue("disabletaskmgr",1,RegistryValueKind.DWord);
key.Close();
returntrue;
}
catch
{
returnfalse;
}
}
///
///解禁注册表
///
///成功返回真,否则返回假
publicboolenableRegedit()
{
RegistryKeykey=Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\policies\\system",true);//打开注册表子项
if(key==null)//如果该项不存在的话,则创建该子项
{
key=Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\policies\\system");
}
try
{
key.SetValue("disableregistrytools",0,RegistryValueKind.DWord);
key.Close();
returntrue;
}
catch
{
returnfalse;
}
}
///
///禁用注册表
///
///成功返回真,否则返回假
publicboolnotEnableRegedit()
{
RegistryKeykey=Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\policies\\system",true);//打开注册表子项
if(key==null)//如果该项不存在的话,则创建该子项
{
key=Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\policies\\system");
}
try
{
key.SetValue("disableregistrytools",1,RegistryValueKind.DWord);
key.Close();
returntrue;
}
catch
{
returnfalse;
}
}
///
///结束进程
///
///进程名称
///成功返回真,否则返回假
publicboolkillProcess(stringprocessName)
{
try
{
foreach(ProcesspinProcess.GetProcesses())
{
if(p.ProcessName==processName)
{
p.Kill();
}
}
returntrue;
}
catch{returnfalse;}
}
///
///注册控件
///
///控件
注册后对应的键值
///成功返回真,否则返回假
publicboolregDll(stringdllIdValue)
{
try
{
RegistryKeykey=Registry.ClassesRoot.OpenSubKey(@"CLSTD\"+dllIdValue,true);//打开注册表子项
if(key==null)//如果该项不存在的话,则创建该子项
{
key=Registry.ClassesRoot.CreateSubKey(@"CLSTD\"+dllIdValue);
}
returntrue;
}
catch{returnfalse;}
}
///
///压缩图片(指定压缩比例值)
///
///源文件
///保存文件
///比例值(例如0.5)
///成功返回真,否则返回假
publicboolpressImage(stringfromFile,stringsaveFile,doublebili)
{
Imageimg;
Bitmapbmp;
Graphicsgrap;
intwidth,height;
try
{
img=Image.FromFile(fromFile);
width=Convert.ToInt32(img.Width*bili);
height=Convert.ToInt32(img.Height*bili);
bmp=newBitmap(width,height);
grap=Graphics.FromImage(bmp);
grap.SmoothingMode=System.Drawing.Drawing2D.SmoothingMode.HighQuality;
grap.InterpolationMode=System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
grap.DrawImage(img,newRectangle(0,0,width,height));
bmp.Save(saveFile,System.Drawing.Imaging.ImageFormat.Jpeg);
grap.Dispose();
bmp.Dispose();
img.Dispose();
returntrue;
}
catch{returnfalse;}
}
///
///压缩图片(指定高度和宽度)
///
///源文件
///保存文件
///宽度值
///高度值
///成功返回真,否则返回假
publicboolpressImage(stringfromFile,stringsaveFile,intwidth,intheight)
{
Imageimg;
Bitmapbmp;
Graphicsgrap;
try
{
img=Image.FromFile(fromFile);
bmp=newBitmap(width,height);
grap=Graphics.FromImage(bmp);
grap.SmoothingMode=System.Drawing.Drawing2D.SmoothingMode.HighQuality;
grap.InterpolationMode=System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
grap.DrawImage(img,newRectangle(0,0,width
height));
bmp.Save(saveFile,System.Drawing.Imaging.ImageFormat.Jpeg);
grap.Dispose();
bmp.Dispose();
img.Dispose();
returntrue;
}
catch{returnfalse;}
}
}
}