private static void RegisterForApplicationRestart( string command, RestartRestrictions restrictions) { uint returnValue = NativeMethods.RegisterApplicationRestart( command, restrictions); if (returnValue == SafeNativeMethods.ResultFailed) { throw new InvalidOperationException( "Application failed to registered for restart."); } if (returnValue == SafeNativeMethods.ResultInvalidArgument) { throw new ArgumentException( "Failed to register application for restart due to bad parameters."); } }
private static string ApplicationRestartSettings( IntPtr processHandle, out RestartRestrictions restart) { IntPtr cmdptr = IntPtr.Zero; uint size = 0; // Find out how big a buffer to allocate // for the command line. uint returnValue = NativeMethods.GetApplicationRestartSettings( processHandle, IntPtr.Zero, ref size, out restart); // Allocate a string buffer. cmdptr = Marshal.AllocHGlobal((int)size * sizeof(char)); // Get the settings using the buffer. returnValue = NativeMethods.GetApplicationRestartSettings( processHandle, cmdptr, ref size, out restart); if (returnValue == SafeNativeMethods.ResultNotFound) { throw new InvalidOperationException( "Application is not registered for restart."); } if (returnValue == SafeNativeMethods.ResultInvalidArgument) { throw new ArgumentException( "Failed to get application restart settings due to bad parameters."); } // Read the buffer's contents as a unicode string. string cmd = Marshal.PtrToStringUni(cmdptr); // Free the buffer. Marshal.FreeHGlobal(cmdptr); return(cmd); }
/// <summary> /// Creates a new instance of the RestartSettings class. /// </summary> /// <param name="commandLine">The command line arguments used to restart the application.</param> /// <param name="restrict">A bitwise combination of the RestartRestrictions /// values that specify when the application should not be restarted. /// </param> public RestartSettings(string commandLine, RestartRestrictions restrict) { command = commandLine; restrictions = restrict; }
internal static extern uint GetApplicationRestartSettings( IntPtr process, IntPtr commandLine, ref uint size, out RestartRestrictions flags);
internal static extern uint RegisterApplicationRestart( [MarshalAs(UnmanagedType.BStr)] string commandLineArgs, RestartRestrictions flags);
private static string ApplicationRestartSettings( IntPtr processHandle, out RestartRestrictions restart) { IntPtr cmdptr = IntPtr.Zero; uint size = 0; // Find out how big a buffer to allocate // for the command line. uint returnValue = NativeMethods.GetApplicationRestartSettings( processHandle, IntPtr.Zero, ref size, out restart); // Allocate a string buffer. cmdptr = Marshal.AllocHGlobal((int)size * sizeof(char)); // Get the settings using the buffer. returnValue = NativeMethods.GetApplicationRestartSettings( processHandle, cmdptr, ref size, out restart); if (returnValue == SafeNativeMethods.ResultNotFound) { throw new InvalidOperationException( "Application is not registered for restart."); } if (returnValue == SafeNativeMethods.ResultInvalidArgument) { throw new ArgumentException( "Failed to get application restart settings due to bad parameters."); } // Read the buffer's contents as a unicode string. string cmd = Marshal.PtrToStringUni(cmdptr); // Free the buffer. Marshal.FreeHGlobal(cmdptr); return cmd; }
/// <summary> /// Creates a new instance of the RestartSettings class. /// </summary> /// <param name="command">The command line arguments /// used to restart the application.</param> /// <param name="restrictions">A bitwise combination of the RestartRestrictions /// values that specify /// when the application should not be restarted. /// </param> public RestartSettings(string command, RestartRestrictions restrictions) { this.command = command; this.restrictions = restrictions; }
internal static extern Result RegisterApplicationRestart( [MarshalAs(UnmanagedType.BStr)] string commandLineArgs, RestartRestrictions flags);