CreateProcess的使用

VB CreateProcess代码 Attribute VB_Name = "Run_Command"Option ExplicitOption Base 0Powered by barenxPrivate Declare Function CreateProcess()Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplica 阅读详情

1. 通过CreateProcess启动进程时,如何传递参数?

  

   http://blog.csdn.net/hityct1/archive/2009/03/08/3968296.aspx

   

   使用编译器vs2008。

第一、第二个参数的用法:

例子:

使用ie打开指定的网页。

注意第二个参数是 可执行文件+命令行参数

view plaincopy to clipboardprint?
#include "stdafx.h"  
#include <windows.h>   
#include <stdio.h>   
 
int main(int argc, char* argv[])   
{   
    STARTUPINFO si = { sizeof(si) };   
    PROCESS_INFORMATION pi;   
 
    si.dwFlags = STARTF_USESHOWWINDOW;   
    si.wShowWindow = TRUE; //TRUE表示显示创建的进程的窗口  
    TCHAR cmdline[] =TEXT("c://program files//internet explorer//iexplore.exe http://community.csdn.net/");  
    BOOL bRet = ::CreateProcess (   
        NULL,  
        cmdline, //在Unicode版本中此参数不能为常量字符串,因为此参数会被修改    
        NULL,   
        NULL,   
        FALSE,   
        CREATE_NEW_CONSOLE,   
        NULL,   
        NULL,   
        &si,   
        &pi);   
 
    int error = GetLastError();  
    if(bRet)   
    {   
        ::CloseHandle (pi.hThread);   
        ::CloseHandle (pi.hProcess);   
 
        printf(" 新进程的进程ID号:%d /n", pi.dwProcessId);   
        printf(" 新进程的主线程ID号:%d /n", pi.dwThreadId);   
    }   
    else 
    {  
        printf("error code:%d/n",error );  
    }  
    return 0;   
}  
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>

int main(int argc, char* argv[])
{
 STARTUPINFO si = { sizeof(si) };
 PROCESS_INFORMATION pi;

 si.dwFlags = STARTF_USESHOWWINDOW;
 si.wShowWindow = TRUE; //TRUE表示显示创建的进程的窗口
 TCHAR cmdline[] =TEXT("c://program files//internet explorer//iexplore.exe http://community.csdn.net/");
 BOOL bRet = ::CreateProcess (
  NULL,
  cmdline, //在Unicode版本中此参数不能为常量字符串,因为此参数会被修改 
  NULL,
  NULL,
  FALSE,
  CREATE_NEW_CONSOLE,
  NULL,
  NULL,
  &si,
  &pi);

 int error = GetLastError();
 if(bRet)
 {
  ::CloseHandle (pi.hThread);
  ::CloseHandle (pi.hProcess);

  printf(" 新进程的进程ID号:%d /n", pi.dwProcessId);
  printf(" 新进程的主线程ID号:%d /n", pi.dwThreadId);
 }
 else
 {
  printf("error code:%d/n",error );
 }
 return 0;
} 

也可如此:

第一个参数是 可执行文件;第二个参数是 命令行参数

view plaincopy to clipboardprint?
#include "stdafx.h"  
#include <windows.h>   
#include <stdio.h>   
 
int main(int argc, char* argv[])   
{   
    STARTUPINFO si = { sizeof(si) };   
    PROCESS_INFORMATION pi;   
 
    si.dwFlags = STARTF_USESHOWWINDOW;   
    si.wShowWindow = TRUE; //TRUE表示显示创建的进程的窗口  
    TCHAR cmdline[] =TEXT(" http://community.csdn.net/"); //注意前面有空格,否则打开的是主页。  
    BOOL bRet = ::CreateProcess (   
        TEXT("c://program files//internet explorer//iexplore.exe"),  
        cmdline, //在Unicode版本中此参数不能为常量字符串,因为此参数会被修改    
        NULL,   
        NULL,   
        FALSE,   
        CREATE_NEW_CONSOLE,   
        NULL,   
        NULL,   
        &si,   
        &pi);   
 
    int error = GetLastError();  
    if(bRet)   
    {   
        ::CloseHandle (pi.hThread);   
        ::CloseHandle (pi.hProcess);   
 
        printf(" 新进程的进程ID号:%d /n", pi.dwProcessId);   
        printf(" 新进程的主线程ID号:%d /n", pi.dwThreadId);   
    }   
    else 
    {  
        printf("error code:%d/n",error );  
    }  
 
 
    return 0;   
}  

 

2. 启动进程如何获取命令行的参数?

    

        http://qingfengju.com/default.asp?tag=__argv

