windows 打开系统设置(SystemSettings.exe)c++

cpp 复制代码
#include <iostream>
#include <stdlib.h> 
#include <tchar.h>
#include <string> 
#include <windows.h> 
#include <KnownFolders.h>
#include <shlobj.h>

void shellrun1() {
	wchar_t system_buffer[MAX_PATH];
	system_buffer[0] = 0;
	::GetSystemDirectory(system_buffer, MAX_PATH);

	std::wstring sys_path(system_buffer);
	std::wstring rundll32 = sys_path + _T("\\rundll32.exe");

	std::wstring shell32dll = sys_path + _T("\\shell32.dll");

	std::wstring inetcpl = sys_path + _T("\\inetcpl.cpl,,4");

	std::wstring args(shell32dll);
	args.append(L",Control_RunDLL ");
	args.append(inetcpl);

	::ShellExecute(NULL, L"open", rundll32.c_str(), args.c_str(), NULL,
		SW_SHOWNORMAL);
}

void shellrun2(std::string url) {

	char system_buffer[MAX_PATH];
	system_buffer[0] = 0;
	::GetSystemDirectoryA(system_buffer, MAX_PATH);
	std::string sys_path(system_buffer);

	std::string escaped_url(url);
	escaped_url.insert(0, "\"");
	escaped_url += "\"";

	if (reinterpret_cast<ULONG_PTR>(ShellExecuteA(
		NULL, "open", escaped_url.c_str(), NULL,
		sys_path.c_str(), SW_SHOWNORMAL)) <= 32) {
		return;
	}

}
int main()
{
	//网络代理 只需将特定url粘贴打开即可,其他的更多参考下方微软链接
	std::string url("ms-settings:network-proxy");
	shellrun2(url);

	//相机设置
	std::string came_url("ms-settings:privacy-webcam");
	shellrun2(came_url);

	//搜索设置
	std::string search_url("ms-settings:search");
	shellrun2(search_url);

}

//打开其他设置项参考:

// https://learn.microsoft.com/en-us/windows/uwp/launch-resume/launch-settings-app#network--internet

截取部分,需要打开的项复制进去即可

效果图:

相关推荐
不想写代码的星星10 小时前
std::function 详解:用法、原理与现代 C++ 最佳实践
c++
樱木Plus2 天前
深拷贝(Deep Copy)和浅拷贝(Shallow Copy)
c++
blasit4 天前
笔记:Qt C++建立子线程做一个socket TCP常连接通信
c++·qt·tcp/ip
阿白的白日梦4 天前
winget基础管理---更新/修改源为国内源
windows
肆忆_5 天前
# 用 5 个问题学懂 C++ 虚函数(入门级)
c++
不想写代码的星星5 天前
虚函数表:C++ 多态背后的那个男人
c++
端平入洛7 天前
delete又未完全delete
c++
端平入洛8 天前
auto有时不auto
c++
埃博拉酱8 天前
VS Code Remote SSH 连接 Windows 服务器卡在"下载 VS Code 服务器":prcdn DNS 解析失败的诊断与 BITS 断点续传
windows·ssh·visual studio code
唐宋元明清21889 天前
.NET 本地Db数据库-技术方案选型
windows·c#