Sometimes you may want to change profile in Windows Mobile Smartphone within your application. Even if there is no easy to use API or P/Invoke, solution is quite easy. In \Windows folder on your device you can find application called autoprof.exe. This small application takes arguments from command line and sets the profile. For example autoprof.exe -s Meeting will set the Meeting profile.

Available values are Normal, Silent, Car, Headset, Loud, Meeting, Speakerphone These values are independent from user language or OEM settings.

You can experiment it from your desktop PC connected to the device. A> wyou need is the RAPI_start.exe from Windows Mobile Developer Power Toys.

Do it from the application

Changing profile from application is only execution of autoprof.exe within your code. Following C# method will do the job:

using System.Diagnostics;

....

private void SetProfile(string profile)
{
     Process proc = new Process();
     proc.StartInfo.FileName = "autoprof.exe";
     proc.StartInfo.Arguments = "-s " + profile;
     proc.StartInfo.UseShellExecute = true;
     proc.Start();
}

Setting UseShellExecute to true will prevent us from setting the full path to autoprof.exe, since the Windows folder is in system PATH variable. This code will work in .NET CF 1.0.

Complete C# class for CF 2.0

using System;
using System.Diagnostics;
using Microsoft.WindowsMobile.Status;

......

public class PhoneProfile
{
    private enum _Profiles { Normal, Silent, Car, Headset, Loud, Meeting, Speakerphone };

    public static string Active
    {
        get
        {
            return SystemState.PhoneProfile;
        }

        set
        {
            if (Enum.IsDefined(typeof(_Profiles), value)) SetProfile(value);
        }
    }

    private static void SetProfile(string profile)
    {
        Process proc = new Process();
        proc.StartInfo.FileName = "autoprof.exe";
        proc.StartInfo.Arguments = "-s " + profile;
        proc.StartInfo.UseShellExecute = true;
        proc.Start();
    }

    public static string Normal
    { get { return _Profiles.Normal.ToString(); } }

    public static string Silent
    { get { return _Profiles.Silent.ToString(); } }

    public static string Car
    { get { return _Profiles.Car.ToString(); } }

    public static string Headset
    { get { return _Profiles.Headset.ToString(); } }

    public static string Loud
    { get { return _Profiles.Loud.ToString(); } }

    public static string Meeting
    { get { return _Profiles.Meeting.ToString(); } }

    public static string Speakerphone
    { get { return _Profiles.Speakerphone.ToString(); } }
}