Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
3.6 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. uexec.c
  5. Abstract:
  6. Test program for the NT OS User Mode Runtime Library (URTL)
  7. Author:
  8. Steve Wood (stevewo) 18-Aug-1989
  9. Revision History:
  10. --*/
  11. #include <nt.h>
  12. #include <ntrtl.h>
  13. #include <nturtl.h>
  14. #include <string.h>
  15. PVOID MyHeap = NULL;
  16. NTSTATUS
  17. main(
  18. IN ULONG argc,
  19. IN PCH argv[],
  20. IN PCH envp[],
  21. IN ULONG DebugParameter OPTIONAL
  22. )
  23. {
  24. NTSTATUS Status;
  25. STRING ImagePathName;
  26. PCHAR PathVariable, *pp;
  27. CHAR ImageNameBuffer[ 128 ];
  28. RTL_USER_PROCESS_INFORMATION ProcessInformation;
  29. PRTL_USER_PROCESS_PARAMETERS ProcessParameters;
  30. ULONG i, CountBytes, envc, Bogus;
  31. PSTRING DstString;
  32. PCH Src, Dst;
  33. PCH Parameters[ RTL_USER_PROC_PARAMS_DEBUGFLAG+2 ];
  34. Parameters[ RTL_USER_PROC_PARAMS_IMAGEFILE ] =
  35. "Full Path Specification of Image File goes here";
  36. Parameters[ RTL_USER_PROC_PARAMS_CMDLINE ] =
  37. "Complete Command Line goes here";
  38. Parameters[ RTL_USER_PROC_PARAMS_DEBUGFLAG ] =
  39. "Debugging String goes here";
  40. Parameters[ RTL_USER_PROC_PARAMS_DEBUGFLAG+1 ] = NULL;
  41. MyHeap = RtlProcessHeap();
  42. #if DBG
  43. DbgPrint( "Entering UEXEC User Mode Test Program\n" );
  44. DbgPrint( "argc = %ld\n", argc );
  45. for (i=0; i<=argc; i++) {
  46. DbgPrint( "argv[ %ld ]: %s\n",
  47. i,
  48. argv[ i ] ? argv[ i ] : "<NULL>"
  49. );
  50. }
  51. DbgPrint( "\n" );
  52. for (i=0; envp[i]; i++) {
  53. DbgPrint( "envp[ %ld ]: %s\n", i, envp[ i ] );
  54. }
  55. #endif
  56. PathVariable = "\\SystemRoot";
  57. if (envp != NULL) {
  58. pp = envp;
  59. while (Src = *pp++) {
  60. if (!_strnicmp( Src, "PATH=", 5 )) {
  61. PathVariable = Src+5;
  62. break;
  63. }
  64. }
  65. }
  66. DbgPrint( "PATH=%s\n", PathVariable );
  67. ProcessParameters = (PRTL_USER_PROCESS_PARAMETERS)
  68. RtlAllocateHeap( MyHeap, 0, 2048 );
  69. ProcessParameters->MaximumLength = 2048;
  70. argv[ argc ] = NULL;
  71. Status = RtlVectorsToProcessParameters(
  72. argv,
  73. envp,
  74. Parameters,
  75. ProcessParameters
  76. );
  77. ImagePathName.Buffer = ImageNameBuffer;
  78. ImagePathName.Length = 0;
  79. ImagePathName.MaximumLength = sizeof( ImageNameBuffer );
  80. if (RtlSearchPath( PathVariable, "uexec1.exe", NULL, &ImagePathName )) {
  81. Status = RtlCreateUserProcess( &ImagePathName,
  82. NULL,
  83. NULL,
  84. NULL,
  85. TRUE,
  86. NULL,
  87. NULL,
  88. ProcessParameters,
  89. &ProcessInformation,
  90. NULL
  91. );
  92. if (NT_SUCCESS( Status )) {
  93. Status = NtResumeThread( ProcessInformation.Thread, &Bogus );
  94. if (NT_SUCCESS( Status )) {
  95. #if DBG
  96. DbgPrint( "UEXEC waiting for UEXEC1...\n" );
  97. #endif
  98. Status = NtWaitForSingleObject( ProcessInformation.Process,
  99. TRUE,
  100. NULL
  101. );
  102. }
  103. }
  104. }
  105. else {
  106. DbgPrint( "UEXEC1.EXE not found in %s\n", PathVariable );
  107. Status = STATUS_UNSUCCESSFUL;
  108. }
  109. #if DBG
  110. DbgPrint( "Leaving UEXEC User Mode Test Program\n" );
  111. #endif
  112. return( Status );
  113. }