Leaked source code of windows server 2003
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.

144 lines
3.4 KiB

  1. //*************************************************************
  2. // File name: POLSETUP.C
  3. //
  4. // Description: Uninstall program for the Policy Editor
  5. //
  6. // Command Line Options:
  7. //
  8. // No options installs the policy editor
  9. // -u Uninstalls the policy editor
  10. //
  11. //
  12. // Microsoft Confidential
  13. // Copyright (c) Microsoft Corporation 1996
  14. // All rights reserved
  15. //
  16. //*************************************************************
  17. #include <windows.h>
  18. //
  19. // Platform specific command lines
  20. //
  21. #define NT_INST_CMD TEXT("rundll32 syssetup.dll,SetupInfObjectInstallAction DefaultInstall 132 %s")
  22. #define WIN_INST_CMD TEXT("rundll setupx.dll,InstallHinfSection DefaultInstall 132 %s")
  23. #define NT_UNINST_CMD TEXT("rundll32 syssetup.dll,SetupInfObjectInstallAction POLEDIT_remove 4 poledit.inf")
  24. #define WIN_UNINST_CMD TEXT("rundll setupx.dll,InstallHinfSection POLEDIT_remove 4 poledit.inf")
  25. //
  26. // ParseCmdLine
  27. //
  28. // Returns TRUE for uninstall
  29. // FALSE for normal install
  30. //
  31. BOOL ParseCmdLine(LPCTSTR lpCmdLine)
  32. {
  33. while( *lpCmdLine && *lpCmdLine != TEXT('-') && *lpCmdLine != TEXT('/')) {
  34. lpCmdLine++;
  35. }
  36. if (!(*lpCmdLine)) {
  37. return FALSE;
  38. }
  39. lpCmdLine++;
  40. if ( (*lpCmdLine == TEXT('u')) || (*lpCmdLine == TEXT('U')) ) {
  41. return TRUE;
  42. }
  43. return FALSE;
  44. }
  45. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  46. LPSTR lpCmdLine, INT nCmdShow)
  47. {
  48. STARTUPINFO si;
  49. PROCESS_INFORMATION ProcessInformation;
  50. TCHAR szCmdLine[MAX_PATH + MAX_PATH];
  51. OSVERSIONINFO ver;
  52. BOOL bNT, bUninstall = FALSE;
  53. TCHAR szPoleditInf[MAX_PATH];
  54. LPTSTR lpFileName;
  55. //
  56. // Determine if we are running on Windows NT
  57. //
  58. ver.dwOSVersionInfoSize = sizeof(ver);
  59. if (GetVersionEx(&ver)) {
  60. bNT = (ver.dwPlatformId == VER_PLATFORM_WIN32_NT);
  61. } else {
  62. bNT = FALSE;
  63. }
  64. //
  65. // Parse command line
  66. //
  67. if (ParseCmdLine(GetCommandLine())) {
  68. bUninstall = TRUE;
  69. }
  70. //
  71. // Choose the correct command line
  72. //
  73. if (bUninstall) {
  74. if (bNT) {
  75. lstrcpy (szCmdLine, NT_UNINST_CMD);
  76. } else {
  77. lstrcpy (szCmdLine, WIN_UNINST_CMD);
  78. }
  79. } else {
  80. if (!SearchPath (NULL, TEXT("poledit.inf"), NULL, MAX_PATH,
  81. szPoleditInf, &lpFileName)) {
  82. return 1;
  83. }
  84. if (bNT) {
  85. wsprintf (szCmdLine, NT_INST_CMD, szPoleditInf);
  86. } else {
  87. wsprintf (szCmdLine, WIN_INST_CMD, szPoleditInf);
  88. }
  89. }
  90. //
  91. // Spawn the real setup program
  92. //
  93. si.cb = sizeof(STARTUPINFO);
  94. si.lpReserved = NULL;
  95. si.lpTitle = NULL;
  96. si.lpDesktop = NULL;
  97. si.dwX = si.dwY = si.dwXSize = si.dwYSize = 0L;
  98. si.dwFlags = STARTF_USESHOWWINDOW;
  99. si.wShowWindow = SW_SHOWNORMAL;
  100. si.lpReserved2 = NULL;
  101. si.cbReserved2 = 0;
  102. if (CreateProcess(NULL, szCmdLine, NULL, NULL, FALSE,
  103. NORMAL_PRIORITY_CLASS, NULL, NULL,
  104. &si, &ProcessInformation)) {
  105. WaitForSingleObject(ProcessInformation.hProcess, 30000);
  106. CloseHandle(ProcessInformation.hProcess);
  107. CloseHandle(ProcessInformation.hThread);
  108. return 0;
  109. }
  110. return 1;
  111. }