没有合适的资源?快使用搜索试试~ 我知道了~
教你C#怎么打包的方法,这是我在网上查找的和问老师后得到的解决方法!!分享给大家
资源推荐
资源详情
资源评论
using System;
using System.Runtime.InteropServices;
namespace MyServiceInstaller
{
class ServiceInstaller
{
#region Private Variables
private string _servicePath;
private string _serviceName;
private string _serviceDisplayName;
#endregion Private Variables
#region DLLImport
[DllImport("advapi32.dll")]
public static extern IntPtr OpenSCManager(string lpMachineName, string lpSCDB, int scParameter);
[DllImport("Advapi32.dll")]
public static extern IntPtr CreateService(IntPtr SC_HANDLE, string lpSvcName, string lpDisplayName,
int dwDesiredAccess, int dwServiceType, int dwStartType, int dwErrorControl, string lpPathName,
string lpLoadOrderGroup, int lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword);
[DllImport("advapi32.dll")]
public static extern void CloseServiceHandle(IntPtr SCHANDLE);
[DllImport("advapi32.dll")]
public static extern int StartService(IntPtr SVHANDLE, int dwNumServiceArgs, string lpServiceArgVectors);
[DllImport("advapi32.dll", SetLastError = true)]
public static extern IntPtr OpenService(IntPtr SCHANDLE, string lpSvcName, int dwNumServiceArgs);
[DllImport("advapi32.dll")]
public static extern int DeleteService(IntPtr SVHANDLE);
[DllImport("kernel32.dll")]
public static extern int GetLastError();
#endregion DLLImport
using System.Runtime.InteropServices;
namespace MyServiceInstaller
{
class ServiceInstaller
{
#region Private Variables
private string _servicePath;
private string _serviceName;
private string _serviceDisplayName;
#endregion Private Variables
#region DLLImport
[DllImport("advapi32.dll")]
public static extern IntPtr OpenSCManager(string lpMachineName, string lpSCDB, int scParameter);
[DllImport("Advapi32.dll")]
public static extern IntPtr CreateService(IntPtr SC_HANDLE, string lpSvcName, string lpDisplayName,
int dwDesiredAccess, int dwServiceType, int dwStartType, int dwErrorControl, string lpPathName,
string lpLoadOrderGroup, int lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword);
[DllImport("advapi32.dll")]
public static extern void CloseServiceHandle(IntPtr SCHANDLE);
[DllImport("advapi32.dll")]
public static extern int StartService(IntPtr SVHANDLE, int dwNumServiceArgs, string lpServiceArgVectors);
[DllImport("advapi32.dll", SetLastError = true)]
public static extern IntPtr OpenService(IntPtr SCHANDLE, string lpSvcName, int dwNumServiceArgs);
[DllImport("advapi32.dll")]
public static extern int DeleteService(IntPtr SVHANDLE);
[DllImport("kernel32.dll")]
public static extern int GetLastError();
#endregion DLLImport
/// <summary>
/// 应用程序入口.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string i = "0";
if (i.ToString().Trim() == "0")
{
stop();
}
else
{
run();
}
}
static void run()
{
string svcPath;
string svcName;
string svcDispName;
//服务程序的路径
svcPath = @"C:\send\SerialPort_SendService.exe";
svcDispName = "SerialPort_SendService";
svcName = "SerialPort_SendService";
ServiceInstaller c = new ServiceInstaller();
/// 应用程序入口.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string i = "0";
if (i.ToString().Trim() == "0")
{
stop();
}
else
{
run();
}
}
static void run()
{
string svcPath;
string svcName;
string svcDispName;
//服务程序的路径
svcPath = @"C:\send\SerialPort_SendService.exe";
svcDispName = "SerialPort_SendService";
svcName = "SerialPort_SendService";
ServiceInstaller c = new ServiceInstaller();
剩余5页未读,继续阅读
资源评论
sgf110007
- 粉丝: 50
- 资源: 29
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功