当前位置: 首页 > news >正文

大连网络营销网站武汉大学人民医院地址

大连网络营销网站,武汉大学人民医院地址,网站图片怎么做,上品设计你可以使用自定义协议方案(Protocol Scheme)实现网页上点击URL后自动启动远程桌面连接(mstsc),参考你提供的C代码思路,如下实现: 第一步:注册自定义协议 使用类似openmstsc://协议…

你可以使用自定义协议方案(Protocol Scheme)实现网页上点击URL后自动启动远程桌面连接(mstsc),参考你提供的C++代码思路,如下实现:

第一步:注册自定义协议

使用类似openmstsc://协议。

注册示例 (reg 文件形式)
Windows Registry Editor Version 5.00[HKEY_CLASSES_ROOT\openmstsc]
@="URL:openmstsc Protocol"
"URL Protocol"=""[HKEY_CLASSES_ROOT\openmstsc\shell\open\command]
@="\"C:\\your-path\\open_mstsc.exe\" \"%1\""

或通过你的C++代码自动完成注册(代码里已经包含该功能)。


第二步:网页中调用协议URL

网页端代码(简单HTML):

<!DOCTYPE html>
<html lang="zh">
<head><meta charset="UTF-8"><title>远程桌面连接示例</title>
</head>
<body><a href="openmstsc://192.168.1.100:3389">连接远程桌面 192.168.1.100</a>
</body>
</html>

注意:

  • 点击此链接时,浏览器会提示用户是否允许调用该协议(首次使用时会询问),确认即可。

第三步:你的C++程序实现要点(已提供,以下强调注意点)

你的C++程序中关键实现点(你代码中已经包含了):

  • 解析传入的URL,提取IP:端口
  • 使用ShellExecuteExW调用mstsc.exe并传入/v:IP:Port参数。

示例(摘录):

void OpenWithMstsc(const std::wstring& serverIP) {if (serverIP.empty()) return;std::wstring mstscArgs = L"/v:" + serverIP;SHELLEXECUTEINFOW sei = { sizeof(sei) };sei.lpFile = L"mstsc.exe";sei.lpParameters = mstscArgs.c_str();sei.nShow = SW_SHOWNORMAL;sei.fMask = SEE_MASK_NOASYNC;ShellExecuteExW(&sei);
}

完整流程说明

  1. 网页链接点击 → 浏览器触发openmstsc://IP:Port
  2. 浏览器调用注册好的协议→ 执行open_mstsc.exe,传入参数。
  3. 程序解析URL → 调用mstsc.exe→ 远程桌面客户端打开。

这样即可实现点击网页上的链接自动打开远程桌面连接的功能。

