我想将服务安装到 Service Manager 并运行它。我的代码如下:
using System;
using System.Runtime.InteropServices;
class Ana
{
static void Main()
{
IntPtr sc_handle=OpenSCManager(null,null,2);
IntPtr sv_handle = CreateService(sc_handle, "deneme", "deneme", 16, 16, 2, 0, @"D:\ServisDeneme2.exe", null, null, null, null, null);
int i=StartService(sv_handle,0,null);
CloseServiceHandle(sc_handle);
}
[DllImport("advapi32.dll")]
public static extern IntPtr OpenSCManager(string machine, string db, int parameter);
[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, object 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);
}
此代码在我的 32 位计算机上完美运行,但在 64 位计算机上不起作用。我怎样才能为 64 位做同样的工作?