在MFC程序中,可以用以下几种方法来获取命令行参数。
为方便说明,我们假设执行了命令:
C:/test/app.exe -1 -2

方法一
::GetCommandLine();
将获取到 "C:/test/app.exe"  -1 -2

方法二
for (int i=0;i<__argc;i++)
{
__argv[i];
将依次得到C:/test/app.exe  -1  -2
}

方法三
AfxGetApp()->m_lpCmdLine;
将获取到
-1 -2

其他方法
如果希望支持MFC应用程序的标准命令行,还可以使用MFC中的CCommandLineInfo类。

CreateProcess创建的子进程的命令行参数 用CreateProcess创建的子进程所获得的命令行参数有以下几种情况: 1.子进程中,WinMain函数的第三个参数lpCmdLine表示的命令行参数中除去应用程序路径、文件名以及与参数相隔的空格等字符串后的内容。比如 父进程: CreateProcess(NULL, “c:\\test.exe -p“, NULL, NULL, FALSE, 0, NULL, NULL, & 阅读详情

相关推荐

CreateProcess函数 详细使用说明

CreateProcess函数 详细使用说明

CreateProcess的用法

第一、第二个参数的用法:   例子: 使用ie打开指定的网页。 注意第二个参数是 可执行文件+命令行参数 [cpp] view plaincopy #include "stdafx.h"   #include     #include        int main(int argc, char* argv[]) 

jiangqin115的专栏 1345

初学 PCIe System (一) - PCIe介绍及其配置空间

PCI Express (PCIe) 属于第三代的高效能 I/O 汇流排,PCIe Spec对其的介绍是:PCI Express 为各种未来的计算和通信平台所定义的高性能、通用互连 I/O。因此一个PCIe 系统就是指由许多设备相互透过 PCIe 点对点连接所组成的。如下图范例,其结构是由一个Root Complex (RC)、多个Endpoints、Bridge和Switches所组成。.........

yeiris的博客 8100

http://www.cr173.com/html/11519_1.html CreateProcess详解

函数原型  BOOL CreateProcess   (   LPCTSTR lpApplicationName,   LPTSTR lpCommandLine,   LPSECURITY_ATTRIBUTES lpProcessAttributes。   LPSECURITY_ATTRIBUTES lpThreadAttributes,   BO

7829

保姆级教程:用BIGEMAP和Global Mapper搞定5米精度DEM高程数据下载与处理

本文提供了一份详细的5米精度DEM高程数据处理教程,涵盖从BIGEMAP下载到Global Mapper处理的完整流程。通过实战案例和避坑指南,帮助用户掌握高效下载DEM数据、优化等高线生成及坐标系转换的关键技巧,适用于GIS新手和专业人士。

weixin_34169322的博客 402

Anomalib实战指南:从零开始构建自定义异常检测数据集

本文提供了一份详细的Anomalib实战指南,指导用户从零开始构建自定义异常检测数据集。文章深入解析了数据准备的核心步骤、目录结构规范,并对比了PatchCore与FastFlow等关键模型的适用场景。通过清晰的代码示例,手把手演示了环境配置、模型训练与推理评估的全流程,旨在帮助开发者快速掌握这一工业视觉异常检测利器,有效解决实际生产中的缺陷识别难题。

weixin_29054245的博客 656

控制台程序接收命令行参数

如果通过CreateProcess创建进程来调用控制台程序,那么在传递命令参数时需要加上 空格,如果不加上空格,argv是无法获取到参数的,示例如下主程序: nError = ::CreateProcess(cCmdFile, L" -s", NULL, NULL, FALSE, NORMAL...

Yvan Jiang的专栏 2757

家庭宽带IPv6避坑指南:如何通过DHCPv6-PD获取公网地址(附OpenWRT配置)

本文详细解析了家庭宽带IPv6的地址分配机制,重点介绍了通过DHCPv6-PD获取公网地址的方法,并提供了OpenWRT路由器的具体配置步骤。从路由器通告(RA)标记位到前缀委派(PD)流程,帮助用户解决IPv6部署中的常见问题,实现稳定高效的IPv6网络连接。

backprop5master的博客 1297

使用CreateProcess执行cmd,并通过匿名管道获取执行后的结果

console执行命令的操作方式,即通过shell操作电脑的方式,在Linux下的方便快捷无需言说。同样,在Windows下的cmd是一个也是一个很有用的工具,有很多命令,通过console的cmd执行后,能够快速得出结果。在编程中,有很多应用软件或者服务软件需要执行一些windows常用的cmd作为软件辅助,不仅如此,执行有些cmd后还要得出相应的执行结果,以便于根据结果做相应逻辑调整;另一方面...

explorer114的专栏 1万+

手把手教你用Ubuntu 22.04的附加驱动工具安装NVIDIA显卡驱动(含常见错误修复)

本文详细介绍了在Ubuntu 22.04系统上,如何通过图形化的“附加驱动”工具安全、便捷地安装NVIDIA显卡驱动。内容涵盖从准备工作、禁用默认的nouveau驱动、图形界面安装实操,到安装后的验证(如使用nvidia-smi命令),并提供了安装失败黑屏、亮度调节失效等常见问题的深度解决方案,帮助用户彻底搞定驱动安装难题。

weixin_29248653的博客 611

系统安全性评估 (SSA) 详细解析

系统安全性评估(SSA)是一种自下而上的验证过程,目的是确保系统设计中的每个功能、子系统、硬件和软件的实现,符合早期通过 FHA 和 PSSA 设定的安全性需求。它通过对已实现的系统进行系统性综合评价,检验各项设计和安装是否符合预期的安全性目标,最终支持飞机的适航认证。飞行控制系统是飞机安全性设计的核心子系统之一,负责控制飞机的姿态和方向。为了确保飞行控制系统能够在各种飞行条件下保持安全运行,SSA 被用于验证该系统的设计是否满足 FHA 中设定的安全性目标。

qq_41854911的博客 1661

CreateProcess使用心得

1、我们用CreateProcess执行一个外部程序时,怎样才能得到这个程序的输入输出呢?CreateProcess已经替我们准备好了,在CreateProcess的STARTUPINFO参数里有这样几个hStdInput、hStdOutput、hStdError东东,用来为创建的进程指定输入输出,例如用CreateFile创建一个文件,接着把得到的文件句柄指定给hStdOutput,并且把dwF

enoeht的专栏 3569

通信原理 | 通俗理解 | 因子图、消息传递以及它们之间的关系

在算法迭代过程中,通过反复更新这些消息,直到收敛,最终可以得到每个变量的边缘概率分布或最有可能的整体状态。算法通过因子图中的节点反复交换消息,直到找到最优解或所有消息稳定下来,从而解决了比如聚会日期这样的优化问题。在实际应用中,这种方法可以用来解决更复杂的问题,比如图像识别、语音识别和机器学习中的其他问题。,特别是在处理概率模型和执行概率推断时,因子图提供了一个强大的工具。(比如朋友的空闲时间和地点的可用性),并且你希望尽可能让所有人满意。在真正的因子图和消息传递算法中,这个过程被数学化和形式化。

若北辰 1222

CreateProcess

Delphi 使用CreateProcess创建进程并弹出进程PID值 var   ExeName:PChar;   StartupInfo:TStartupInfo;   ProcessInfo:TProcessInformation; begin   FillChar(ProcessInfo,sizeof(TProcessInformation),0);

haiou327’blog 1484

SKUA-GOCAD入门教程-第七节 点的创建与编辑3

本文介绍了四种从井数据创建点集的方法

江洋大葱的博客 969

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

Delphi CreateProcess

Delphi CreateProcess WIN32API函数CreateProcess用来创建一个新的进程和它的主线程,这个新进程运行指定的可执行文件 2010-12-27 17:00:17|分类:Delphi|标签:|字号大中小订阅 CreateProcess百科名片 WIN32API函数CreateProcess用来创建一个新的进程和它的主线程,这个新进程运行指定的...

weixin_30826761的博客 1207

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

CreateProcess创建一个隐藏进程

delphi中使用CreateProcess创建一个隐藏进程 FillChar(StartUpInfo, SizeOf(StartUpInfo), 00); StartUpInfo.dwFlags := STARTF_USESHOWWINDOW; StartUpInfo.w

haiou327’blog 9849

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

createprocess重启程序_vb用createprocess启动其他应用程序

Option ExplicitPrivate Type PROCESS_INFORMATIONhProcess As LonghThread As LongdwProcessId As LongdwThreadId As LongEnd TypePrivate Type STARTUPINFOcb As LonglpReserved As StringlpDesktop As StringlpTi...

weixin_39637920的博客 225

CreateProcess详解

重庆邮电大学 pppz(Java学生) 2120

CreateProcess()函数详解

CreateProcess 说明: WIN32API函数CreateProcess用来创建一个新的进程和它的主线程,这个新进程运行指定的可执行文件。 函数原型: BOOL CreateProcess (     LPCTSTR lpApplicationName,            LPTSTR lpCommandLine,            LPSECURITY_AT

夜空中最亮的星 4万+
上一篇: VC中一个关于宏的使用问题(转载)
下一篇: 关于在动态库的对话框中放置ocx,导致对话框弹不出来的问题
lllxy
博客等级 码龄25年 43粉丝 120原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值