在实际应用中需要在一个进程启动另外一个进程,可以将子进程的路径写入注册表中,然后主进程读取注册表中子进程路径,启动子进程,并以命令行参数的形式传入参数,启动子进程。具体实现方式如下

(1)      子进程通过bat文件将路径写入注册表

reg add "HKEY_CLASSES_ROOT\btoolpplayerprotocol\shell\open\command" /t REG_SZ /d "\"%~dp0btoolpplayer.exe\" \"%%1\"" /f

/v表示名称,这里没有说明是默认值

/t表示类型

/d表示值

%cd%代表的是当前工作目录(current working directory,variable);

%~dp0代表的是当前批处理文件所在完整目录(the batch file's directory,fixed)。

(2)       主进程访问注册表读取路径信息

这里可以直接加入键名称,然后直接根据键名称访问键值,下面是遍历获取exe,不太合适。

QSettings reg("HKEY_CLASSES_ROOT\\btoolpplayerprotocol\\shell\\open\\command", QSettings::NativeFormat);

QStringList keyList = reg.childKeys();

QString location = "";

foreach(QString key, keyList)

{

QString slocation = reg.value(key).toString();

if (slocation!="" || slocation.contains("exe", Qt::CaseSensitive))

{

location = slocation;

break;

}

}

(3)      采用process访问进程

int index = location.indexOf("exe", 0);

index += 3;

location = location.mid(1, index-1);

QStringList Qstringlist;

Qstringlist << csCmd;

QProcess process;

LOGIC_TRACE("start paltplayer begin! ");

process.startDetached(location, Qstringlist);//分离

       LOGIC_TRACE("start paltplayer end! ");

(4)       bat从注册表中将键值删除

reg delete "HKEY_CLASSES_ROOT\btoolpplayerprotocol" /f

Qt访问注册表并调用子进程的更多相关文章

  1. 关于64位操作系统使用C#访问注册表失败的问题

    通过C#的注册表类 Registry.GetValue 进行访问时,其返回值一直为空.然后认真检查检查再检查了注册表路径,发现路径没有一点问题,不说废话,上代码: if (Registry.GetVa ...

  2. IIS 发表web 之后,访问注册表项失败得问题

    错误: 对注册表项“HKEY_LOCAL_MACHINE\SOFTWARE\xx\xxxx\xxxxx”的访问被拒绝. 解决办法: 打开IIS,找到应用程序池,然后找到自己web使用得程序池,右键高级 ...

  3. 解决EP拒绝访问注册表Global键的的问题

    问题描述   打开EP站点时出现如下Error: Message: An unhandled error has occurred. To view details about this error, ...

  4. 关于QT写注册表开机自启动

    注册表中权限: 1.HKEY_CURRENT_USER 2.HKEY_LOCAL_MACHINE 网上有很多帖子都是用的2,其实这样有违用户权限,而且如果不是管理员用户,会写入不成功! 代码如下: Q ...

  5. 调用Windows属性窗口(居然是通过注册表来调用的)

    简述 在Windows系统下.可以通过:右键 -> 属性,来查看文件/文件夹对应的属性信息,包括:常规.安全.详细信息等. 简述 共有类型 共有类型 首先,需要包含头文件: #include & ...

  6. 这种方法在受到.NET版本和访问注册表权限时,是最佳解决方案,虽然代码看起来很多,不过下面的类直接拿走用就可以了。

    public class FileContentType  {      private static IDictionary<string, string> _mappings = ne ...

  7. 64位系统访问注册表SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

    public int ChecNonkWoW64() { try { ; string subKey = @"SOFTWARE\Microsoft\Windows\CurrentVersio ...

  8. inno安装客户端,写注册表url调用客户端

    [Registry] Root: HKCR; SubKey: xxx; ValueData: "xxx"; ValueType: string; Flags: CreateValu ...

  9. 利用C#访问注册表获取软件的安装路径

    文章地址:https://blog.csdn.net/yl2isoft/article/details/17332139

随机推荐

  1. gdb调试问题汇总

    1. 宏调试 在GDB下,我们无法print宏定义,因为宏是预编译的.但是我们还是有办法来调试宏,这个需要GCC的配合. 在GCC编译程序的时候,加上-ggdb3参数,这样,你就可以调试宏了.另外,你 ...

  2. mybatis 3.2.*打印sql结果集

    虽然可以写个interceptor记录下,但是总归没有log4j来的自然.一段时间不查问题,总是要忘了,记录下: 在mybatis 3.2.*中,可以在log4j中如下配置: log4j.logger ...

  3. 【RMAN】使用RMAN的 Compressed Backupsets备份压缩技术 (转载)

    1.Oracle参考文档中关于RMAN备份压缩的描述1)关于如何通过调整RMAN参数启用取消备份压缩功能http://download.oracle.com/docs/cd/B19306_01/bac ...

  4. Codeforces 750E New Year and Old Subsequence - 线段树 - 动态规划

    A string t is called nice if a string "2017" occurs in t as a subsequence but a string &qu ...

  5. Codeforces Round #427 (Div. 2) Problem B The number on the board (Codeforces 835B) - 贪心

    Some natural number was written on the board. Its sum of digits was not less than k. But you were di ...

  6. VC++ 获取exe或者dll版本信息

    #include <iostream> #include <atlstr.h> #pragma comment(lib,"version.lib") CSt ...

  7. 【Python54.1--豆瓣登录】

    1.模拟豆瓣登录 ''' |-- 代码解析: |-- 1.登录必须具备的条件:url,cookie,fromData fromData的参数如下: source: index_nav form_ema ...

  8. Python3 tkinter基础 Listbox height 显示行数的上限

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  9. Python3基础 list + *运算 扩充列表

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  10. 流程控制if,while,for

    if语句 什么是if语句 判断一个条件如果成立则做...不成立则做....为何要有if语句 让计算机能够像人一样具有判断的能力 如何用if语句 语法1: if 条件1: code1 code2 cod ...