Executing a process (program)

 

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows Xp Pro SP2

Target platform: none, just for learning and fun

Header file: Standard and Windows

Additional library: none

Additional project setting: Set project to be compiled as C

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)

Other info: non-CLR or unmanaged.

To do: Executing a process (program)

To show: Playing with Windows processes

 

 

/* Illustrates the the variables used for accessing

* command-line arguments and environment variables: argc, argv, envp,

* This program will be executed by crtexecprog.exe and others which follows

*/

#include <stdio.h>

 

/* argc - Number of strings in array argv */

/* *argv[] - Array of command-line argument strings */

/* **envp - Array of environment variable strings */

int main(int argc, char *argv[], char **envp)

{

int count;

 

/* Display each command-line argument. */

printf("\nCommand-line arguments:\n");

for (count = 0; count < argc; count++)

printf(" argv[%d] %s.\n", count, argv[count]);

/* Display each environment variable. */

printf("\nEnvironment variables:\n");

while (*envp != NULL)

printf(" %s.\n", *(envp++));

 

return 0;

}

 

Output example:

 

Command-line arguments:

argv[0] f:\vc2005project\cplus\debug\cplus.exe.

Environment variables:

ALLUSERSPROFILE=C:\Documents and Settings\All Users.WINDOWS.

APPDATA=C:\Documents and Settings\Johnny\Application Data.

CLIENTNAME=Console.

CommonProgramFiles=C:\Program Files\Common Files.

COMPUTERNAME=MYPERSONAL.

ComSpec=C:\WINDOWS\system32\cmd.exe.

FP_NO_HOST_CHECK=NO.

HOMEDRIVE=C:.

HOMEPATH=\Documents and Settings\Johnny.

INCLUDE=c:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\include\.

LIB=c:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Lib\.

LOGONSERVER=\\MYPERSONAL.

NUMBER_OF_PROCESSORS=2.

OS=Windows_NT.

Path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Common Files\Adobe\AGL;C:\Prog

ram Files\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\Microsoft Visual Studio 8\;C:\Program Files\Mic

rosoft Visual Studio 8\VC\bin.

PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH.

PROCESSOR_ARCHITECTURE=x86.

PROCESSOR_IDENTIFIER=x86 Family 15 Model 3 Stepping 4, GenuineIntel.

PROCESSOR_LEVEL=15.

PROCESSOR_REVISION=0304.

ProgramFiles=C:\Program Files.

PROMPT=$P$G.

SESSIONNAME=Console.

SystemDrive=C:.

SystemRoot=C:\WINDOWS.

TEMP=C:\DOCUME~1\Johnny\LOCALS~1\Temp.

TMP=C:\DOCUME~1\Johnny\LOCALS~1\Temp.

USERDOMAIN=MYPERSONAL.

USERNAME=Johnny.

USERPROFILE=C:\Documents and Settings\Johnny.

VS71COMNTOOLS=c:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Tools\.

VS80COMNTOOLS=C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\.

WecVersionForRosebud.9C8=2.

windir=C:\WINDOWS.

_ACP_ATLPROV=C:\Program Files\Microsoft Visual Studio 8\VC\Bin\ATLProv.dll.

_ACP_INCLUDE=C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include;C:\Program Files\Mic

rosoft Visual Studio 8\VC\include;C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include;C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\include.

_ACP_LIB=C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib;C:\Program Files\Microsoft Visual Studio 8\

VC\lib;C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\lib;C:\Program Files\Microsoft

Visual Studio 8\SDK\v2.0\lib;C:\Program Files\Microsoft Visual Studio 8\;C:\Program Files\Microsoft Visual Studio 8\lib.

_ACP_PATH=C:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Bin;C:\Program Files\Microsoft

Visual Studio 8\VC\bin;C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\bin;C:\Program Files\Microsof

t Visual Studio 8\Common7\Tools\bin;C:\Program Files\Microsoft Visual Studio 8\Common7\tools;C:\Program Files\

Microsoft Visual Studio 8\Common7\ide;C:\Program Files\HTML Help Workshop;C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\bin;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;C:\Program Files\Microsoft Visual Studio 8\;

C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Common Files\Adobe\AGL;C:\Program Files\Microsoft SQL Server\90\Tools\binn\.

Press any key to continue . . .

 

 

Note: Your environment variables should be different.

 

 

C and C++ Programming Resources | C & C++ Code Example Index