using System; using System.Runtime.InteropServices; [StructLayout(LayoutKind.Sequential)] public struct AT_INFO { public uint JobTime; public uint DaysOfMonth; public byte DaysOfWeek; public byte Flags; [MarshalAs(UnmanagedType.LPTStr)] public string Command; } class Tester { [DllImport("netapi32.dll", EntryPoint="NetScheduleJobAdd", SetLastError=true)] public static extern int NetScheduleJobAdd(string ServerName, IntPtr Buffer, ref int jobId); static void Main() { int result = 0; int jobId = 0; IntPtr ptr = IntPtr.Zero; AT_INFO ai = new AT_INFO(); ai.JobTime = 16 * 60 * 60 *1000; ai.DaysOfMonth = 0x4000000; ai.DaysOfWeek = 0; ai.Flags = 0x10; // JOB_NONINTERACTIVE; ai.Command = "notepad.exe"; ptr = Marshal.AllocHGlobal(Marshal.SizeOf(ai)); Marshal.StructureToPtr(ai, ptr, true); result = NetScheduleJobAdd(null, ptr, ref jobId); if (result == 0) { Console.WriteLine("Job: {0}", jobId); } else Console.WriteLine("Error return: {0}",result); } }