This is what
sc.Start(arg);
does:
public void Start(string[] args)
{
IntPtr[] ptrArray = new IntPtr[args.Length];
int index = 0;
GCHandle handle = new GCHandle();
try
{
handle = GCHandle.Alloc(ptrArray, GCHandleType.Pinned);
if (!UnsafeNativeMethods.StartService(serviceHandle, args.Length, handle.AddrOfPinnedObject()))
{
Exception innerException = CreateSafeWin32Exception();
throw new InvalidOperationException(Res.GetString("CannotStart", new object[] { this.ServiceName, this.MachineName }), innerException);
}
}
}
Considering where the problem appears to be (above), it
looks like there's a 1000 element limit on the size of the array of args (OR perhaps a maximum total length of arguments) that can be passed to:
[DllImport("advapi32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
public static extern bool StartService(IntPtr serviceHandle, int argNum, IntPtr argPtrs);
Consider wrapping your code in a
try...catch
and calling
Marshal.GetLastWin32Error
to determine exactly what went wrong.
See
http://msdn.microsoft.com/en-us/windows/ms686321(v=vs.71).aspx[
^] and
http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.getlastwin32error(v=vs.100).aspx[
^]