Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than advapi32, prefix the name with the module name and a period.
ChangeServiceConfig2 (advapi32)
.
C# Signature:
[DllImport("advapi32.dll", SetLastError=true, CharSet=CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool ChangeServiceConfig2(
IntPtr hService,
int dwInfoLevel,
IntPtr lpInfo);
VB Signature:
Declare Function ChangeServiceConfig2 Lib "advapi32.dll" (TODO) As TODO
Values for dwInfoLevel determine what structures are using for lpInfo. The possible values for this parameter can be found in WinSvc.h in the platform SDK.
To open service you don't need to use Windows API (OpenSCManager() and OpenService()) use field of System.ServiceProcess.ServiceController class (ServiceController.ServiceHandle.DangerousGetHandle())
Sample Code:
public MyServiceInstaller()
{
InitializeComponent();
serviceInstaller1.Committed += new InstallEventHandler(serviceInstaller1_Committed);
}
try
{
scHandle = OpenSCManager(null, null, (uint)SCM_ACCESS.SC_MANAGER_ALL_ACCESS);
if (scHandle == IntPtr.Zero)
{
throw new Exception(String.Format("Error connecting to Service Control Manager. Error provided was: 0x{0:X}", Marshal.GetLastWin32Error()));
}
svcHandle = OpenService(scHandle, serviceName, (int)SERVICE_ACCESS.SERVICE_ALL_ACCESS);
if (svcHandle == IntPtr.Zero)
{
throw new Exception(String.Format("Error opening service for modifying. Error returned was: 0x{0:X}", Marshal.GetLastWin32Error()));
}
IntPtr lpsaActions = Marshal.AllocHGlobal(Marshal.SizeOf(action) * 2);
if (lpsaActions == IntPtr.Zero)
{
throw new Exception(String.Format("Unable to allocate memory for service action, error was: 0x{0:X}", Marshal.GetLastWin32Error()));
}
// Make sure to close open handles
if (svcHandle != IntPtr.Zero)
{
CloseServiceHandle(svcHandle);
}
if (scHandle != IntPtr.Zero)
{
CloseServiceHandle(scHandle);
}
}
Changes the optional configuration parameters of a service.
8/8/2011 7:49:05 AM - -87.205.225.145
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).