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.

2112 lines
49 KiB

  1. //*************************************************************
  2. // File name: GPRESULT.C
  3. //
  4. // Description: Command line tool to dump the resultant set
  5. // of policy.
  6. //
  7. // Note: This is just a simple command line tool,
  8. // SitaramR and team are writing the real
  9. // resultant set of policy tool.
  10. //
  11. // Microsoft Confidential
  12. // Copyright (c) Microsoft Corporation 1999
  13. // All rights reserved
  14. //
  15. //*************************************************************
  16. #include "gpresult.h"
  17. #include <common.ver>
  18. #define GROUPPOLICY_KEY TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Group Policy")
  19. #define GROUPMEMBERSHIP_KEY TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Group Policy\\GroupMembership")
  20. #define GPEXT_KEY TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\GPExtensions")
  21. #define SCRIPTS_KEYNAME TEXT("Software\\Policies\\Microsoft\\Windows\\System\\Scripts")
  22. #define PROFILE_LIST_PATH TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList\\%s")
  23. BOOL ParseCommandLine (int argc, char *argv[]);
  24. void DumpGeneralInfo (void);
  25. DWORD DumpPolicyOverview (BOOL bMachine);
  26. void StringToGuid( TCHAR * szValue, GUID * pGuid );
  27. void DumpProfileInfo (void);
  28. void DumpSecurityGroups(BOOL bMachine);
  29. void DumpSecurityPrivileges(void);
  30. void DumpGPOInfo (PGROUP_POLICY_OBJECT pGPO);
  31. void DumpFolderRedir (void);
  32. void DumpIPSec (void);
  33. void DumpDiskQuota (void);
  34. void DumpScripts (PGROUP_POLICY_OBJECT pGPO, LPTSTR lpScriptType, LPTSTR lpTitle);
  35. void DumpAppMgmt (BOOL bMachine);
  36. GUID guidRegistry = REGISTRY_EXTENSION_GUID;
  37. BOOL g_bVerbose = FALSE;
  38. BOOL g_bSuperVerbose = FALSE;
  39. BOOL g_bUser = TRUE;
  40. BOOL g_bMachine = TRUE;
  41. BOOL g_bDebuggerOutput = FALSE;
  42. DWORD g_bNewFunc = FALSE;
  43. //*************************************************************
  44. //
  45. // main()
  46. //
  47. // Purpose: main entry point
  48. //
  49. // Parameters: argc and argv
  50. //
  51. //
  52. // Return: int error code
  53. //
  54. //*************************************************************
  55. int __cdecl main( int argc, char *argv[])
  56. {
  57. SYSTEMTIME systime;
  58. TCHAR szDate[100];
  59. TCHAR szTime[100];
  60. HANDLE hUser, hMachine;
  61. BOOL bResult;
  62. //
  63. // Parse the command line args
  64. //
  65. bResult = ParseCommandLine (argc, argv);
  66. //
  67. // Print the legal banner
  68. //
  69. PrintString(IDS_LEGAL1);
  70. PrintString(IDS_LEGAL2);
  71. PrintString(IDS_2NEWLINE);
  72. if (!bResult)
  73. {
  74. PrintString(IDS_USAGE1);
  75. PrintString(IDS_USAGE2);
  76. PrintString(IDS_USAGE3);
  77. PrintString(IDS_USAGE4);
  78. PrintString(IDS_USAGE5);
  79. PrintString(IDS_USAGE6);
  80. return 0;
  81. }
  82. //
  83. // Claim the policy critical sections while this tool is running so that
  84. // the data can't change while the report is being generated.
  85. //
  86. hUser = EnterCriticalPolicySection(FALSE);
  87. hMachine = EnterCriticalPolicySection(TRUE);
  88. //
  89. // Print the date and time this report is generated
  90. //
  91. GetLocalTime (&systime);
  92. GetDateFormat (LOCALE_USER_DEFAULT, DATE_LONGDATE, &systime,
  93. NULL, szDate, ARRAYSIZE(szDate));
  94. GetTimeFormat (LOCALE_USER_DEFAULT, 0, &systime,
  95. NULL, szTime, ARRAYSIZE(szTime));
  96. PrintString(IDS_CREATEINFO, szDate, szTime);
  97. //
  98. // Print the general machine info
  99. //
  100. DumpGeneralInfo ();
  101. //
  102. // Dump out user policy results if appropriate
  103. //
  104. if (g_bUser)
  105. {
  106. DumpPolicyOverview (FALSE);
  107. PrintString(IDS_2NEWLINE);
  108. }
  109. //
  110. // Dump out computer policy results if appropriate
  111. //
  112. if (g_bMachine)
  113. {
  114. DumpPolicyOverview (TRUE);
  115. }
  116. //
  117. // Release the policy critical sections
  118. //
  119. LeaveCriticalPolicySection(hUser);
  120. LeaveCriticalPolicySection(hMachine);
  121. return 0;
  122. }
  123. //*************************************************************
  124. //
  125. // DumpGeneralInfo()
  126. //
  127. // Purpose: Dumps out the general info about the computer
  128. //
  129. // Parameters: none
  130. //
  131. // Return: void
  132. //
  133. //*************************************************************
  134. void DumpGeneralInfo (void)
  135. {
  136. OSVERSIONINFOEX osiv;
  137. OSVERSIONINFO osver;
  138. DWORDLONG dwlConditionMask;
  139. BOOL bTSAppServer = FALSE;
  140. BOOL bTSRemoteAdmin = FALSE;
  141. BOOL bWks = FALSE;
  142. HKEY hkey;
  143. LONG lResult;
  144. TCHAR szProductType[50];
  145. DWORD dwType, dwSize;
  146. PrintString(IDS_OSINFO);
  147. //
  148. // Query the registry for the product type.
  149. //
  150. lResult = RegOpenKeyEx (HKEY_LOCAL_MACHINE,
  151. TEXT("System\\CurrentControlSet\\Control\\ProductOptions"),
  152. 0,
  153. KEY_READ,
  154. &hkey);
  155. if (lResult == ERROR_SUCCESS)
  156. {
  157. dwSize = sizeof(szProductType);
  158. szProductType[0] = TEXT('\0');
  159. lResult = RegQueryValueEx (hkey,
  160. TEXT("ProductType"),
  161. NULL,
  162. &dwType,
  163. (LPBYTE) szProductType,
  164. &dwSize);
  165. RegCloseKey (hkey);
  166. if (lResult == ERROR_SUCCESS)
  167. {
  168. if (!lstrcmpi (szProductType, TEXT("WinNT")))
  169. {
  170. bWks = TRUE;
  171. PrintString(IDS_OS_PRO);
  172. } else if (!lstrcmpi (szProductType, TEXT("ServerNT"))) {
  173. PrintString(IDS_OS_SRV);
  174. } else if (!lstrcmpi (szProductType, TEXT("LanmanNT"))) {
  175. PrintString(IDS_OS_DC);
  176. }
  177. }
  178. }
  179. //
  180. // Build number
  181. //
  182. ZeroMemory( &osver, sizeof( OSVERSIONINFO ) );
  183. osver.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
  184. if (GetVersionEx(&osver))
  185. {
  186. if (osver.szCSDVersion[0] != TEXT('\0'))
  187. PrintString(IDS_OS_BUILDNUMBER1, osver.dwMajorVersion,
  188. osver.dwMinorVersion, osver.dwBuildNumber, osver.szCSDVersion);
  189. else
  190. PrintString(IDS_OS_BUILDNUMBER2, osver.dwMajorVersion,
  191. osver.dwMinorVersion, osver.dwBuildNumber);
  192. }
  193. //
  194. // Check for a TS App Server
  195. //
  196. ZeroMemory( &osiv, sizeof( OSVERSIONINFOEX ) );
  197. osiv.dwOSVersionInfoSize = sizeof( OSVERSIONINFOEX );
  198. osiv.wSuiteMask = VER_SUITE_TERMINAL;
  199. dwlConditionMask = (DWORDLONG) 0L;
  200. VER_SET_CONDITION( dwlConditionMask, VER_SUITENAME, VER_AND );
  201. bTSAppServer = VerifyVersionInfo(&osiv, VER_SUITENAME, dwlConditionMask);
  202. //
  203. // Check for TS running in remote admin mode
  204. //
  205. ZeroMemory( &osiv, sizeof( OSVERSIONINFOEX ) );
  206. osiv.dwOSVersionInfoSize = sizeof( OSVERSIONINFOEX );
  207. osiv.wSuiteMask = VER_SUITE_SINGLEUSERTS;
  208. dwlConditionMask = (DWORDLONG) 0L;
  209. VER_SET_CONDITION( dwlConditionMask, VER_SUITENAME, VER_AND );
  210. bTSRemoteAdmin = VerifyVersionInfo(&osiv, VER_SUITENAME, dwlConditionMask);
  211. if (!bWks)
  212. {
  213. if (bTSAppServer)
  214. {
  215. if (bTSRemoteAdmin)
  216. {
  217. PrintString(IDS_TS_REMOTEADMIN);
  218. }
  219. else
  220. {
  221. PrintString(IDS_TS_APPSERVER);
  222. }
  223. }
  224. else
  225. {
  226. PrintString(IDS_TS_NONE);
  227. }
  228. }
  229. else
  230. {
  231. PrintString(IDS_TS_NOTSUPPORTED);
  232. }
  233. }
  234. //*************************************************************
  235. //
  236. // ParseCommandLine()
  237. //
  238. // Purpose: Parses the command line args
  239. //
  240. // Parameters: argc and argv
  241. //
  242. // Return: TRUE if processing should continue
  243. // FALSE if this tool should exit immediately
  244. //
  245. //*************************************************************
  246. BOOL ParseCommandLine (int argc, char *argv[])
  247. {
  248. int iIndex = 1;
  249. LPSTR lpArg;
  250. while (iIndex < argc)
  251. {
  252. lpArg = argv[iIndex] + 1;
  253. //
  254. // Enable verbose mode
  255. //
  256. if (!lstrcmpiA("V", lpArg))
  257. {
  258. g_bVerbose = TRUE;
  259. }
  260. else if (!lstrcmpiA("v", lpArg))
  261. {
  262. g_bVerbose = TRUE;
  263. }
  264. //
  265. // Enable super verbose mode
  266. //
  267. else if (!lstrcmpiA("S", lpArg))
  268. {
  269. g_bVerbose = TRUE;
  270. g_bSuperVerbose = TRUE;
  271. }
  272. else if (!lstrcmpiA("s", lpArg))
  273. {
  274. g_bVerbose = TRUE;
  275. g_bSuperVerbose = TRUE;
  276. }
  277. //
  278. // Show computer policy only
  279. //
  280. else if (!lstrcmpiA("C", lpArg))
  281. {
  282. g_bMachine = TRUE;
  283. g_bUser = FALSE;
  284. }
  285. else if (!lstrcmpiA("c", lpArg))
  286. {
  287. g_bMachine = TRUE;
  288. g_bUser = FALSE;
  289. }
  290. //
  291. // Show user policy only
  292. //
  293. else if (!lstrcmpiA("U", lpArg))
  294. {
  295. g_bMachine = FALSE;
  296. g_bUser = TRUE;
  297. }
  298. else if (!lstrcmpiA("u", lpArg))
  299. {
  300. g_bMachine = FALSE;
  301. g_bUser = TRUE;
  302. }
  303. //
  304. // Output to the debugger instead of the screen
  305. //
  306. else if (!lstrcmpiA("D", lpArg))
  307. {
  308. g_bDebuggerOutput = TRUE;
  309. }
  310. else if (!lstrcmpiA("d", lpArg))
  311. {
  312. g_bDebuggerOutput = TRUE;
  313. }
  314. //
  315. // Show the usage screen
  316. //
  317. else if (!lstrcmpiA("?", lpArg))
  318. {
  319. return FALSE;
  320. }
  321. iIndex++;
  322. }
  323. return TRUE;
  324. }
  325. //*************************************************************
  326. //
  327. // ExtractDomainNameFromSamName()
  328. //
  329. // Purpose: Pulls the domain name out of a SAM style
  330. // name. eg: NTDev\ericflo
  331. //
  332. // Parameters: lpSamName - source
  333. // lpDomainName - destination
  334. //
  335. // Return: TRUE if successful
  336. // FALSE if an error occurs
  337. //
  338. //*************************************************************
  339. BOOL ExtractDomainNameFromSamName (LPTSTR lpSamName, LPTSTR lpDomainName)
  340. {
  341. LPTSTR lpSrc, lpDest;
  342. //
  343. // Look for the \ between the domain and username and copy
  344. // the contents to the domain name buffer
  345. //
  346. lpSrc = lpSamName;
  347. lpDest = lpDomainName;
  348. while (*lpSrc && ((*lpSrc) != TEXT('\\')))
  349. {
  350. *lpDest = *lpSrc;
  351. lpSrc++;
  352. lpDest++;
  353. }
  354. if (*lpSrc != TEXT('\\'))
  355. {
  356. return FALSE;
  357. }
  358. *lpDest = TEXT('\0');
  359. return TRUE;
  360. }
  361. //*************************************************************
  362. //
  363. // GetDomainType()
  364. //
  365. // Purpose: Determines if the domain is NT4 or W2k by checking
  366. // if DS support is available.
  367. //
  368. // Parameters: lpDomainName - domain name
  369. // pbW2K - TRUE if w2k, FALSE if something else
  370. // pbLocalAccount - TRUE if local account
  371. //
  372. // Return: TRUE if successful
  373. // FALSE if an error occurs
  374. //
  375. //*************************************************************
  376. BOOL GetDomainType (LPTSTR lpDomainName, BOOL * pbW2K, BOOL *pbLocalAccount)
  377. {
  378. PDOMAIN_CONTROLLER_INFO pDCI;
  379. DWORD dwResult, dwSize;
  380. TCHAR szComputerName[MAX_PATH];
  381. //
  382. // Check this domain for a DC
  383. //
  384. dwResult = DsGetDcName (NULL, lpDomainName, NULL, NULL,
  385. DS_DIRECTORY_SERVICE_PREFERRED, &pDCI);
  386. if (dwResult == ERROR_SUCCESS)
  387. {
  388. //
  389. // Found a DC, does it have a DS ?
  390. //
  391. if (pDCI->Flags & DS_DS_FLAG) {
  392. *pbW2K = TRUE;
  393. }
  394. NetApiBufferFree(pDCI);
  395. return TRUE;
  396. }
  397. //
  398. // Check if the domain name is also the computer name (eg: local account)
  399. //
  400. dwSize = ARRAYSIZE(szComputerName);
  401. if (GetComputerName (szComputerName, &dwSize))
  402. {
  403. if (!lstrcmpi(szComputerName, lpDomainName))
  404. {
  405. *pbLocalAccount = TRUE;
  406. return TRUE;
  407. }
  408. }
  409. return FALSE;
  410. }
  411. //*************************************************************
  412. //
  413. // DumpPolicyOverview()
  414. //
  415. // Purpose: Main function that dumps the summary information
  416. // about each CSE and it's GPOs
  417. //
  418. // Parameters: bMachine - computer or user policy
  419. //
  420. // Return: Win32 error code
  421. //
  422. //*************************************************************
  423. DWORD DumpPolicyOverview (BOOL bMachine)
  424. {
  425. HKEY hKey, hSubKey;
  426. DWORD dwType, dwSize, dwIndex, dwNameSize;
  427. LONG lResult;
  428. FILETIME ftWrite, ftLocal;
  429. SYSTEMTIME systime;
  430. TCHAR szTime[30];
  431. TCHAR szDate[30];
  432. TCHAR szName[50];
  433. TCHAR szBuffer[MAX_PATH] = {0};
  434. TCHAR szDomainName[150] = {0};
  435. ULONG ulSize;
  436. GUID guid;
  437. PGROUP_POLICY_OBJECT pGPO, pGPOTemp;
  438. BOOL bW2KDomain = FALSE;
  439. BOOL bLocalAccount = FALSE;
  440. LPTSTR lpSiteName = NULL;
  441. //
  442. // Print a banner
  443. //
  444. if (bMachine)
  445. {
  446. ulSize = MAX_PATH;
  447. GetComputerObjectName (NameSamCompatible, szBuffer, &ulSize);
  448. ExtractDomainNameFromSamName (szBuffer, szDomainName);
  449. GetDomainType (szDomainName, &bW2KDomain, &bLocalAccount);
  450. if (bW2KDomain)
  451. {
  452. ulSize = ARRAYSIZE(szBuffer);
  453. szBuffer[0] = TEXT('\0');
  454. GetComputerObjectName (NameFullyQualifiedDN, szBuffer, &ulSize);
  455. }
  456. PrintString(IDS_NEWLINE);
  457. PrintString(IDS_LINE);
  458. PrintString(IDS_NEWLINE);
  459. PrintString(IDS_COMPRESULTS1);
  460. PrintString(IDS_COMPRESULTS2, szBuffer);
  461. PrintString(IDS_DOMAINNAME, szDomainName);
  462. if (bW2KDomain)
  463. {
  464. PrintString(IDS_W2KDOMAIN);
  465. DsGetSiteName(NULL, &lpSiteName);
  466. PrintString(IDS_SITENAME, lpSiteName);
  467. NetApiBufferFree(lpSiteName);
  468. }
  469. else if (bLocalAccount)
  470. {
  471. PrintString(IDS_LOCALCOMP);
  472. }
  473. else
  474. {
  475. PrintString(IDS_NT4DOMAIN);
  476. }
  477. //
  478. // Dump out the computer's security group information
  479. //
  480. PrintString(IDS_NEWLINE);
  481. DumpSecurityGroups(bMachine);
  482. PrintString(IDS_NEWLINE);
  483. PrintString(IDS_LINE);
  484. PrintString(IDS_NEWLINE);
  485. }
  486. else
  487. {
  488. ulSize = MAX_PATH;
  489. GetUserNameEx (NameSamCompatible, szBuffer, &ulSize);
  490. ExtractDomainNameFromSamName (szBuffer, szDomainName);
  491. GetDomainType (szDomainName, &bW2KDomain, &bLocalAccount);
  492. if (bW2KDomain)
  493. {
  494. ulSize = ARRAYSIZE(szBuffer);
  495. szBuffer[0] = TEXT('\0');
  496. GetUserNameEx (NameFullyQualifiedDN, szBuffer, &ulSize);
  497. }
  498. PrintString(IDS_NEWLINE);
  499. PrintString(IDS_LINE);
  500. PrintString(IDS_NEWLINE);
  501. PrintString(IDS_USERRESULTS1);
  502. PrintString(IDS_USERRESULTS2, szBuffer);
  503. PrintString(IDS_DOMAINNAME, szDomainName);
  504. if (bW2KDomain)
  505. {
  506. PrintString(IDS_W2KDOMAIN);
  507. DsGetSiteName(NULL, &lpSiteName);
  508. PrintString(IDS_SITENAME, lpSiteName);
  509. NetApiBufferFree(lpSiteName);
  510. }
  511. else if (bLocalAccount)
  512. {
  513. PrintString(IDS_LOCALUSER);
  514. }
  515. else
  516. {
  517. PrintString(IDS_NT4DOMAIN);
  518. }
  519. //
  520. // Dump out the user's profile and security group information
  521. //
  522. PrintString(IDS_NEWLINE);
  523. DumpProfileInfo();
  524. DumpSecurityGroups(bMachine);
  525. if (g_bVerbose)
  526. {
  527. DumpSecurityPrivileges();
  528. }
  529. PrintString(IDS_2NEWLINE);
  530. PrintString(IDS_LINE);
  531. PrintString(IDS_NEWLINE);
  532. }
  533. //
  534. // Find out the last time Group Policy was applied
  535. //
  536. lResult = RegOpenKeyEx (bMachine ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, GROUPPOLICY_KEY,
  537. 0, KEY_READ, &hKey);
  538. if (lResult != ERROR_SUCCESS)
  539. {
  540. PrintString(IDS_OPENHISTORYFAILED, lResult);
  541. return lResult;
  542. }
  543. lResult = RegQueryInfoKey (hKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  544. &ftWrite);
  545. if (lResult == ERROR_SUCCESS)
  546. {
  547. FileTimeToLocalFileTime (&ftWrite, &ftLocal);
  548. FileTimeToSystemTime (&ftLocal, &systime);
  549. GetTimeFormat (LOCALE_USER_DEFAULT, 0, &systime, NULL, szTime, ARRAYSIZE(szTime));
  550. GetDateFormat (LOCALE_USER_DEFAULT, DATE_LONGDATE, &systime, NULL, szDate, ARRAYSIZE(szDate));
  551. PrintString(IDS_LASTTIME, szDate, szTime);
  552. }
  553. else
  554. {
  555. PrintString(IDS_QUERYKEYINFOFAILED, lResult);
  556. }
  557. RegCloseKey (hKey);
  558. //
  559. // Find out which DC Group Policy was applied from last time
  560. //
  561. if (RegOpenKeyEx (bMachine ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER,
  562. TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Group Policy\\History"),
  563. 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
  564. dwSize = MAX_PATH * sizeof(TCHAR);
  565. szBuffer[0] = TEXT('\0');
  566. if (RegQueryValueEx (hKey, TEXT("DCName"), NULL, &dwType,
  567. (LPBYTE) szBuffer, &dwSize) == ERROR_SUCCESS)
  568. {
  569. PrintString(IDS_DCNAME, (szBuffer+2));
  570. g_bNewFunc = TRUE;
  571. }
  572. RegCloseKey (hKey);
  573. }
  574. //
  575. // Dump out registry policy information
  576. //
  577. lResult = GetAppliedGPOList (bMachine ? GPO_LIST_FLAG_MACHINE : 0, NULL, NULL,
  578. &guidRegistry, &pGPO);
  579. if (lResult == ERROR_SUCCESS)
  580. {
  581. if (pGPO)
  582. {
  583. PrintString(IDS_LINE2);
  584. if (bMachine)
  585. {
  586. PrintString(IDS_COMPREGPOLICY);
  587. }
  588. else
  589. {
  590. PrintString(IDS_USERREGPOLICY);
  591. }
  592. pGPOTemp = pGPO;
  593. while (pGPOTemp)
  594. {
  595. PrintString(IDS_GPONAME, pGPOTemp->lpDisplayName);
  596. DumpGPOInfo (pGPOTemp);
  597. pGPOTemp = pGPOTemp->pNext;
  598. }
  599. FreeGPOList (pGPO);
  600. //
  601. // If we are in verbose mode, dump out the registry settings that
  602. // were applied
  603. //
  604. if (g_bVerbose) {
  605. if (bMachine)
  606. ExpandEnvironmentStrings (TEXT("%ALLUSERSPROFILE%\\ntuser.pol"), szBuffer, MAX_PATH);
  607. else
  608. ExpandEnvironmentStrings (TEXT("%USERPROFILE%\\ntuser.pol"), szBuffer, MAX_PATH);
  609. DisplayRegistryData (szBuffer);
  610. }
  611. }
  612. }
  613. //
  614. // Enumerate the extensions
  615. //
  616. lResult = RegOpenKeyEx (HKEY_LOCAL_MACHINE, GPEXT_KEY, 0, KEY_READ, &hKey);
  617. if (lResult == ERROR_SUCCESS)
  618. {
  619. dwIndex = 0;
  620. dwNameSize = 50;
  621. while (RegEnumKeyEx (hKey, dwIndex, szName, &dwNameSize, NULL, NULL,
  622. NULL, NULL) == ERROR_SUCCESS)
  623. {
  624. //
  625. // Skip the registry extension since we did it above
  626. //
  627. if (lstrcmpi(TEXT("{35378EAC-683F-11D2-A89A-00C04FBBCFA2}"), szName))
  628. {
  629. //
  630. // Get the list of GPOs this extension applied
  631. //
  632. StringToGuid(szName, &guid);
  633. lResult = GetAppliedGPOList (bMachine ? GPO_LIST_FLAG_MACHINE : 0, NULL, NULL,
  634. &guid, &pGPO);
  635. if (lResult == ERROR_SUCCESS)
  636. {
  637. if (pGPO)
  638. {
  639. //
  640. // Get the extension's friendly display name
  641. //
  642. lResult = RegOpenKeyEx (hKey, szName, 0, KEY_READ, &hSubKey);
  643. if (lResult == ERROR_SUCCESS)
  644. {
  645. dwSize = MAX_PATH * sizeof(TCHAR);
  646. lResult = RegQueryValueEx (hSubKey, NULL, 0, &dwType, (LPBYTE) &szBuffer,
  647. &dwSize);
  648. if (lResult == ERROR_SUCCESS)
  649. {
  650. PrintString(IDS_LINE2);
  651. if (bMachine)
  652. {
  653. PrintString (IDS_COMPPOLICY, szBuffer);
  654. }
  655. else
  656. {
  657. PrintString (IDS_USERPOLICY, szBuffer);
  658. }
  659. }
  660. else
  661. {
  662. PrintString(IDS_LINE2);
  663. if (bMachine)
  664. {
  665. PrintString (IDS_COMPPOLICY, szName);
  666. }
  667. else
  668. {
  669. PrintString (IDS_USERPOLICY, szName);
  670. }
  671. }
  672. //
  673. // Dump out the GPO list
  674. //
  675. pGPOTemp = pGPO;
  676. while (pGPOTemp)
  677. {
  678. PrintString(IDS_GPONAME, pGPOTemp->lpDisplayName);
  679. DumpGPOInfo (pGPOTemp);
  680. pGPOTemp = pGPOTemp->pNext;
  681. }
  682. //
  683. // If we're in verbose mode, then dump out some addition
  684. // information about certain extensions
  685. //
  686. if (g_bVerbose)
  687. {
  688. if (!lstrcmpi(TEXT("{827D319E-6EAC-11D2-A4EA-00C04F79F83A}"), szName))
  689. {
  690. PrintString(IDS_SECEDIT);
  691. }
  692. else if (!lstrcmpi(TEXT("{e437bc1c-aa7d-11d2-a382-00c04f991e27}"), szName))
  693. {
  694. DumpIPSec ();
  695. }
  696. else if (!lstrcmpi(TEXT("{25537BA6-77A8-11D2-9B6C-0000F8080861}"), szName))
  697. {
  698. DumpFolderRedir ();
  699. }
  700. else if (!lstrcmpi(TEXT("{3610eda5-77ef-11d2-8dc5-00c04fa31a66}"), szName))
  701. {
  702. DumpDiskQuota ();
  703. }
  704. else if (!lstrcmpi(TEXT("{c6dc5466-785a-11d2-84d0-00c04fb169f7}"), szName))
  705. {
  706. DumpAppMgmt (bMachine);
  707. }
  708. else if (!lstrcmpi(TEXT("{42B5FAAE-6536-11d2-AE5A-0000F87571E3}"), szName))
  709. {
  710. if (bMachine)
  711. {
  712. DumpScripts (pGPO, TEXT("Startup"), TEXT("Startup scripts specified in"));
  713. DumpScripts (pGPO, TEXT("Shutdown"), TEXT("Shutdown scripts specified in"));
  714. }
  715. else
  716. {
  717. DumpScripts (pGPO, TEXT("Logon"), TEXT("Logon scripts specified in"));
  718. DumpScripts (pGPO, TEXT("Logoff"), TEXT("Logoff scripts specified in"));
  719. }
  720. }
  721. else
  722. {
  723. PrintString(IDS_NOINFO);
  724. }
  725. }
  726. }
  727. FreeGPOList (pGPO);
  728. }
  729. }
  730. }
  731. dwIndex++;
  732. dwNameSize = 50;
  733. }
  734. RegCloseKey (hKey);
  735. }
  736. return ERROR_SUCCESS;
  737. }
  738. //*************************************************************
  739. //
  740. // StringToGuid()
  741. //
  742. // Purpose: Converts a GUID in string format to a GUID structure
  743. //
  744. // Parameters: szValue - guid in string format
  745. // pGuid - guid structure receiving the guid
  746. //
  747. //
  748. // Return: void
  749. //
  750. //*************************************************************
  751. void StringToGuid( TCHAR * szValue, GUID * pGuid )
  752. {
  753. WCHAR wc;
  754. INT i;
  755. //
  756. // If the first character is a '{', skip it
  757. //
  758. if ( szValue[0] == L'{' )
  759. szValue++;
  760. //
  761. // Since szValue may be used again, no permanent modification to
  762. // it is be made.
  763. //
  764. wc = szValue[8];
  765. szValue[8] = 0;
  766. pGuid->Data1 = wcstoul( &szValue[0], 0, 16 );
  767. szValue[8] = wc;
  768. wc = szValue[13];
  769. szValue[13] = 0;
  770. pGuid->Data2 = (USHORT)wcstoul( &szValue[9], 0, 16 );
  771. szValue[13] = wc;
  772. wc = szValue[18];
  773. szValue[18] = 0;
  774. pGuid->Data3 = (USHORT)wcstoul( &szValue[14], 0, 16 );
  775. szValue[18] = wc;
  776. wc = szValue[21];
  777. szValue[21] = 0;
  778. pGuid->Data4[0] = (unsigned char)wcstoul( &szValue[19], 0, 16 );
  779. szValue[21] = wc;
  780. wc = szValue[23];
  781. szValue[23] = 0;
  782. pGuid->Data4[1] = (unsigned char)wcstoul( &szValue[21], 0, 16 );
  783. szValue[23] = wc;
  784. for ( i = 0; i < 6; i++ )
  785. {
  786. wc = szValue[26+i*2];
  787. szValue[26+i*2] = 0;
  788. pGuid->Data4[2+i] = (unsigned char)wcstoul( &szValue[24+i*2], 0, 16 );
  789. szValue[26+i*2] = wc;
  790. }
  791. }
  792. //*************************************************************
  793. //
  794. // DumpProfileInfo()
  795. //
  796. // Purpose: Checks if the user has a roaming profile and if
  797. // so prints the storage path.
  798. //
  799. // Parameters: void
  800. //
  801. // Return: void
  802. //
  803. //*************************************************************
  804. void DumpProfileInfo (void)
  805. {
  806. LPTSTR lpSid = NULL;
  807. HANDLE hProcess = NULL;
  808. TCHAR szBuffer[MAX_PATH];
  809. TCHAR szBuffer2[MAX_PATH];
  810. HKEY hKey;
  811. DWORD dwType, dwSize;
  812. //
  813. // Get the user's token
  814. //
  815. if (!OpenProcessToken (GetCurrentProcess(), TOKEN_ALL_ACCESS, &hProcess))
  816. {
  817. PrintString(IDS_OPENPROCESSTOKEN, GetLastError());
  818. goto Exit;
  819. }
  820. //
  821. // Get the user's sid
  822. //
  823. lpSid = GetSidString(hProcess);
  824. if (!lpSid)
  825. {
  826. PrintString(IDS_QUERYSID);
  827. goto Exit;
  828. }
  829. //
  830. // Open the user's profile mapping key
  831. //
  832. wsprintf (szBuffer, PROFILE_LIST_PATH, lpSid);
  833. if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, szBuffer, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
  834. {
  835. szBuffer[0] = TEXT('\0');
  836. dwSize = MAX_PATH * sizeof(TCHAR);
  837. //
  838. // Get the roaming profile value
  839. //
  840. if (RegQueryValueEx (hKey, TEXT("CentralProfile"), NULL, &dwType,
  841. (LPBYTE) &szBuffer, &dwSize) == ERROR_SUCCESS)
  842. {
  843. if (szBuffer[0] != TEXT('\0'))
  844. {
  845. PrintString(IDS_ROAMINGPROFILE, szBuffer);
  846. }
  847. else
  848. {
  849. PrintString(IDS_NOROAMINGPROFILE);
  850. }
  851. }
  852. szBuffer[0] = TEXT('\0');
  853. dwSize = MAX_PATH * sizeof(TCHAR);
  854. //
  855. // Get the local profile value
  856. //
  857. if (RegQueryValueEx (hKey, TEXT("ProfileImagePath"), NULL, &dwType,
  858. (LPBYTE) &szBuffer, &dwSize) == ERROR_SUCCESS)
  859. {
  860. if (szBuffer[0] != TEXT('\0'))
  861. {
  862. ExpandEnvironmentStrings(szBuffer, szBuffer2, MAX_PATH);
  863. PrintString(IDS_LOCALPROFILE, szBuffer2);
  864. }
  865. else
  866. {
  867. PrintString(IDS_NOLOCALPROFILE);
  868. }
  869. }
  870. RegCloseKey (hKey);
  871. }
  872. Exit:
  873. if (lpSid)
  874. {
  875. DeleteSidString(lpSid);
  876. }
  877. if (hProcess)
  878. {
  879. CloseHandle (hProcess);
  880. }
  881. }
  882. //*************************************************************
  883. //
  884. // DumpSecurityGroups()
  885. //
  886. // Purpose: Dumps the user's / computer's security groups
  887. //
  888. // Parameters: bMachine
  889. //
  890. // Return: void
  891. //
  892. //*************************************************************
  893. void DumpSecurityGroups (BOOL bMachine)
  894. {
  895. DWORD dwSize, dwIndex, dwNameSize, dwDomainSize, dwCount, dwSidSize, dwType;
  896. TCHAR szName[100];
  897. TCHAR szDomain[100];
  898. TCHAR szValueName[25];
  899. SID_NAME_USE eUse;
  900. PSID pSid;
  901. HKEY hKey;
  902. LONG lResult;
  903. NTSTATUS status;
  904. LPTSTR pSidString;
  905. if (bMachine)
  906. {
  907. PrintString(IDS_SECURITYGROUPS2);
  908. }
  909. else
  910. {
  911. PrintString(IDS_SECURITYGROUPS1);
  912. }
  913. //
  914. // Open the registry key
  915. //
  916. lResult = RegOpenKeyEx ((bMachine ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER),
  917. TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Group Policy\\GroupMembership"),
  918. 0, KEY_READ, &hKey);
  919. if (lResult != ERROR_SUCCESS)
  920. {
  921. if ((lResult != ERROR_FILE_NOT_FOUND) && (lResult != ERROR_PATH_NOT_FOUND))
  922. {
  923. PrintString (IDS_OPENHISTORYFAILED, lResult);
  924. }
  925. return;
  926. }
  927. //
  928. // Query for the largest sid
  929. //
  930. lResult = RegQueryInfoKey (hKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  931. NULL, &dwSidSize, NULL, NULL);
  932. if (lResult != ERROR_SUCCESS)
  933. {
  934. PrintString(IDS_QUERYKEYINFOFAILED, lResult);
  935. RegCloseKey (hKey);
  936. return;
  937. }
  938. //
  939. // Allocate a buffer for the sid
  940. //
  941. pSidString = LocalAlloc (LPTR, dwSidSize);
  942. if (!pSidString)
  943. {
  944. PrintString(IDS_MEMALLOCFAILED, GetLastError());
  945. RegCloseKey (hKey);
  946. return;
  947. }
  948. //
  949. // Query for the number of sids
  950. //
  951. dwSize = sizeof(dwCount);
  952. lResult = RegQueryValueEx (hKey, TEXT("Count"), NULL, &dwType,
  953. (LPBYTE) &dwCount, &dwSize);
  954. if (lResult != ERROR_SUCCESS)
  955. {
  956. PrintString (IDS_QUERYVALUEFAILED, lResult);
  957. LocalFree (pSidString);
  958. RegCloseKey (hKey);
  959. return;
  960. }
  961. //
  962. // Lookup the friendly display name for each sid and print it on the screen
  963. //
  964. for (dwIndex = 0; dwIndex < dwCount; dwIndex++)
  965. {
  966. wsprintf (szValueName, TEXT("Group%d"), dwIndex);
  967. dwSize = dwSidSize;
  968. lResult = RegQueryValueEx (hKey, szValueName, NULL, &dwType,
  969. (LPBYTE) pSidString, &dwSize);
  970. if (lResult != ERROR_SUCCESS)
  971. {
  972. PrintString (IDS_QUERYVALUEFAILED, lResult);
  973. LocalFree (pSidString);
  974. RegCloseKey (hKey);
  975. return;
  976. }
  977. status = AllocateAndInitSidFromString (pSidString, &pSid);
  978. if (status != STATUS_SUCCESS)
  979. {
  980. PrintString (IDS_QUERYSID);
  981. LocalFree (pSidString);
  982. RegCloseKey (hKey);
  983. return;
  984. }
  985. dwNameSize = ARRAYSIZE(szName);
  986. dwDomainSize = ARRAYSIZE(szDomain);
  987. if (LookupAccountSid(NULL, pSid, szName, &dwNameSize,
  988. szDomain, &dwDomainSize, &eUse))
  989. {
  990. PrintString(IDS_GROUPNAME, szDomain, szName);
  991. }
  992. else
  993. {
  994. if (GetLastError() != ERROR_NONE_MAPPED)
  995. {
  996. PrintString(IDS_LOOKUPACCOUNT, GetLastError());
  997. }
  998. }
  999. RtlFreeSid(pSid);
  1000. }
  1001. LocalFree (pSidString);
  1002. RegCloseKey (hKey);
  1003. }
  1004. //*************************************************************
  1005. //
  1006. // DumpSecurityPrivileges()
  1007. //
  1008. // Purpose: Dumps the user's security privileges
  1009. //
  1010. // Parameters: void
  1011. //
  1012. // Return: void
  1013. //
  1014. //*************************************************************
  1015. void DumpSecurityPrivileges (void)
  1016. {
  1017. HANDLE hProcess;
  1018. DWORD dwSize, dwIndex, dwNameSize, dwLang;
  1019. TCHAR szName[100];
  1020. TCHAR szDisplayName[200];
  1021. TOKEN_PRIVILEGES *lpPrivileges;
  1022. PLUID pLuid;
  1023. LUID_AND_ATTRIBUTES *pEntry;
  1024. PrintString(IDS_SECURITYPRIVILEGES);
  1025. //
  1026. // Get the user's token
  1027. //
  1028. if (!OpenProcessToken (GetCurrentProcess(), TOKEN_ALL_ACCESS, &hProcess))
  1029. {
  1030. PrintString(IDS_OPENPROCESSTOKEN, GetLastError());
  1031. return;
  1032. }
  1033. //
  1034. // Query the token for the privileges
  1035. //
  1036. dwSize = 0;
  1037. GetTokenInformation(hProcess, TokenPrivileges, NULL, 0, &dwSize);
  1038. if (dwSize == 0)
  1039. {
  1040. PrintString(IDS_PRIVSIZE);
  1041. CloseHandle(hProcess);
  1042. return;
  1043. }
  1044. lpPrivileges = LocalAlloc (LPTR, dwSize);
  1045. if (!lpPrivileges)
  1046. {
  1047. PrintString(IDS_MEMALLOCFAILED, GetLastError());
  1048. CloseHandle(hProcess);
  1049. return;
  1050. }
  1051. if (!GetTokenInformation(hProcess, TokenPrivileges, lpPrivileges, dwSize, &dwSize))
  1052. {
  1053. PrintString(IDS_TOKENINFO, GetLastError());
  1054. LocalFree(lpPrivileges);
  1055. CloseHandle(hProcess);
  1056. return;
  1057. }
  1058. //
  1059. // Lookup the friendly display name for each privilege and print it on the screen
  1060. //
  1061. for (dwIndex = 0; dwIndex < lpPrivileges->PrivilegeCount; dwIndex++)
  1062. {
  1063. dwNameSize = 100;
  1064. pEntry = &lpPrivileges->Privileges[dwIndex];
  1065. pLuid = &pEntry->Luid;
  1066. if (LookupPrivilegeName(NULL, pLuid, szName, &dwNameSize))
  1067. {
  1068. dwNameSize = 200;
  1069. if (LookupPrivilegeDisplayName (NULL, szName, szDisplayName, &dwNameSize, &dwLang))
  1070. {
  1071. PrintString(IDS_GPONAME, szDisplayName);
  1072. }
  1073. else
  1074. {
  1075. PrintString(IDS_GPONAME, szName);
  1076. }
  1077. }
  1078. else
  1079. {
  1080. if (GetLastError() != ERROR_NONE_MAPPED)
  1081. {
  1082. PrintString(IDS_LOOKUPFAILED, GetLastError());
  1083. }
  1084. }
  1085. }
  1086. LocalFree (lpPrivileges);
  1087. CloseHandle (hProcess);
  1088. }
  1089. //*************************************************************
  1090. //
  1091. // DumpGPOInfo()
  1092. //
  1093. // Purpose: Prints the details about a specific GPO
  1094. //
  1095. // Parameters: pGPO - a GPO
  1096. //
  1097. // Return: void
  1098. //
  1099. //*************************************************************
  1100. void DumpGPOInfo (PGROUP_POLICY_OBJECT pGPO)
  1101. {
  1102. TCHAR szBuffer[2 * MAX_PATH];
  1103. LPTSTR lpTemp;
  1104. if (!g_bVerbose)
  1105. {
  1106. return;
  1107. }
  1108. //
  1109. // Print the version number and guid
  1110. //
  1111. if (g_bSuperVerbose)
  1112. {
  1113. if (g_bNewFunc)
  1114. {
  1115. PrintString(IDS_REVISIONNUMBER1, LOWORD(pGPO->dwVersion), HIWORD(pGPO->dwVersion));
  1116. }
  1117. else
  1118. {
  1119. PrintString(IDS_REVISIONNUMBER2, pGPO->dwVersion);
  1120. }
  1121. }
  1122. else
  1123. {
  1124. if (g_bNewFunc)
  1125. {
  1126. PrintString(IDS_REVISIONNUMBER2, LOWORD(pGPO->dwVersion));
  1127. }
  1128. else
  1129. {
  1130. PrintString(IDS_REVISIONNUMBER2, pGPO->dwVersion);
  1131. }
  1132. }
  1133. PrintString(IDS_UNIQUENAME, pGPO->szGPOName);
  1134. //
  1135. // To get the domain name, we parse the UNC path because the domain name
  1136. // is also the server name
  1137. //
  1138. lstrcpy (szBuffer, (pGPO->lpFileSysPath+2));
  1139. lpTemp = szBuffer;
  1140. while (*lpTemp && *lpTemp != TEXT('\\'))
  1141. lpTemp++;
  1142. if (*lpTemp == TEXT('\\'))
  1143. {
  1144. *lpTemp = TEXT('\0');
  1145. PrintString(IDS_DOMAINNAME2, szBuffer);
  1146. }
  1147. //
  1148. // Print out where this GPO was linked (LSDOU)
  1149. //
  1150. if (g_bNewFunc)
  1151. {
  1152. switch (pGPO->GPOLink)
  1153. {
  1154. case GPLinkMachine:
  1155. PrintString(IDS_LOCALLINK);
  1156. break;
  1157. case GPLinkSite:
  1158. PrintString(IDS_SITELINK, (pGPO->lpLink + 7));
  1159. break;
  1160. case GPLinkDomain:
  1161. PrintString(IDS_DOMAINLINK, (pGPO->lpLink + 7));
  1162. break;
  1163. case GPLinkOrganizationalUnit:
  1164. PrintString(IDS_OULINK, (pGPO->lpLink + 7));
  1165. break;
  1166. case GPLinkUnknown:
  1167. default:
  1168. PrintString(IDS_UNKNOWNLINK);
  1169. break;
  1170. }
  1171. }
  1172. PrintString(IDS_NEWLINE);
  1173. }
  1174. //*************************************************************
  1175. //
  1176. // DumpFolderRedir()
  1177. //
  1178. // Purpose: Prints any redirected folder locations
  1179. //
  1180. // Parameters: void
  1181. //
  1182. // Return: void
  1183. //
  1184. //*************************************************************
  1185. void DumpFolderRedir (void)
  1186. {
  1187. TCHAR szPath[2 * MAX_PATH];
  1188. TCHAR szNames[200];
  1189. LPTSTR lpName;
  1190. TCHAR szRdr[2 * MAX_PATH];
  1191. if (!g_bVerbose)
  1192. {
  1193. return;
  1194. }
  1195. //
  1196. // Get the path to the local settings\app data folder
  1197. //
  1198. if (SHGetFolderPath (NULL, CSIDL_LOCAL_APPDATA , NULL, SHGFP_TYPE_CURRENT, szPath) != S_OK)
  1199. {
  1200. PrintString(IDS_GETFOLDERPATH);
  1201. return;
  1202. }
  1203. //
  1204. // Tack on the folder rdr specific stuff
  1205. //
  1206. lstrcat (szPath, TEXT("\\Microsoft\\Windows\\File Deployment\\{25537BA6-77A8-11D2-9B6C-0000F8080861}.ini"));
  1207. //
  1208. // Grab the section names from the ini file
  1209. //
  1210. if (!GetPrivateProfileSectionNames (szNames, 200, szPath))
  1211. {
  1212. PrintString(IDS_GETPRIVATEPROFILE);
  1213. return;
  1214. }
  1215. //
  1216. // Loop through the sections getting the path value for each. If the path
  1217. // doesn't start with %userprofile%, then we assume it has been redirected.
  1218. //
  1219. lpName = szNames;
  1220. while (*lpName)
  1221. {
  1222. GetPrivateProfileString (lpName, TEXT("Path"), TEXT("%USERPROFILE%"), szRdr,
  1223. 2 * MAX_PATH, szPath);
  1224. if (CompareString (LOCALE_USER_DEFAULT, NORM_IGNORECASE, szRdr, 13,
  1225. TEXT("%USERPROFILE%"), 13) != CSTR_EQUAL)
  1226. {
  1227. PrintString(IDS_FOLDERREDIR, lpName, szRdr);
  1228. }
  1229. lpName = lpName + lstrlen(lpName) + 1;
  1230. }
  1231. }
  1232. //*************************************************************
  1233. //
  1234. // DumpIPSec()
  1235. //
  1236. // Purpose: Dumps out the IPSec information
  1237. //
  1238. // Parameters: none
  1239. //
  1240. // Return: void
  1241. //
  1242. //*************************************************************
  1243. void DumpIPSec (void)
  1244. {
  1245. HKEY hKey;
  1246. DWORD dwSize, dwType;
  1247. TCHAR szBuffer[350];
  1248. if (RegOpenKeyEx (HKEY_LOCAL_MACHINE,
  1249. TEXT("Software\\Policies\\Microsoft\\Windows\\IPSec\\GPTIPSECPolicy"),
  1250. 0,
  1251. KEY_READ,
  1252. &hKey) == ERROR_SUCCESS)
  1253. {
  1254. dwSize = 350 * sizeof(TCHAR);
  1255. szBuffer[0] = TEXT('\0');
  1256. if (RegQueryValueEx (hKey, TEXT("DSIPSECPolicyName"),
  1257. NULL, &dwType, (LPBYTE) szBuffer, &dwSize) == ERROR_SUCCESS)
  1258. {
  1259. PrintString(IDS_IPSEC_NAME, szBuffer);
  1260. }
  1261. dwSize = 350 * sizeof(TCHAR);
  1262. szBuffer[0] = TEXT('\0');
  1263. if (RegQueryValueEx (hKey, TEXT("DSIPSECPolicyDescription"),
  1264. NULL, &dwType, (LPBYTE) szBuffer, &dwSize) == ERROR_SUCCESS)
  1265. {
  1266. PrintString(IDS_IPSEC_DESC, szBuffer);
  1267. }
  1268. dwSize = 350 * sizeof(TCHAR);
  1269. szBuffer[0] = TEXT('\0');
  1270. if (RegQueryValueEx (hKey, TEXT("DSIPSECPolicyPath"),
  1271. NULL, &dwType, (LPBYTE) szBuffer, &dwSize) == ERROR_SUCCESS)
  1272. {
  1273. PrintString(IDS_IPSEC_PATH, szBuffer);
  1274. }
  1275. RegCloseKey (hKey);
  1276. }
  1277. }
  1278. //*************************************************************
  1279. //
  1280. // DumpDiskQuota()
  1281. //
  1282. // Purpose: Dumps out the disk quota policies
  1283. //
  1284. // Parameters: none
  1285. //
  1286. // Return: void
  1287. //
  1288. //*************************************************************
  1289. void DumpDiskQuota (void)
  1290. {
  1291. HKEY hKey;
  1292. DWORD dwSize, dwType, dwData;
  1293. TCHAR szBuffer[350];
  1294. if (RegOpenKeyEx (HKEY_LOCAL_MACHINE,
  1295. TEXT("Software\\Policies\\Microsoft\\Windows NT\\DiskQuota"),
  1296. 0,
  1297. KEY_READ,
  1298. &hKey) == ERROR_SUCCESS)
  1299. {
  1300. //
  1301. // Query for enabled
  1302. //
  1303. dwSize = sizeof(dwData);
  1304. dwData = 0;
  1305. RegQueryValueEx (hKey, TEXT("Enable"),
  1306. NULL, &dwType, (LPBYTE) &dwData, &dwSize);
  1307. if (dwData)
  1308. {
  1309. PrintString (IDS_DQ_ENABLED1);
  1310. }
  1311. else
  1312. {
  1313. PrintString (IDS_DQ_ENABLED2);
  1314. }
  1315. //
  1316. // Query for enforced
  1317. //
  1318. dwSize = sizeof(dwData);
  1319. dwData = 0;
  1320. RegQueryValueEx (hKey, TEXT("Enforce"),
  1321. NULL, &dwType, (LPBYTE) &dwData, &dwSize);
  1322. if (dwData)
  1323. {
  1324. PrintString (IDS_DQ_ENFORCED1);
  1325. }
  1326. else
  1327. {
  1328. PrintString (IDS_DQ_ENFORCED2);
  1329. }
  1330. //
  1331. // Query for limit
  1332. //
  1333. dwSize = sizeof(dwData);
  1334. dwData = 0xFFFFFFFF;
  1335. RegQueryValueEx (hKey, TEXT("Limit"),
  1336. NULL, &dwType, (LPBYTE) &dwData, &dwSize);
  1337. if (dwData != 0xFFFFFFFF)
  1338. {
  1339. PrintString (IDS_DQ_LIMIT1, dwData);
  1340. dwSize = sizeof(dwData);
  1341. dwData = 2;
  1342. RegQueryValueEx (hKey, TEXT("LimitUnits"),
  1343. NULL, &dwType, (LPBYTE) &dwData, &dwSize);
  1344. switch (dwData)
  1345. {
  1346. case 1:
  1347. PrintString (IDS_DQ_KB);
  1348. break;
  1349. case 2:
  1350. PrintString (IDS_DQ_MB);
  1351. break;
  1352. case 3:
  1353. PrintString (IDS_DQ_GB);
  1354. break;
  1355. case 4:
  1356. PrintString (IDS_DQ_TB);
  1357. break;
  1358. case 5:
  1359. PrintString (IDS_DQ_PB);
  1360. break;
  1361. case 6:
  1362. PrintString (IDS_DQ_EB);
  1363. break;
  1364. }
  1365. }
  1366. else
  1367. {
  1368. PrintString (IDS_DQ_LIMIT2);
  1369. }
  1370. //
  1371. // Query for warning level
  1372. //
  1373. dwSize = sizeof(dwData);
  1374. dwData = 0xFFFFFFFF;
  1375. RegQueryValueEx (hKey, TEXT("Threshold"),
  1376. NULL, &dwType, (LPBYTE) &dwData, &dwSize);
  1377. if (dwData != 0xFFFFFFFF)
  1378. {
  1379. PrintString (IDS_DQ_WARNING1, dwData);
  1380. dwSize = sizeof(dwData);
  1381. dwData = 2;
  1382. RegQueryValueEx (hKey, TEXT("ThresholdUnits"),
  1383. NULL, &dwType, (LPBYTE) &dwData, &dwSize);
  1384. switch (dwData)
  1385. {
  1386. case 1:
  1387. PrintString (IDS_DQ_KB);
  1388. break;
  1389. case 2:
  1390. PrintString (IDS_DQ_MB);
  1391. break;
  1392. case 3:
  1393. PrintString (IDS_DQ_GB);
  1394. break;
  1395. case 4:
  1396. PrintString (IDS_DQ_TB);
  1397. break;
  1398. case 5:
  1399. PrintString (IDS_DQ_PB);
  1400. break;
  1401. case 6:
  1402. PrintString (IDS_DQ_EB);
  1403. break;
  1404. }
  1405. }
  1406. else
  1407. {
  1408. PrintString (IDS_DQ_WARNING2);
  1409. }
  1410. //
  1411. // Log event over limit
  1412. //
  1413. dwSize = sizeof(dwData);
  1414. dwData = 0;
  1415. RegQueryValueEx (hKey, TEXT("LogEventOverLimit"),
  1416. NULL, &dwType, (LPBYTE) &dwData, &dwSize);
  1417. if (dwData)
  1418. {
  1419. PrintString (IDS_DQ_LIMIT_EXCEED1);
  1420. }
  1421. else
  1422. {
  1423. PrintString (IDS_DQ_LIMIT_EXCEED2);
  1424. }
  1425. //
  1426. // Log event over threshold
  1427. //
  1428. dwSize = sizeof(dwData);
  1429. dwData = 0;
  1430. RegQueryValueEx (hKey, TEXT("LogEventOverThreshold"),
  1431. NULL, &dwType, (LPBYTE) &dwData, &dwSize);
  1432. if (dwData)
  1433. {
  1434. PrintString (IDS_DQ_LIMIT_EXCEED3);
  1435. }
  1436. else
  1437. {
  1438. PrintString (IDS_DQ_LIMIT_EXCEED4);
  1439. }
  1440. //
  1441. // Apply policy to removable media
  1442. //
  1443. dwSize = sizeof(dwData);
  1444. dwData = 0;
  1445. RegQueryValueEx (hKey, TEXT("ApplyToRemovableMedia"),
  1446. NULL, &dwType, (LPBYTE) &dwData, &dwSize);
  1447. if (dwData)
  1448. {
  1449. PrintString (IDS_DQ_REMOVABLE1);
  1450. }
  1451. else
  1452. {
  1453. PrintString (IDS_DQ_REMOVABLE2);
  1454. }
  1455. RegCloseKey (hKey);
  1456. }
  1457. }
  1458. void DumpScripts (PGROUP_POLICY_OBJECT pGPO, LPTSTR lpScriptType, LPTSTR lpTitle)
  1459. {
  1460. PGROUP_POLICY_OBJECT pGPOTemp;
  1461. TCHAR szPath[MAX_PATH];
  1462. TCHAR szCmdLine[MAX_PATH];
  1463. TCHAR szArgs[MAX_PATH];
  1464. TCHAR szTemp[30];
  1465. DWORD dwIndex;
  1466. BOOL bShowTitle;
  1467. pGPOTemp = pGPO;
  1468. while (pGPOTemp)
  1469. {
  1470. bShowTitle = TRUE;
  1471. lstrcpy (szPath, pGPOTemp->lpFileSysPath);
  1472. lstrcat (szPath, TEXT("\\Scripts\\Scripts.ini"));
  1473. dwIndex = 0;
  1474. while (TRUE)
  1475. {
  1476. //
  1477. // Get the command line
  1478. //
  1479. szCmdLine[0] = TEXT('\0');
  1480. wsprintf (szTemp, TEXT("%dCmdLine"), dwIndex);
  1481. GetPrivateProfileString (lpScriptType, szTemp, TEXT(""),
  1482. szCmdLine, MAX_PATH,
  1483. szPath);
  1484. //
  1485. // If the command line is empty, we're finished
  1486. //
  1487. if (szCmdLine[0] == TEXT('\0'))
  1488. {
  1489. break;
  1490. }
  1491. //
  1492. // Get the parameters
  1493. //
  1494. szArgs[0] = TEXT('\0');
  1495. wsprintf (szTemp, TEXT("%dParameters"), dwIndex);
  1496. GetPrivateProfileString (lpScriptType, szTemp, TEXT(""),
  1497. szArgs, MAX_PATH,
  1498. szPath);
  1499. if (bShowTitle)
  1500. {
  1501. PrintString(IDS_SCRIPTS_TITLE, lpTitle, pGPOTemp->lpDisplayName);
  1502. bShowTitle = FALSE;
  1503. }
  1504. PrintString(IDS_SCRIPTS_ENTRY, szCmdLine, szArgs);
  1505. dwIndex++;
  1506. }
  1507. pGPOTemp = pGPOTemp->pNext;
  1508. }
  1509. }
  1510. void DumpAppMgmt (BOOL bMachine)
  1511. {
  1512. DWORD dwNumApps = 0, i, dwCount;
  1513. PMANAGEDAPPLICATION pPubApps = NULL;
  1514. PLOCALMANAGEDAPPLICATION pLocalApps = NULL;
  1515. //
  1516. // Assigned applications first
  1517. //
  1518. if (bMachine)
  1519. {
  1520. PrintString(IDS_APPMGMT_TITLE1);
  1521. }
  1522. else
  1523. {
  1524. PrintString (IDS_APPMGMT_TITLE2);
  1525. }
  1526. dwCount = 0;
  1527. if (GetLocalManagedApplications (!bMachine, &dwNumApps, &pLocalApps) == ERROR_SUCCESS)
  1528. {
  1529. for (i=0; i < dwNumApps; i++)
  1530. {
  1531. if (pLocalApps[i].dwState & LOCALSTATE_ASSIGNED)
  1532. {
  1533. PrintString(IDS_APPMGMT_NAME, pLocalApps[i].pszDeploymentName);
  1534. PrintString(IDS_APPMGMT_GPONAME, pLocalApps[i].pszPolicyName);
  1535. if (pLocalApps[i].dwState & LOCALSTATE_POLICYREMOVE_ORPHAN)
  1536. {
  1537. PrintString(IDS_APPMGMT_ORPHAN);
  1538. }
  1539. if (pLocalApps[i].dwState & LOCALSTATE_POLICYREMOVE_UNINSTALL)
  1540. {
  1541. PrintString(IDS_APPMGMT_UNINSTALL);
  1542. }
  1543. dwCount++;
  1544. }
  1545. }
  1546. }
  1547. if (dwCount == 0)
  1548. {
  1549. PrintString(IDS_APPMGMT_NONE);
  1550. }
  1551. //
  1552. // Exit now if this is machine processing
  1553. //
  1554. if (bMachine)
  1555. {
  1556. if (pLocalApps)
  1557. {
  1558. LocalFree (pLocalApps);
  1559. }
  1560. return;
  1561. }
  1562. //
  1563. // Now published applications
  1564. //
  1565. PrintString(IDS_APPMGMT_TITLE3);
  1566. dwCount = 0;
  1567. for (i=0; i < dwNumApps; i++)
  1568. {
  1569. if (pLocalApps[i].dwState & LOCALSTATE_PUBLISHED)
  1570. {
  1571. PrintString(IDS_APPMGMT_NAME, pLocalApps[i].pszDeploymentName);
  1572. PrintString(IDS_APPMGMT_GPONAME, pLocalApps[i].pszPolicyName);
  1573. if (pLocalApps[i].dwState & LOCALSTATE_POLICYREMOVE_ORPHAN)
  1574. {
  1575. PrintString(IDS_APPMGMT_ORPHAN);
  1576. }
  1577. if (pLocalApps[i].dwState & LOCALSTATE_POLICYREMOVE_UNINSTALL)
  1578. {
  1579. PrintString(IDS_APPMGMT_UNINSTALL);
  1580. }
  1581. dwCount++;
  1582. }
  1583. }
  1584. if (dwCount == 0)
  1585. {
  1586. PrintString(IDS_APPMGMT_NONE);
  1587. }
  1588. if (pLocalApps)
  1589. {
  1590. LocalFree (pLocalApps);
  1591. }
  1592. //
  1593. // Exit now if we are not in super verbose mode
  1594. //
  1595. if (!g_bSuperVerbose)
  1596. {
  1597. PrintString(IDS_APPMGMT_ARP1);
  1598. return;
  1599. }
  1600. //
  1601. // Query for the full list of published applications
  1602. //
  1603. PrintString(IDS_APPMGMT_ARP2);
  1604. dwCount = 0;
  1605. if (GetManagedApplications (NULL, MANAGED_APPS_USERAPPLICATIONS, MANAGED_APPS_INFOLEVEL_DEFAULT,
  1606. &dwNumApps, &pPubApps) == ERROR_SUCCESS)
  1607. {
  1608. for (i=0; i < dwNumApps; i++)
  1609. {
  1610. PrintString(IDS_APPMGMT_NAME, pPubApps[i].pszPackageName);
  1611. PrintString(IDS_APPMGMT_GPONAME, pPubApps[i].pszPolicyName);
  1612. if (pPubApps[i].bInstalled)
  1613. {
  1614. PrintString(IDS_APPMGMT_STATE1);
  1615. }
  1616. else
  1617. {
  1618. PrintString(IDS_APPMGMT_STATE2);
  1619. }
  1620. dwCount++;
  1621. }
  1622. if (pPubApps)
  1623. {
  1624. LocalFree (pPubApps);
  1625. }
  1626. }
  1627. if (dwCount == 0)
  1628. {
  1629. PrintString(IDS_APPMGMT_NONE);
  1630. }
  1631. }
  1632. void PrintString(UINT uiStringId, ...)
  1633. {
  1634. LPTSTR lpMsg;
  1635. TCHAR szFormat[100];
  1636. TCHAR szBuffer[200];
  1637. va_list marker;
  1638. va_start(marker, uiStringId);
  1639. if (LoadString (GetModuleHandle(NULL), uiStringId, szFormat, ARRAYSIZE(szFormat)))
  1640. {
  1641. wvsprintf(szBuffer, szFormat, marker);
  1642. if (g_bDebuggerOutput)
  1643. {
  1644. OutputDebugString (szBuffer);
  1645. }
  1646. else
  1647. {
  1648. _tprintf(TEXT("%s"), szBuffer);
  1649. }
  1650. }
  1651. va_end(marker);
  1652. }