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.

65 lines
1.8 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2001
  5. //
  6. // File: control.cpp
  7. //
  8. // Contents: Command line wrapper for nlb.exe
  9. //
  10. // Notes:
  11. //
  12. // Author: chrisdar
  13. //
  14. // Created: 6 Apr 2001
  15. //
  16. // Change History:
  17. //
  18. //+---------------------------------------------------------------------------
  19. #include <windows.h>
  20. #include <wchar.h>
  21. #include <process.h>
  22. #include <stdio.h>
  23. int __cdecl wmain (int argc, PWCHAR argv[]) {
  24. // Set up the path+exe to be executed
  25. // Note: system32 is the correct directory, even for i64 machines!
  26. const wchar_t* pwszPath = L"%systemroot%\\system32\\wlbs.exe";
  27. const DWORD dwPathLen = wcslen(pwszPath);
  28. // Get space needed to hold the command line arguments
  29. DWORD dwArgSpace = 0;
  30. int i = 0;
  31. for (i=1; i<argc; i++)
  32. {
  33. dwArgSpace += wcslen(argv[i]);
  34. }
  35. // Allocate memory for the path+exe+arguments+1 (for NULL termination)
  36. // Params are separated by space and 'argc - 1' spaces are needed.
  37. // +1 for a NULL terminator ==> add 'argc' to length
  38. wchar_t* pwszCommand = new wchar_t[dwPathLen + dwArgSpace + argc];
  39. if (NULL == pwszCommand)
  40. {
  41. printf("Memory allocation failure...exiting\n");
  42. return -1;
  43. }
  44. // Build up the command line with spaces as token separators
  45. wcscpy(pwszCommand, pwszPath);
  46. for (i=1; i<argc; i++)
  47. {
  48. wcscat(pwszCommand, L" ");
  49. wcscat(pwszCommand, argv[i]);
  50. }
  51. // Execute the command for the user
  52. if (-1 == _wsystem(pwszCommand))
  53. {
  54. // Prints a text equivalent of errno for the system call
  55. _wperror(L"Command execution failed: ");
  56. return -1;
  57. }
  58. return 0;
  59. }