|Manuals

ServerUtils.RunAsAdmin Method

Runs an application in elevated mode (with administrator permissions).

Description

This method runs an application in elevated mode with administrator permissions. This mode is required to save server configuration to protected system files.

Syntax

public static void RunAsAdmin(string fileName, string parameters);

Parameters

Parameter Type Description
fileName string Full path of the application to run
parameters string Arguments to pass to the application

Remarks

  • Use this method when you need to save changes to the server configuration
  • The method will launch the Windows UAC dialog to request permissions
  • The parameters are passed to the relaunched application

Example

static void Main(string[] args)
{
    if (args.Length == 0)
    {
        // Restart the application with administrator permissions
        ServerUtils.RunAsAdmin(Application.ExecutablePath, "/edit");
    }
    else
    {
        // Already running with elevated permissions
        Server server = new Server();
        // Modify configuration...
        server.Save();
    }
}

See Also