// open_mstsc.cpp
// C++ 重写版本:实现与 C# 相同功能,包括注册自定义协议、解析 URL,并通过 WPS 打开文件,且不弹出控制台窗口。
//语言功能 "结构化绑定" 需要编译器标志 "/std:c++17"
//链接器-》系统-》子系统-》窗口模式
#include <windows.h>
#include <shlwapi.h>
#include <iostream>
#include <string>
#include <urlmon.h>
#include <shellapi.h>
#include <algorithm> // for std::transform
#pragma comment(lib, "Shlwapi.lib")
#pragma comment(lib, "urlmon.lib")
#include <cctype>
const std::wstring PROTOCOL_NAME = L"openMstsc";
#include <windows.h>
#include <shellapi.h>bool IsRunAsAdmin() {BOOL isAdmin = FALSE;PSID adminGroup;SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;if (AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,0, 0, 0, 0, 0, 0, &adminGroup)) {CheckTokenMembership(NULL, adminGroup, &isAdmin);FreeSid(adminGroup);}return isAdmin;
}void RelaunchAsAdmin() {wchar_t exePath[MAX_PATH];GetModuleFileNameW(NULL, exePath, MAX_PATH);SHELLEXECUTEINFOW sei = { sizeof(sei) };sei.lpVerb = L"runas"; // 以管理员权限运行sei.lpFile = exePath;sei.nShow = SW_SHOWNORMAL;sei.fMask = SEE_MASK_NOASYNC;if (ShellExecuteExW(&sei)) {ExitProcess(0); // 关闭当前进程}
}
// 替代 HttpUtility.UrlDecode 的简单实现
// 使用 UrlUnescapeW API 进行解码
static std::wstring UrlDecode(const std::wstring& encoded) {if (encoded.empty()) return L"";// 预留缓冲区存放解码后的结果const size_t BUFFER_SIZE = 4096;wchar_t buffer[BUFFER_SIZE];wcsncpy_s(buffer, encoded.c_str(), BUFFER_SIZE);DWORD dwSize = (DWORD)BUFFER_SIZE;HRESULT hr = UrlUnescapeW(buffer, NULL, &dwSize, URL_UNESCAPE_INPLACE);if (SUCCEEDED(hr)) {return std::wstring(buffer);}else {// 如果解码失败,可以根据需求返回空字符串或原始值return L"";}
}static std::wstring ProcessServerIP(const std::wstring& inputUrl, const std::wstring& protocolName)
{// 1) 构造 "{protocol}://" 的小写形式std::wstring lowerProtocol = protocolName;std::transform(lowerProtocol.begin(), lowerProtocol.end(), lowerProtocol.begin(), ::towlower);std::wstring protocolPrefix = lowerProtocol + L"://";// 2) 转换 inputUrl 为小写进行查找std::wstring lowerInput = inputUrl;std::transform(lowerInput.begin(), lowerInput.end(), lowerInput.begin(), ::towlower);// 3) 移除 "protocol://"std::wstring url;size_t pos = lowerInput.find(protocolPrefix);if (pos != std::wstring::npos){url = inputUrl.substr(pos + protocolPrefix.size());}else{url = inputUrl;  // 原始 URL}// 4) URL 解码(假设 UrlDecode 是可用函数)url = UrlDecode(url);// 5) 去除路径部分,仅保留 "host:port"size_t pathPos = url.find(L'/');if (pathPos != std::wstring::npos){url = url.substr(0, pathPos);}return url;
}//-----------------------------------------------------------
// 下面是原有的函数声明与实现
//-----------------------------------------------------------void RegisterUrlScheme(const std::wstring& protocol, const std::wstring& exePath);
std::wstring GetRegisteredPath(const std::wstring& protocol);void OpenWithMstsc(const std::wstring& fileUrl);
std::pair<std::wstring, std::wstring> GetWpsLauncherPath();
void EnsureUrlScheme(const std::wstring& protocol);int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
//int main(){if (!IsRunAsAdmin()) {RelaunchAsAdmin(); // 如果不是管理员权限,则重新以管理员权限运行return 0;}EnsureUrlScheme(PROTOCOL_NAME);int argc;LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc);if (argv == NULL) return 0;if (argc < 2) {//MessageBoxW(NULL, L"⚠️ 未检测到 URL 参数。", L"提示", MB_OK | MB_ICONWARNING);return 0;}// 调用新版 ProcessUrlstd::wstring url = ProcessServerIP(argv[1], PROTOCOL_NAME);if (PathIsURLW(url.c_str())) {OpenWithMstsc(url);}else {}LocalFree(argv);return 0;
}void EnsureUrlScheme(const std::wstring& protocol) {wchar_t exePath[MAX_PATH];GetModuleFileNameW(NULL, exePath, MAX_PATH);std::wstring registeredPath = GetRegisteredPath(protocol);if (registeredPath.empty() || !_wcsicmp(registeredPath.c_str(), exePath) == 0) {RegisterUrlScheme(protocol, exePath);}
}std::wstring GetRegisteredPath(const std::wstring& protocol) {HKEY hKey;std::wstring regPath = L"";std::wstring keyPath = protocol + L"\\shell\\open\\command";if (RegOpenKeyExW(HKEY_CLASSES_ROOT, keyPath.c_str(), 0, KEY_READ, &hKey) == ERROR_SUCCESS) {wchar_t value[MAX_PATH];DWORD value_length = sizeof(value);if (RegQueryValueExW(hKey, NULL, NULL, NULL, (LPBYTE)value, &value_length) == ERROR_SUCCESS) {std::wstring commandLine(value);size_t firstQuoteEnd = commandLine.find(L'"', 1);if (firstQuoteEnd != std::wstring::npos) {regPath = commandLine.substr(1, firstQuoteEnd - 1);}}RegCloseKey(hKey);}return regPath;
}void RegisterUrlScheme(const std::wstring& protocol, const std::wstring& exePath) {HKEY hKey;std::wstring keyPath = protocol;if (RegCreateKeyExW(HKEY_CLASSES_ROOT, keyPath.c_str(), 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) {RegSetValueExW(hKey, NULL, 0, REG_SZ, (const BYTE*)(L"URL:" + protocol + L" Protocol").c_str(),(DWORD)((protocol.size() + 10) * sizeof(wchar_t)));RegSetValueExW(hKey, L"URL Protocol", 0, REG_SZ, (const BYTE*)L"", sizeof(wchar_t));HKEY hCommandKey;if (RegCreateKeyExW(hKey, L"shell\\open\\command", 0, NULL, 0, KEY_WRITE, NULL, &hCommandKey, NULL) == ERROR_SUCCESS) {std::wstring command = L"\"" + exePath + L"\" \"%1\"";RegSetValueExW(hCommandKey, NULL, 0, REG_SZ, (const BYTE*)command.c_str(), (DWORD)(command.size() * sizeof(wchar_t)));RegCloseKey(hCommandKey);}RegCloseKey(hKey);MessageBoxW(NULL, L"远程组件注册成功。", L"成功", MB_OK | MB_ICONINFORMATION);}
}void OpenWithMstsc(const std::wstring& serverIP) {if (serverIP.empty()) {// MessageBoxW(NULL, L"❌ 服务器 IP 不能为空。", L"错误", MB_OK | MB_ICONERROR);return;}// 远程桌面连接的完整命令行参数std::wstring mstscArgs = L"/v:" + serverIP;SHELLEXECUTEINFOW sei = { sizeof(sei) };sei.lpFile = L"mstsc.exe";  // 远程桌面客户端sei.lpParameters = mstscArgs.c_str();sei.nShow = SW_SHOWNORMAL;sei.fMask = SEE_MASK_NOASYNC;if (!ShellExecuteExW(&sei)) {// MessageBoxW(NULL, L"❌ 无法启动远程桌面连接。", L"错误", MB_OK | MB_ICONERROR);}
}

注意上面代码要以管理员权限运行才能正确写入注册表,否则失败

下面将继续实现一下unbuntu上如何实现类似方法

sudo apt install freerdp2-x11  
xfreerdp /v:10.10.10.11:33389 /u:username /p:passwrod /cert-ignore /dynamic-resolution or( /w:1440 /h:900)


 


文章转载自:
http://proctectomy.pfbx.cn
http://bhave.pfbx.cn
http://quatrain.pfbx.cn
http://iatrical.pfbx.cn
http://subcapsular.pfbx.cn
http://busheler.pfbx.cn
http://terdiurnal.pfbx.cn
http://crwth.pfbx.cn
http://circumjacent.pfbx.cn
http://psophometer.pfbx.cn
http://muddledom.pfbx.cn
http://perpetually.pfbx.cn
http://troy.pfbx.cn
http://brainman.pfbx.cn
http://valentinite.pfbx.cn
http://crystallogeny.pfbx.cn
http://rewaken.pfbx.cn
http://fingerfish.pfbx.cn
http://chinchin.pfbx.cn
http://abborrent.pfbx.cn
http://windflaw.pfbx.cn
http://chilloplasty.pfbx.cn
http://resinosis.pfbx.cn
http://forestall.pfbx.cn
http://afrikanerdom.pfbx.cn
http://deathwatch.pfbx.cn
http://pleuron.pfbx.cn
http://convolution.pfbx.cn
http://relight.pfbx.cn
http://throstle.pfbx.cn
http://organon.pfbx.cn
http://pergamum.pfbx.cn
http://televox.pfbx.cn
http://slumbrous.pfbx.cn
http://roseola.pfbx.cn
http://semiotics.pfbx.cn
http://anglican.pfbx.cn
http://ragwort.pfbx.cn
http://meshugge.pfbx.cn
http://finitism.pfbx.cn
http://gamin.pfbx.cn
http://ultrasonologist.pfbx.cn
http://expedition.pfbx.cn
http://kinesics.pfbx.cn
http://stonker.pfbx.cn
http://acatalectic.pfbx.cn
http://syncretism.pfbx.cn
http://rexine.pfbx.cn
http://henotheism.pfbx.cn
http://eudaimonism.pfbx.cn
http://snowcem.pfbx.cn
http://dereism.pfbx.cn
http://resistibility.pfbx.cn
http://eldership.pfbx.cn
http://corymb.pfbx.cn
http://indolent.pfbx.cn
http://poverty.pfbx.cn
http://photopia.pfbx.cn
http://misandry.pfbx.cn
http://addenda.pfbx.cn
http://james.pfbx.cn
http://abu.pfbx.cn
http://interpulse.pfbx.cn
http://mainboom.pfbx.cn
http://mycoflora.pfbx.cn
http://burnous.pfbx.cn
http://cohabitant.pfbx.cn
http://interflow.pfbx.cn
http://teletypist.pfbx.cn
http://pinaceous.pfbx.cn
http://oktastylos.pfbx.cn
http://palsa.pfbx.cn
http://thanatophoric.pfbx.cn
http://inexactitude.pfbx.cn
http://falsetto.pfbx.cn
http://unengaged.pfbx.cn
http://softy.pfbx.cn
http://farthing.pfbx.cn
http://knife.pfbx.cn
http://biohazard.pfbx.cn
http://enterate.pfbx.cn
http://roose.pfbx.cn
http://meretricious.pfbx.cn
http://bilection.pfbx.cn
http://chronical.pfbx.cn
http://outer.pfbx.cn
http://monography.pfbx.cn
http://goddaughter.pfbx.cn
http://frigger.pfbx.cn
http://mattock.pfbx.cn
http://cuculliform.pfbx.cn
http://remediable.pfbx.cn
http://epidermolysis.pfbx.cn
http://thyrotoxic.pfbx.cn
http://debugging.pfbx.cn
http://gorget.pfbx.cn
http://edifier.pfbx.cn
http://countertendency.pfbx.cn
http://gumweed.pfbx.cn
http://outguess.pfbx.cn
http://www.15wanjia.com/news/71800.html

相关文章:

  • 网站建设bd方案广州推广优化
  • 国际贸易相关网站网站卖链接
  • 网站开发中涉及的侵权行为谷歌seo新规则
  • 做网站周记新闻头条国内大事
  • 计算机应用技术毕业设计青岛网站seo
  • 怎样建设小游戏网站seo描述快速排名
  • 好搜seo软件seo是指什么职位
  • 网页制作公司南昌官网优化包括什么内容
  • 弹幕网站用什么做营业推广策略有哪些
  • 洛阳做网站公司地址今日头条十大新闻最新
  • 怎么推广自己做的网站网络营销策划书包括哪些内容
  • seo优化员高级seo培训
  • 泰安seo服务seo网站排名优化公司
  • 汕头网站制作开发今日最新闻
  • 网站备案号链接大数据营销专业
  • 怎么知道网站是哪个公司做的百度排名推广
  • 到哪里做网站南宁哪里有seo推广厂家
  • 魅影看b站直播可以吗手机免费正能量erp软件下载
  • 佛山公司网站设计团队广告平台
  • 如何建立自己的电商平台sem和seo哪个工作好
  • 教育企业重庆网站建设淘宝店铺运营推广
  • 公司建设网站需要多少钱网站关键词排名分析
  • 肇东市网站千网推软文推广平台
  • 做外贸的网站如何选择服务器2023年适合小学生的新闻
  • 深圳网站建设 百业网络营销的特点有哪些?
  • 深圳找做网站刚刚中国出啥大事了
  • wordpress发邮件功能南京seo优化
  • 阿里云主机做网站个人网站首页设计
  • 双语网站建设报价优化seo
  • 重庆网站建设cqhtwl襄阳网站推广优化技巧