Windows startup process fails - Unable to start Bluetooth settings in a specific scenario

Even though there are command line commands to launch (for the most part?) Various Control Panel screens in Windows 10, a particular scenario seems to fail:

If the device starts up with Bluetooth disabled (not disabled), running the command that should open the Bluetooth settings screen simply does nothing. The command can be either ms-settings: bluetooth , bthprops.cpl, or ms-settings: Bluetooth .

I also tried to launch the bluetooth devices screen directly (using the command % windir% \ explorer.exe shell: {28803F59-3A75-4058-995F-4EE5503B023C} as described here ), but clicking on "Bluetooth Settings" in that window does nothing ...

The only way to go directly to the Bluetooth settings screen without having to wade through the main control panel window and not turn on Bluetooth is by right-clicking on the appropriate piece in the Windows Action Center:

Right click on Bluetooth bar in Windows Action Center

While this seems like a bug at the operating system level, I was wondering if there is a way to find out when startup fails from C # code. So I tried using the following code:

try
{
    var process = new Process();
    process.StartInfo.FileName = "control";
    process.StartInfo.Arguments = "bthprops.cpl";
    process.Exited += (s, e) =>
    {
        if (process.ExitCode != 0)
        {
            TurnOnBt();
        }
    };
    var res = process.Start();
    if (!res)
    {
        TurnOnBt();
    }
}
catch (System.Exception ex)
{
    int test = 6; // just for breakpoint
}

      

The problem is that the exception was never thrown and most of the time the Process.Exit event was never fired.

Next, calling Windows.Devices.Radios.Radio.GetRadiosAsync () returns an empty list!

Currently the only solution I have found is to manually enable bluetooth - this will not change the behavior of Process.Start / Exit, but it will allow the command to dine successfully to directly open the bluetooth settings window and get a list of bluetooth / radio devices. However, if you turn off Bluetooth and restart the machine, the same problem will occur over and over again.

Any ideas for a code based workaround?

+3


source to share


1 answer


note - this is all based on my debugging research only, none of this is documented


I'll see how BT settings window is open through Action Center (win8.1, win 10):

IApplicationActivationManager

created and named ActivateApplication

with:

appUserModelId = L"windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel"

arguments = L"page=SettingsPagePCSystemBluetooth"

C ++ code might look like this:

if (0 <= CoInitialize(0))
{
    IApplicationActivationManager* pAppAct;
    if (0 <= CoCreateInstance(__uuidof(ApplicationActivationManager), 0, CLSCTX_ALL, IID_PPV_ARGS(&pAppAct)))
    {
        ULONG dwProcessId;
        pAppAct->ActivateApplication(
            L"windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel", 
            L"page=SettingsPagePCSystemBluetooth", 
            AO_NONE , 
            &dwProcessId);
        pAppAct->Release();
    }
    CoUninitialize();
}

      

the processId link (if ok) to "X:\Windows\ImmersiveControlPanel\SystemSettings.exe" -ServerName:microsoft.windows.immersivecontrolpanel



for C # - look IApplicationActivationManager :: ActivateApplication in C #?

strings "windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel"

and is "page=SettingsPagePCSystemBluetooth"

not documented anywhere, and I'm not sure if it is "saved", but it is currently being used to open the bluetooth control page in system preferences. as it is.


if we start control.exe bthprops.cpl

- the process ( control.exe

) was launched without any error - as a result, you did not receive any errors when calling this code.

then control.exe bthprops.cpl

execute a new process rundll32.exe Shell32.dll,Control_RunDLL bthprops.cpl,

and exit

call rundll32.dll

Control_RunDLLW(HWND_DESKTOP, (HINSTANCE)&__ImageBase, L"bthprops.cpl", SW_SHOWDEFAULT);

we can and forward the call void WINAPI Control_RunDLLW(HWND hwndParent, HINSTANCE hInst, PCWSTR cplName, int nCmdShow );

, this api is exported from shell32.dll

Control_RunDLLW

load internally "bthprops.cpl"

(3rd argument is cplName), find CPlApplet entry point and send CPL_INIT . bthprops.cpl

in this check, the message bthserv

works through OpenService(L"BTHSERV", )

+ QueryServiceStatus

(in the function BthpIsbluetoothServiceRunning

), and if it "BTHSERV"

doesn't work, it returns zero (error code)

0


source







All Articles