GridView CheckBox 实现全选,跨页 CheckBox选择
Windows Service的注册的两种方法(转贴加整理)
一. 用VS2005实现;
二.调用API注册和注销Windows Service (转自:疾风之狼的BLOG)
一. 用VS2005实现;
1.新建一WINDOWS SERVICES工程WindowsService1;
2.双击打开Service1.cs,右键选择INSTALLER添加;
3.编译生成WindowsService1.exe.
4.使用命令installutil -i D:/Qiuwu/ProLab/2005C#.NET/WindowsService1/WindowsService1/bin/Debug/WindowsService1.exe,注册服务,
installutil -u D:/Qiuwu/ProLab/2005C#.NET/WindowsService1/WindowsService1/bin/Debug/WindowsService1.exe,卸载服务,
5.打开“允许服务与桌面交互”的功能,是得服务可以运行带画面的程序.方法:控制面板->管理工具->服务->选择刚安装的服务右击->属性->登陆(LOGON)->选择(LOCAL SYSTEM ACCOUNT),将“允许服务与桌面交互”复选框钩上即可.
一下是一些实现类似功能的C#代码:
-----------立即启动--------------
private void serviceInstaller1_AfterInstall(object sender, System.Configuration.Install.InstallEventArgs e)
{
ServiceController myService = new ServiceController("TestWindowsServices");
myService.Start();
myService.Dispose();
}
添加描述:1.1没有直接方法,2.0里有直接的方法 ServiceInstaller.Description
//----------------------------添加服务描述信息 开始 ------------
public override void Install(IDictionary stateServer)
{
Microsoft.Win32.RegistryKey system,
//HKEY_LOCAL_MACHINE/Services/CurrentControlSet
currentControlSet,
//.../Services
services,
//.../ <Service Name>
service,
//.../Parameters - this is where you can put service-specific configuration
config;
try
{
//Let the project installer do its job
base.Install(stateServer);
//Open the HKEY_LOCAL_MACHINE/SYSTEM key
system = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("System");
//Open CurrentControlSet
currentControlSet = system.OpenSubKey("CurrentControlSet");
//Go to the services key
services = currentControlSet.OpenSubKey("Services");
//Open the key for your service, and allow writing
service = services.OpenSubKey(this.serviceInstaller1.ServiceName, true);
//Add your service's description as a REG_SZ value named "Description"
service.SetValue("Description","Test Windows Services");
//(Optional) Add some custom information your service will use...
//注意此处即为实现“允许服务与桌面交互”
service.SetValue("Type",0x00000110);
config = service.CreateSubKey("Parameters");
}
catch(Exception e)
{
Console.WriteLine("An exception was thrown during service installation:/n" + e.ToString());
}
}
public override void Uninstall(IDictionary stateServer)
{
Microsoft.Win32.RegistryKey system,
currentControlSet,
services,
service;
try
{
//Drill down to the service key and open it with write permission
system = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("System");
currentControlSet = system.OpenSubKey("CurrentControlSet");
services = currentControlSet.OpenSubKey("Services");
service = services.OpenSubKey(this.serviceInstaller1.ServiceName, true);
//Delete any keys you created during installation (or that your service created)
service.DeleteSubKeyTree("Parameters");
//...
}
catch(Exception e)
{
Console.WriteLine("Exception encountered while uninstalling service:/n" + e.ToString());
}
finally
{
//Let the project installer do its job
base.Uninstall(stateServer);
}
}
//---------------------------- 结束 ----------------------------
二.调用API注册和注销Windows Service (转自:疾风之狼的BLOG)
调用API注册和注销Windows Service
(转自:http://blog.csdn.net/Mittermeyer/archive/2004/01/04/11653.aspx)
0、写在前面
public static extern System.IntPtr OpenSCManager(
System.String lpMachineName,
System.String lpDatabaseName,
System.UInt32 dwDesiredAccess
);
[DllImport("advapi32.dll",EntryPoint = "CreateServiceA")]
public static extern System.IntPtr CreateService(
System.IntPtr hSCManager,
System.String lpServiceName,
System.String lpDisplayName,
System.UInt32 dwDesiredAccess,
System.UInt32 dwServiceType,
System.UInt32 dwStartType,
System.UInt32 dwErrorControl,
System.String lpBinaryPathName,
System.String lpLoadOrderGroup,
System.IntPtr lpdwTagId,
System.String lpDependencies,
System.String lpServiceStartName,
System.String lpPassword
);
[DllImport("advapi32.dll")]
public static extern System.Boolean CloseServiceHandle(
System.IntPtr hSCObject
);
System.IntPtr hService,
System.UInt32 dwInfoLevel,
ref System.String lpInfo
);
其中lpInfo的声明原型是一个LPVOID,如果设置Description属性的话指向的是一个结构:
LPTSTR lpDescription;
} SERVICE_DESCRIPTION, *LPSERVICE_DESCRIPTION;
这个结构里面包含了一个字符指针,也就是说需要在函数调用时传递一个指向字符指针的指针,偷懒起见,ref System.String就足够了,无需再定义结构了,呵呵!
{
System.Boolean fRet = false;
System.IntPtr hServiceManager = IntPtr.Zero,hService = IntPtr.Zero;
System.String sServicePath = null,sDesc = null;
hServiceManager = OpenSCManager(Environment.MachineName,null,SC_MANAGER_ALL_ACCESS);
if (hServiceManager != IntPtr.Zero)
{
hService = CreateService(hServiceManager,"sampleservice","Sample Service",SERVICE_ALL_ACCESS,
SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS,SERVICE_AUTO_START,SERVICE_ERROR_NORMAL,
sServicePath,null,IntPtr.Zero,null,null,null);
if (hService != IntPtr.Zero)
{
sDesc = "This is a sample service.";
fRet = ChangeServiceConfig2(hService,SERVICE_CONFIG_DESCRIPTION,ref sDesc);
CloseServiceHandle(hService);
hService = IntPtr.Zero;
}
CloseServiceHandle(hServiceManager);
hServiceManager = IntPtr.Zero;
}
return fRet;
}
public static extern System.IntPtr OpenService(
System.IntPtr hSCManager,
System.String lpServiceName,
System.UInt32 dwDesiredAccess
);
[DllImport("advapi32.dll")]
public static extern System.Boolean DeleteService(
System.IntPtr hService
);
比较简单没什么可多说的看一个完整的例子:
{
System.Boolean fRet = false;
System.IntPtr hServiceManager = IntPtr.Zero,hService = IntPtr.Zero;
if (hServiceManager != IntPtr.Zero)
{
hService = OpenService(hServiceManager,"sampleservice",SERVICE_ALL_ACCESS);
if (hService != IntPtr.Zero)
{
fRet = DeleteService(hService);
CloseServiceHandle(hService);
hService = IntPtr.Zero;
}
CloseServiceHandle(hServiceManager);
hServiceManager = IntPtr.Zero;
}
return fRet;
}
[DllImport("advapi32.dll")]
public static extern System.IntPtr OpenSCManager(
System.String lpMachineName,
System.String lpDatabaseName,
System.UInt32 dwDesiredAccess
);
[DllImport("advapi32.dll",EntryPoint = "CreateServiceA")]
public static extern System.IntPtr CreateService(
System.IntPtr hSCManager,
System.String lpServiceName,
System.String lpDisplayName,
System.UInt32 dwDesiredAccess,
System.UInt32 dwServiceType,
System.UInt32 dwStartType,
System.UInt32 dwErrorControl,
System.String lpBinaryPathName,
System.String lpLoadOrderGroup,
System.IntPtr lpdwTagId,
System.String lpDependencies,
System.String lpServiceStartName,
System.String lpPassword
);
[DllImport("advapi32.dll")]
public static extern System.IntPtr OpenService(
System.IntPtr hSCManager,
System.String lpServiceName,
System.UInt32 dwDesiredAccess
);
[DllImport("advapi32.dll")]
public static extern System.Boolean DeleteService(
System.IntPtr hService
);
[DllImport("advapi32.dll")]
public static extern System.Boolean CloseServiceHandle(
System.IntPtr hSCObject
);
[DllImport("advapi32.dll")]
public static extern System.Boolean ChangeServiceConfig2(
System.IntPtr hService,
System.UInt32 dwInfoLevel,
ref System.String lpInfo
);
// Service Control Manager object specific access types
public const System.UInt32 SC_MANAGER_CONNECT = 0x0001;
public const System.UInt32 SC_MANAGER_CREATE_SERVICE = 0x0002;
public const System.UInt32 SC_MANAGER_ENUMERATE_SERVICE = 0x0004;
public const System.UInt32 SC_MANAGER_LOCK = 0x0008;
public const System.UInt32 SC_MANAGER_QUERY_LOCK_STATUS = 0x0010;
public const System.UInt32 SC_MANAGER_MODIFY_BOOT_CONFIG = 0x0020;
public const System.UInt32 SC_MANAGER_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED |
SC_MANAGER_CONNECT |
SC_MANAGER_CREATE_SERVICE |
SC_MANAGER_ENUMERATE_SERVICE |
SC_MANAGER_LOCK |
SC_MANAGER_QUERY_LOCK_STATUS |
SC_MANAGER_MODIFY_BOOT_CONFIG;
// Service object specific access type
public const System.UInt32 SERVICE_QUERY_CONFIG = 0x0001;
public const System.UInt32 SERVICE_CHANGE_CONFIG = 0x0002;
public const System.UInt32 SERVICE_QUERY_STATUS = 0x0004;
public const System.UInt32 SERVICE_ENUMERATE_DEPENDENTS = 0x0008;
public const System.UInt32 SERVICE_START = 0x0010;
public const System.UInt32 SERVICE_STOP = 0x0020;
public const System.UInt32 SERVICE_PAUSE_CONTINUE = 0x0040;
public const System.UInt32 SERVICE_INTERROGATE = 0x0080;
public const System.UInt32 SERVICE_USER_DEFINED_CONTROL = 0x0100;
public const System.UInt32 SERVICE_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED |
SERVICE_QUERY_CONFIG |
SERVICE_CHANGE_CONFIG |
SERVICE_QUERY_STATUS |
SERVICE_ENUMERATE_DEPENDENTS |
SERVICE_START |
SERVICE_STOP |
SERVICE_PAUSE_CONTINUE |
SERVICE_INTERROGATE |
SERVICE_USER_DEFINED_CONTROL;
// service type
public const System.UInt32 SERVICE_KERNEL_DRIVER = 0x00000001;
public const System.UInt32 SERVICE_FILE_SYSTEM_DRIVER = 0x00000002;
public const System.UInt32 SERVICE_ADAPTER = 0x00000004;
public const System.UInt32 SERVICE_RECOGNIZER_DRIVER = 0x00000008;
public const System.UInt32 SERVICE_DRIVER = SERVICE_KERNEL_DRIVER |
SERVICE_FILE_SYSTEM_DRIVER |
SERVICE_RECOGNIZER_DRIVER;
public const System.UInt32 SERVICE_WIN32_OWN_PROCESS = 0x00000010;
public const System.UInt32 SERVICE_WIN32_SHARE_PROCESS = 0x00000020;
public const System.UInt32 SERVICE_WIN32 = SERVICE_WIN32_OWN_PROCESS |
SERVICE_WIN32_SHARE_PROCESS;
public const System.UInt32 SERVICE_INTERACTIVE_PROCESS = 0x00000100;
public const System.UInt32 SERVICE_TYPE_ALL = SERVICE_WIN32 |
SERVICE_ADAPTER |
SERVICE_DRIVER |
SERVICE_INTERACTIVE_PROCESS;
// Start Type
public const System.UInt32 SERVICE_BOOT_START = 0x00000000;
public const System.UInt32 SERVICE_SYSTEM_START = 0x00000001;
public const System.UInt32 SERVICE_AUTO_START = 0x00000002;
public const System.UInt32 SERVICE_DEMAND_START = 0x00000003;
public const System.UInt32 SERVICE_DISABLED = 0x00000004;
// Error control type
public const System.UInt32 SERVICE_ERROR_IGNORE = 0x00000000;
public const System.UInt32 SERVICE_ERROR_NORMAL = 0x00000001;
public const System.UInt32 SERVICE_ERROR_SEVERE = 0x00000002;
public const System.UInt32 SERVICE_ERROR_CRITICAL = 0x00000003;
// Info levels for ChangeServiceConfig2 and QueryServiceConfig2
public const System.UInt32 SERVICE_CONFIG_DESCRIPTION = 1;
public const System.UInt32 SERVICE_CONFIG_FAILURE_ACTIONS = 2;
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=11653
GridView CheckBox 实现全选,跨页 CheckBox选择相关推荐
- 微信小程序checkbox的全选以及所有checkbox选中之后的全选
微信小程序checkbox的全选以及所有checkbox选中之后的全选 微信小程序checkbox的全选以及所有checkbox选中之后的全选 第一次写,软件都不懂,直接把代码拷过来了 模板 WXML ...
- layui 实现表单、表格中复选框checkbox的全选功能
一.layui 实现表单中多选框的全选功能,代码如下: //html页面表单 <form class="layui-form"><div class=" ...
- 实现checkbox的全选和取消
如果点击全选就把所有选项全选上,这个我们常用... View Code 1 <script type="text/javascript"> 2 /*实现checkbox ...
- JQuery 判断checkbox是否选中,checkbox全选,获取checkbox选中值
2019独角兽企业重金招聘Python工程师标准>>> JQuery是一个非常容易上手的框架,但是有很多东西需要我们深入学习的. 判断checkbox是否被选中网上有选多种写法,这里 ...
- 在项目中学习.NET的JQuery CheckBox方法(全选、取消全选、其他)
一.在项目中遇到的CheckBox的全选和取消全选以及其他等解决方案如下: // 对全选和取消全选的事件 $("#CheckAll").click(function () { ...
- JS如何控制checkbox的全选反选
JS代码: 1 <script language="javascript" type="text/javascript"> 2 3 //转载请保留出 ...
- jQuery实现checkbox的全选反选方法
checkbox的全选.取消全选.选中所有奇数.选中所有偶数等方法的实现代码如下: 注意jQuery的版本:jQuery1.6增加了prop,1.6之前的还是使用attr()和removeAttr() ...
- JQuery实现复选框CheckBox的全选、反选、提交操作
对复选框最基本的应用,就是对复选框进行全选.反选和提交等操作.复杂的操作需要与选项挂钩,来达到各种级联反应效果. [示例]使用Jquery实现复选框CheckBox的全选.反选.提交操作. (1)创建 ...
- Android高级控件(一)——ListView绑定CheckBox实现全选,增加和删除等功能
Android高级控件(一)--ListView绑定CheckBox实现全选,增加和删除等功能 这个控件还是挺复杂的,也是项目中应该算是比较常用的了,所以写了一个小Demo来讲讲,主要是自定义adap ...
- layui checkbox 反选/全选/取消单个取消全选/全部选中勾上全选
更: 下面连接文章就是解决checkbox只能取到最后一个值的解决办法 https://blog.csdn.net/qq_16513911/article/details/81981733 <d ...
最新文章
- 嵌入式四大通信接口的解释
- Java 必须掌握的 12 种 Spring 常用注解!
- 高校复试计算机英语文献翻译,专业文献英语翻译复试.pdf
- 你还记得当初为什么进入IT行业吗?
- 用clock()统计代码的执行时间(C语言)
- ASP.NET MVC:4 Ways To Prevent Duplicate Form Submission(转载)
- 软件外包故事 - 加入团队战斗
- 云服务器搭建代挂,服务器上搭建个人博客
- 【mybatis】xml中定义变量
- Nugine: Rust 性能调优
- 设计模式(4):生成器模式(Builder)
- Initialize flexnet service failed error code 50003错误
- oracle 18c,Oracle 18c
- 【C语言】扫雷游戏详解及完整代码
- 解决Establishing SSL connection without server‘s identity verification is not recommended问题
- AutoCAD系统变量大全
- 数据分析报告2:Superstore销售情况分析
- 56.com flash http://www.56.com/deux4_97177389.swf
- 新年新希望--爱摸鱼的美工(12)
- Python内置函数——最值与求和