home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 June / Chip_2001-06_cd1.bin / zkuste / vbasic / Data / Utility / MSISDK15.msi / WiPolicy.vbs < prev    next >
Text File  |  2000-10-05  |  7KB  |  107 lines

  1. ' Windows Installer utility to manage installer policy settings
  2. ' For use with Windows Scripting Host, CScript.exe or WScript.exe
  3. ' Copyright (c) 1999-2000, Microsoft Corporation
  4. ' Demonstrates the use of the installer policy keys
  5. ' Policy can be configured by an administrator using the NT Group Policy Editor
  6. '
  7. Option Explicit
  8.  
  9. Dim policies(13, 4)
  10. policies(0, 0)="LM" : policies(0, 1)="HKLM" : policies(0, 2)="Logging"              : policies(0, 3)="REG_SZ"    : policies(0, 4) = "Logging modes if not supplied by install from set iwearucmpv"
  11. policies(1, 0)="DO" : policies(1, 1)="HKLM" : policies(1, 2)="Debug"                : policies(1, 3)="REG_DWORD" : policies(1, 4) = "     OutputDebugString: 1=debug output, 2=verbose debug output"
  12. policies(2, 0)="DI" : policies(2, 1)="HKLM" : policies(2, 2)="DisableMsi"           : policies(2, 3)="REG_DWORD" : policies(2, 4) = "   1=Disable non-managed installs, 2=disable all installs"
  13. policies(3, 0)="WT" : policies(3, 1)="HKLM" : policies(3, 2)="Timeout"              : policies(3, 3)="REG_DWORD" : policies(3, 4) = "              Wait timeout in seconds in case of no activity"
  14. policies(4, 0)="DB" : policies(4, 1)="HKLM" : policies(4, 2)="DisableBrowse"        : policies(4, 3)="REG_DWORD" : policies(4, 4) = "        Disable user browsing of source locations if 1"
  15. policies(5, 0)="DP" : policies(5, 1)="HKLM" : policies(5, 2)="DisablePatch"         : policies(5, 3)="REG_DWORD" : policies(5, 4) = "         Disable patch application to all products if 1"
  16. policies(6, 0)="UC" : policies(6, 1)="HKLM" : policies(6, 2)="EnableUserControl"    : policies(6, 3)="REG_DWORD" : policies(6, 4) = "    Public properties sent to install service if 1"
  17. policies(7, 0)="SS" : policies(7, 1)="HKLM" : policies(7, 2)="SafeForScripting"     : policies(7, 3)="REG_DWORD" : policies(7, 4) = "     Installer safe for scripting from browser if 1"
  18. policies(8, 0)="EM" : policies(8, 1)="HKLM" : policies(8, 2)="AlwaysInstallElevated": policies(8, 3)="REG_DWORD" : policies(8, 4) = "System privileges if 1 and HKCU value also set"
  19. policies(9, 0)="EU" : policies(9, 1)="HKCU" : policies(9, 2)="AlwaysInstallElevated": policies(9, 3)="REG_DWORD" : policies(9, 4) = "System privileges if 1 and HKLM value also set"
  20. policies(10,0)="DR" : policies(10,1)="HKCU" : policies(10,2)="DisableRollback"      : policies(10,3)="REG_DWORD" : policies(10,4) = "      Disable rollback if 1 - use is not recommended"
  21. policies(11,0)="TS" : policies(11,1)="HKCU" : policies(11,2)="TransformsAtSource"   : policies(11,3)="REG_DWORD" : policies(11,4) = "   Locate transforms at root of source image if 1"
  22. policies(12,0)="TP" : policies(12,1)="HKCU" : policies(12,2)="TransformsSecure"     : policies(12,3)="REG_DWORD" : policies(12,4) = "     Pin secure tranforms in client-side-cache if 1"
  23. policies(13,0)="SO" : policies(13,1)="HKCU" : policies(13,2)="SearchOrder"          : policies(13,3)="REG_SZ"    : policies(13,4) = "Search order of source types, set of n,m,u (default=nmu)"
  24.  
  25. Dim argCount:argCount = Wscript.Arguments.Count
  26. Dim message, iPolicy, policyKey, policyValue, WshShell, policyCode
  27. On Error Resume Next
  28.  
  29. ' If no arguments supplied, then list all current policy settings
  30. If argCount = 0 Then
  31.     Set WshShell = WScript.CreateObject("WScript.Shell") : CheckError
  32.     For iPolicy = 0 To UBound(policies)
  33.         policyValue = ReadPolicyValue(iPolicy)
  34.         If Not IsEmpty(policyValue) Then 'policy key present, else skip display
  35.             If Not IsEmpty(message) Then message = message & vbLf
  36.             message = message & policies(iPolicy,0) & ": " & policies(iPolicy,2) & "(" & policies(iPolicy,1) & ") = " & policyValue
  37.         End If
  38.     Next
  39.     If IsEmpty(message) Then message = "No installer policies set"
  40.     Wscript.Echo message
  41.     Wscript.Quit 0
  42. End If
  43.  
  44. ' Check for ?, and show help message if found
  45. policyCode = UCase(Wscript.Arguments(0))
  46. If InStr(1, policyCode, "?", vbTextCompare) <> 0 Then
  47.     message = "Windows Installer utility to manage installer policy settings" &_
  48.         vbLf & " If no arguments are supplied, current policy settings in list will be reported" &_
  49.         vbLf & " The 1st argument specifies the policy to set, using a code from the list below" &_
  50.         vbLf & " The 2nd argument specifies the new policy setting, use """" to remove the policy" &_
  51.         vbLf & " If the 2nd argument is not supplied, the current policy value will be reported"
  52.     For iPolicy = 0 To UBound(policies)
  53.         message = message & vbLf & policies(iPolicy,0) & ": " & policies(iPolicy,2) & "(" & policies(iPolicy,1) & ")  " & policies(iPolicy,4)
  54.     Next
  55.     message = message & vblf & vblf & "Copyright (C) Microsoft Corporation, 1999-2000.  All rights reserved."
  56.  
  57.     Wscript.Echo message
  58.     Wscript.Quit 1
  59. End If
  60.  
  61. ' Policy code supplied, look up in array
  62. For iPolicy = 0 To UBound(policies)
  63.     If policies(iPolicy, 0) = policyCode Then Exit For
  64. Next
  65. If iPolicy > UBound(policies) Then Wscript.Echo "Unknown policy code: " & policyCode : Wscript.Quit 2
  66. Set WshShell = WScript.CreateObject("WScript.Shell") : CheckError
  67.  
  68. ' If no value supplied, then simply report current value
  69. policyValue = ReadPolicyValue(iPolicy)
  70. If IsEmpty(policyValue) Then policyValue = "Not present"
  71. message = policies(iPolicy,0) & ": " & policies(iPolicy,2) & "(" & policies(iPolicy,1) & ") = " & policyValue
  72. If argCount > 1 Then ' Value supplied, set policy
  73.     policyValue = WritePolicyValue(iPolicy, Wscript.Arguments(1))
  74.     If IsEmpty(policyValue) Then policyValue = "Not present"
  75.     message = message & " --> " & policyValue
  76. End If
  77. Wscript.Echo message
  78.  
  79. Function ReadPolicyValue(iPolicy)
  80.     On Error Resume Next
  81.     Dim policyKey:policyKey = policies(iPolicy,1) & "\Software\Policies\Microsoft\Windows\Installer\" & policies(iPolicy,2)
  82.     ReadPolicyValue = WshShell.RegRead(policyKey)
  83. End Function
  84.  
  85. Function WritePolicyValue(iPolicy, policyValue)
  86.     On Error Resume Next
  87.     Dim policyKey:policyKey = policies(iPolicy,1) & "\Software\Policies\Microsoft\Windows\Installer\" & policies(iPolicy,2)
  88.     If Len(policyValue) Then
  89.         WshShell.RegWrite policyKey, policyValue, policies(iPolicy,3) : CheckError
  90.         WritePolicyValue = policyValue
  91.     ElseIf Not IsEmpty(ReadPolicyValue(iPolicy)) Then
  92.         WshShell.RegDelete policyKey : CheckError
  93.     End If
  94. End Function
  95.  
  96. Sub CheckError
  97.     Dim message, errRec
  98.     If Err = 0 Then Exit Sub
  99.     message = Err.Source & " " & Hex(Err) & ": " & Err.Description
  100.     If Not installer Is Nothing Then
  101.         Set errRec = installer.LastErrorRecord
  102.         If Not errRec Is Nothing Then message = message & vbLf & errRec.FormatText
  103.     End If
  104.     Wscript.Echo message
  105.     Wscript.Quit 2
  106. End Sub
  107.