home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / WindowsServerTrial / server.iso / sources / install.wim / 4 / Windows / System32 / SCregEdit.wsf < prev    next >
Encoding:
Text File  |  2008-01-05  |  37.0 KB  |  1,176 lines

  1. '********************************************************************
  2. '*
  3. '* Copyright (c) Microsoft Corporation. All rights reserved. 
  4. '*
  5. '* Module Name:    SCregEdit.wsf 
  6. '*
  7. '* Abstract:       Enables an administrator to edit particular registry
  8. '*                   settings.
  9. '*
  10. '* Version # 1.0.0.1005
  11. '*
  12. '********************************************************************
  13.  
  14. <job>
  15.  
  16. <script language="VBScript">
  17.  
  18.  
  19. ' Global declaration 
  20. OPTION EXPLICIT
  21.  
  22. 'ON ERROR RESUME NEXT
  23. Err.Clear
  24. ' Set constants for use throughout script
  25. CONST HKEY_CURRENT_USER             = &H80000001
  26. CONST HKEY_LOCAL_MACHINE            = &H80000002
  27. const KEY_SET_VALUE             = &H0001
  28. CONST ForReading                    = 1
  29.  
  30. CONST VIEWQUICKKEY                    = "/v"
  31. CONST HELPSWITCH                    = "/?"
  32. CONST CLISWITCH                        = "/CLI"
  33. CONST REGMULTISZ                    = "REG_MULTI_SZ"
  34. CONST REGSZ                        = "REG_SZ"
  35. CONST REGDWORD                        = "REG_DWORD"
  36. CONST CONST_CSCRIPT                 = 2
  37.  
  38. CONST strComputer                   = "."
  39.  
  40. Dim bHasAccessRight
  41. ' Get command line arguments
  42. Dim objArgs, oReg
  43. Dim Resource, Resource2, Resource3, Resource4, LocSwitch
  44. Set objArgs = WScript.Arguments
  45. ' establish object references.
  46. Dim objFSO, FILEPATH, langFSO
  47. Set objFSO = CreateObject("Scripting.FileSystemObject")
  48. Set langFSO = CreateObject("Scripting.FileSystemObject")
  49. FILEPATH = objFSO.GetAbsolutePathName(strComputer) 'Current folder path
  50.  
  51. Dim arrKeyList()
  52. Dim arrSwitchList()
  53.  
  54.  
  55. ' Check whether the script is run using CScript
  56. dim strScriptHost
  57.  
  58. strScriptHost = Right((LCase(Wscript.FullName)), 11)
  59. If strScriptHost <> "cscript.exe" Then 
  60.  
  61.    resource = GetLocalizedResource("L_UseCscript1_ErrorMessage")
  62.    resource2 = GetLocalizedResource("L_UseCscript2E_ErrorMessage")
  63.    resource3 = GetLocalizedResource("L_UseCscript3_ErrorMessage")
  64.  
  65.    WScript.Echo ( resource & vbCRLF & _
  66.         ExpandEnvironmentString(resource2) & resource3 )
  67.  
  68.    WScript.Quit(1000)
  69.  
  70. End If
  71.  
  72.  
  73. Call MainProcessingLoop
  74. ' ****************************************************************************************
  75. '* Function : MainProcessingLoop()
  76. '*
  77. '* Purpose  : This function is the main processing loop for the application. 
  78. '*
  79. '* Input:    
  80. '* Output:   
  81. '*
  82. ' ****************************************************************************************
  83. Sub MainProcessingLoop()
  84.  
  85.     ' Establish key values from text file to compare input.
  86.  
  87.     BuildKeyListArray()
  88.  
  89.     If objArgs.Count = 0 Then        'No arguments passed when running the script
  90.         ShowHelpInfo(HELPSWITCH)
  91.     ElseIf objArgs.Count = 1 Then
  92.         ShowHelpInfo(lcase(objArgs(0)))
  93.     elseif objArgs.count > 1 then
  94.         if lcase(objArgs(0)) = VIEWQUICKKEY or lcase(objArgs(1)) = VIEWQUICKKEY then
  95.             ' process view request
  96.             if lcase(objArgs(0)) = VIEWQUICKKEY then
  97.                 ViewSwitch(lcase(objArgs(1)))
  98.             else
  99.                 ViewSwitch(lcase(objArgs(0)))
  100.             End If
  101.         elseif objArgs(0) = HELPSWITCH or objArgs(1) = HELPSWITCH then
  102.             if objArgs(0) = HELPSWITCH then
  103.                 ShowHelpInfo(lcase(objArgs(1)))
  104.             else
  105.                 ShowHelpInfo(lcase(objArgs(0)))
  106.             end if
  107.         elseif objArgs(0) = CLISWITCH then
  108.             ShowCliHelp()
  109.         Else
  110.             ProcessSwitch(lcase(objArgs(0)))
  111.         End If
  112.     End If
  113. End Sub
  114. ' ****************************************************************************************
  115. '* Function : ProcessSwitch
  116. '*
  117. '* Purpose  : This function makes the updates to the registry based on the passed in switch
  118. '*              and other command line arguments.
  119. '*
  120. '* Input:    [in]  switch      The quick key for the registry entry to update
  121. '* Output:   
  122. '*
  123. ' ****************************************************************************************
  124. Sub ProcessSwitch(switch)
  125.     Dim k, arrValues, returnValue
  126.     k = -1
  127.     
  128.     k = GetArrayElement(switch)
  129.     if k <> -1 then
  130.     If CheckArgs(switch) = True Then            'Check if number of args expected and given are same
  131.         If SpecialCaseCheck(switch) = True Then
  132.             'Dim arrValues
  133.             If arrKeyList(k)(3) = REGMULTISZ Then
  134.                 arrValues = Array(objArgs(1), objArgs(2), objArgs(3))
  135.                 Call SetMultiStringValue(strComputer,HKEY_LOCAL_MACHINE,arrKeyList(k)(2),arrKeyList(k)(1),arrValues) 'Setting the MultiString value
  136.             ElseIf arrKeyList(k)(3) = REGSZ Then
  137.                 Call SetStringValue(strComputer, HKEY_LOCAL_MACHINE, arrKeyList(k)(2),arrKeyList(k)(1), CInt(objArgs(1))) 'Setting the MultiString value
  138.             ElseIf arrKeyList(k)(3) = REGDWORD Then
  139.                 Call SetDWORDValue(strComputer, HKEY_LOCAL_MACHINE, arrKeyList(k)(2),arrKeyList(k)(1), Int(objArgs(1))) 'Setting the DWORD value
  140.             End IF
  141.         Else If SpecialCaseCheck(switch) = "AU" Then
  142.             Call ConfigureAU(CInt(objArgs(1)))
  143.         End If
  144.  
  145.         End If
  146.     End If
  147.     else
  148.         resource = GetLocalizedResource("L10600")
  149.         Wscript.Echo(resource)
  150.     End If    
  151.  
  152. End Sub
  153. ' ****************************************************************************************
  154. '* Function : ViewSwitch()
  155. '*
  156. '* Purpose  : This sub allows the viewing of all registry elements.
  157. '*
  158. '* Input:    [in]  switch      the quickkey to the registry entry to view.
  159. '* Output:   
  160. '*
  161. ' ****************************************************************************************
  162. Sub ViewSwitch(switch)
  163.  
  164.     dim k, returnValue
  165.     returnValue = ""    
  166.     k = GetArrayElement(switch)
  167.  
  168.     if k <> -1 then
  169.         select case arrKeyList(k)(3)
  170.         case REGMULTISZ
  171.             returnValue = ViewMultiStringValue(strComputer, HKEY_LOCAL_MACHINE, arrKeyList(k)(2), arrKeyList(k)(1))
  172.         case REGDWORD
  173.             returnValue = ViewDWORDValue(strComputer, HKEY_LOCAL_MACHINE, arrKeyList(k)(2), arrKeyList(k)(1))
  174.         case REGSZ
  175.             returnValue = ViewStringValue(strComputer, HKEY_LOCAL_MACHINE, arrKeyList(k)(2), arrKeyList(k)(1))
  176.         end select
  177.         Wscript.Echo(arrKeyList(k)(2) & " " & arrKeyList(k)(1))
  178.         if isnull(returnValue) then
  179.             resource = GetLocalizedResource("L10565")
  180.             Wscript.Echo(resource)
  181.         else
  182.             resource = GetLocalizedResource("L10400")
  183.             Wscript.Echo(resource)
  184.             Wscript.Echo("" & returnValue)
  185.         end if
  186.     else
  187.         resource = GetLocalizedResource("L10600")
  188.         Wscript.Echo(resource)
  189.     end if                        
  190.  
  191. End Sub
  192.  
  193. ' ****************************************************************************************
  194. '* Function : ShowHelpInfo()
  195. '*
  196. '* Purpose  : This sub allows the viewing of help for a particular quick key.
  197. '*
  198. '* Input:    [in]  switch      the quickkey to the registry entry to view help for.
  199. '* Output:   
  200. '*
  201. ' ****************************************************************************************
  202. Sub ShowHelpInfo(switch)
  203.     dim keyCounter, counter, count, HelpCount
  204.     keyCounter = 0
  205.     counter = 1
  206.     dim helpLine
  207.     If switch = "/?" Then
  208.         'au help
  209.         Keycounter = 10
  210.         count = 1
  211.         For count = counter to keycounter
  212.             helpline = "au" & count
  213.             resource = GetLocalizedResource(helpline)
  214.             Wscript.Echo(resource)
  215.             If count = 4 or count = 5 or count = 7 Then
  216.                 Wscript.Echo()
  217.             End If
  218.         Next
  219.         Wscript.Echo()
  220.         Wscript.Echo()
  221.         'ar help
  222.         Keycounter = 5
  223.         count = 1
  224.         For count = counter to keycounter
  225.             helpline = "ar" & count
  226.             resource = GetLocalizedResource(helpline)
  227.             Wscript.Echo(resource)
  228.             If count = 2 or count = 3 Then
  229.                 Wscript.Echo()
  230.             End If
  231.         Next
  232.         HelpCount = 1
  233.         For HelpCount = HelpCount to 2
  234.             Wscript.Echo()
  235.             Wscript.Echo()
  236.             'cs and im help
  237.             Keycounter = 6
  238.             count = 1
  239.             For count = counter to keycounter
  240.                 If HelpCount = 1 then
  241.                     helpline = "cs" & count
  242.                 else
  243.                     helpline = "im" & count
  244.                 End If
  245.                 resource = GetLocalizedResource(helpline)
  246.                 Wscript.Echo(resource)
  247.                 If count = 3 or count = 4 Then
  248.                     Wscript.Echo()
  249.                 End If
  250.             Next
  251.         Next
  252.         HelpCount = 1
  253.         For HelpCount = HelpCount to 2
  254.             Wscript.Echo()
  255.             Wscript.Echo()
  256.             'dw and dp help
  257.             Keycounter = 7
  258.             count = 1
  259.             For count = counter to keycounter
  260.                 If HelpCount = 1 then
  261.                     helpline = "dp" & count
  262.                 else
  263.                     helpline = "dw" & count
  264.                 End If
  265.                 resource = GetLocalizedResource(helpline)
  266.                 Wscript.Echo(resource)
  267.                 If count = 4 or count = 5 Then
  268.                     Wscript.Echo()
  269.                 End If
  270.             Next
  271.         Next
  272.         Wscript.Echo()
  273.         Wscript.Echo()
  274.         'cli help
  275.         Keycounter = 4
  276.         count = 1
  277.         For count = counter to keycounter
  278.             helpline = "cli" & count
  279.             resource = GetLocalizedResource(helpline)
  280.             Wscript.Echo(resource)
  281.             If count = 3 Then
  282.                 Wscript.Echo()
  283.             End If
  284.         Next
  285.     Else
  286.         Select Case switch
  287.             Case arrSwitchList(0)
  288.                 'au help
  289.                 Keycounter = 10
  290.                 count = 1
  291.                 For count = counter to keycounter
  292.                     helpline = "au" & count
  293.                     resource = GetLocalizedResource(helpline)
  294.                     Wscript.Echo(resource)
  295.                     If count = 4 or count = 5 or count = 7 Then
  296.                         Wscript.Echo()
  297.                     End If
  298.                 Next
  299.             Case arrSwitchList(1)
  300.                 'ar help
  301.                 Keycounter = 5
  302.                 count = 1
  303.                 For count = counter to keycounter
  304.                     helpline = "ar" & count
  305.                     resource = GetLocalizedResource(helpline)
  306.                     Wscript.Echo(resource)
  307.                     If count = 2 or count = 3 Then
  308.                         Wscript.Echo()
  309.                     End If
  310.                 Next
  311.             Case arrSwitchList(2)
  312.                 'cs help
  313.                 Keycounter = 6
  314.                 count = 1
  315.                 For count = counter to keycounter
  316.                     helpline = "cs" & count
  317.                     resource = GetLocalizedResource(helpline)
  318.                     Wscript.Echo(resource)
  319.                     If count = 3 or count = 4 Then
  320.                         Wscript.Echo()
  321.                     End If
  322.                 Next
  323.             Case arrSwitchList(3)
  324.                 'im help
  325.                 Keycounter = 6
  326.                 count = 1
  327.                 For count = counter to keycounter
  328.                     helpline = "im" & count
  329.                     resource = GetLocalizedResource(helpline)
  330.                     Wscript.Echo(resource)
  331.                     If count = 3 or count = 4 Then
  332.                         Wscript.Echo()
  333.                     End If
  334.                 Next
  335.             Case arrSwitchList(4)
  336.                 'dp help
  337.                 Keycounter = 7
  338.                 count = 1
  339.                 For count = counter to keycounter
  340.                     helpline = "dp" & count
  341.                     resource = GetLocalizedResource(helpline)
  342.                     Wscript.Echo(resource)
  343.                     If count = 4 or count = 5 Then
  344.                         Wscript.Echo()
  345.                     End If
  346.                 Next
  347.             Case arrSwitchList(5)
  348.                 'dw help
  349.                 Keycounter = 7
  350.                 count = 1
  351.                 For count = counter to keycounter
  352.                     helpline = "dw" & count
  353.                     resource = GetLocalizedResource(helpline)
  354.                     Wscript.Echo(resource)
  355.                     If count = 4 or count = 5 Then
  356.                         Wscript.Echo()
  357.                     End If
  358.                 Next
  359.             Case arrSwitchList(6)
  360.                 'cli help
  361.                 ShowCliHelp()
  362.         Case Else
  363.             resource = GetLocalizedResource("L10600")
  364.             Wscript.Echo(resource)
  365.         End Select
  366.     End If
  367. End Sub
  368.  
  369. ' ****************************************************************************************
  370. '* Function : ShowCliHelp()
  371. '*
  372. '* Purpose  : This sub displays the command line tool help.
  373. '*
  374. '* Input:    
  375. '* Output:   
  376. '*
  377. ' ****************************************************************************************
  378. Sub ShowCliHelp()
  379.     dim keyCounter, counter, count, HelpCount
  380.     keyCounter = 88
  381.     counter = 0
  382.     dim helpLine
  383.     count = 1
  384.     For count = counter to keycounter
  385.         helpline = "L" & (10800 + count)
  386.         resource = GetLocalizedResource(helpline)
  387.         Wscript.Echo(resource)
  388.     Next
  389. End Sub
  390.  
  391. ' ****************************************************************************************
  392. '* Function : SpecialCaseCheck()
  393. '*
  394. '* Purpose  : This sub allows the handling of special cases when editing registry entries.
  395. '*
  396. '* Input:    [in]  switch      the quickkey to the registry entry to edit.
  397. '* Output:   returns true if entry still needs to be updated. False if passed in values do 
  398. '*             not meet criteria or if value is already updated.
  399. '*
  400. ' ****************************************************************************************
  401. Function SpecialCaseCheck(switch)
  402.     dim arrValues, k
  403.     Select Case switch
  404.         Case arrSwitchList(0)
  405.             If IsNumeric(objArgs(1)) = True Then
  406.                 If objArgs(1) = 1 or objArgs(1) = 4 Then
  407.                     SpecialCaseCheck = "AU"
  408.                 Else
  409.                     resource = GetLocalizedResource("L10570")
  410.                     Wscript.Echo(resource)
  411.                     Wscript.Echo()
  412.                     ShowHelpInfo(switch)
  413.                     SpecialCaseCheck = false
  414.                 End If
  415.             End If
  416.         Case arrSwitchList(1)
  417.             If IsNumeric(objArgs(1)) = True Then
  418.                 If objArgs(1) = 0 or objArgs(1) = 1 Then
  419.                     SpecialCaseCheck = True
  420.                 Else
  421.                     resource = GetLocalizedResource("L10580")
  422.                     Wscript.Echo(resource)
  423.                     Wscript.Echo()
  424.                     ShowHelpInfo(switch)
  425.                     SpecialCaseCheck = false
  426.                 End If
  427.             End If
  428.         Case arrSwitchList(2)
  429.             If IsNumeric(objArgs(1)) = True Then
  430.                 If objArgs(1) = 0 or objArgs(1) = 1 Then
  431.                     SpecialCaseCheck = True
  432.                 Else
  433.                     resource = GetLocalizedResource("L10580")
  434.                     Wscript.Echo(resource)
  435.                     Wscript.Echo()    
  436.                     ShowHelpInfo(switch)
  437.                     SpecialCaseCheck = false
  438.                 End If
  439.             End If
  440.         Case arrSwitchList(3)
  441.             If IsNumeric(objArgs(1)) = True Then
  442.                 If objArgs(1) = 0 or objArgs(1) = 1 Then
  443.                     SpecialCaseCheck = True
  444.                 Else
  445.                     resource = GetLocalizedResource("L10580")
  446.                     Wscript.Echo(resource)
  447.                     Wscript.Echo()    
  448.                     ShowHelpInfo(switch)
  449.                     SpecialCaseCheck = false
  450.                 End If
  451.             End If
  452.         Case arrSwitchList(4)
  453.             If IsNumeric(objArgs(1)) = True Then
  454.                 If objArgs(1) >= 0 and objArgs(1) <= 65535 Then
  455.                     SpecialCaseCheck = True
  456.                 Else
  457.                     resource = GetLocalizedResource("L10590")
  458.                     Wscript.Echo(resource)
  459.                     Wscript.Echo()    
  460.                     ShowHelpInfo(switch)
  461.                     SpecialCaseCheck = false
  462.                 End If
  463.             End If
  464.         Case arrSwitchList(5)
  465.             If IsNumeric(objArgs(1)) = True Then
  466.                 If objArgs(1) >= 0 and objArgs(1) <= 65535 Then
  467.                     SpecialCaseCheck = True
  468.                 Else
  469.                     resource = GetLocalizedResource("L10590")
  470.                     Wscript.Echo(resource)
  471.                     Wscript.Echo()    
  472.                     ShowHelpInfo(switch)
  473.                     SpecialCaseCheck = false
  474.                 End If
  475.             End If
  476.  
  477.         Case Else
  478.             SpecialCaseCheck = True
  479.     End Select
  480. End Function
  481.  
  482. ' ****************************************************************************************
  483. '* Function : GetArrayElement()
  484. '*
  485. '* Purpose  : This function determines which array value has the passed in switch
  486. '*
  487. '* Input:    [in]  switch      the quickkey to the registry entry to view.
  488. '* Output:   returns the index of the array that contains the switch.
  489. '*
  490. ' ****************************************************************************************
  491. Function GetArrayElement(switch)
  492.     dim k, returnValue
  493.     
  494.     returnValue = -1
  495.  
  496.     For k = 0 to Ubound(arrKeyList)
  497.         If arrKeyList(k)(0) = switch Then    'Find the array wtih first element as the switch in the arrKeyList array
  498.             returnValue = k
  499.         end if        
  500.     Next
  501.  
  502.     GetArrayElement = returnValue
  503.     
  504. End Function
  505. ' ****************************************************************************************
  506. '* Function : BuildKeyListArray()
  507. '*
  508. '* Purpose  : This sub sets a global array used throughout the script
  509. '*
  510. '* Input:    
  511. '* Output:   
  512. '*
  513. ' ****************************************************************************************
  514. Sub BuildKeyListArray()
  515.  
  516.     dim count, counter, keyCounter, RegCounter
  517.     dim regvalue
  518.     dim inputLine
  519.     Dim arrValues
  520.  
  521.     keyCounter = 0
  522.     counter = 0
  523.  
  524.     'Recounter must equal the number of registry switches supported - 1
  525.     Regcounter = 6
  526.     count = 0
  527.     For count = counter to RegCounter
  528.         regvalue = "reg" & count
  529.         inputLine = GetLocalizedResource(regvalue)
  530.         arrValues = split(inputLine, ",")    ' If not, then put the comma seperated line into an array
  531.            ReDim Preserve arrKeyList(keyCounter)        'Since we don't know how many switches are present in the file
  532.         arrKeyList(keyCounter) = arrValues            'For each switch from arrValues put it into arrKeyList
  533.         keyCounter = keyCounter + 1
  534.     Next
  535.  
  536.     keyCounter = 0
  537.     counter = 0
  538.     count = 0
  539.     For count = counter to RegCounter
  540.         regvalue = "switch" & count
  541.         inputLine = GetLocalizedResource(regvalue)
  542.         'arrValues = split(inputLine, ",")    ' If not, then put the comma seperated line into an array
  543.            ReDim Preserve arrSwitchList(keyCounter)        'Since we don't know how many switches are present in the file
  544.         arrSwitchList(keyCounter) = inputLine            'For each switch from arrValues put it into arrKeyList
  545.         keyCounter = keyCounter + 1
  546.     Next
  547.  
  548.  
  549.  
  550. End Sub
  551.  
  552. ' ****************************************************************************************
  553. '* Function : SetMultiStringValue()
  554. '*
  555. '* Purpose  : This sub is the generic function to set a multi string registry key.
  556. '*
  557. '* Input:    [in]  strComputer      the name of the computer
  558. '*             [in]  root             The root of the registry entry to update.
  559. '*             [in]  strKeyPath       path to registry entry to update.
  560. '*             [in]  strValueName     value name of registry entry to update.
  561. '*             [in]  arrValues        array of values to update.
  562. '* Output:   
  563. '*
  564. ' ****************************************************************************************
  565. Sub SetMultiStringValue(strComputer,root,strKeyPath, strValueName, arrValues)
  566.  
  567.     Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
  568.         strComputer & "\root\default:StdRegProv")
  569.  
  570.  
  571.     oReg.CheckAccess root, strKeyPath, _
  572.             KEY_SET_VALUE, bHasAccessRight
  573.  
  574.     If bHasAccessRight = True Then
  575.         oReg.SetMultiStringValue root,strKeyPath,strValueName,arrValues
  576.         resource = GetLocalizedResource("L10440")
  577.         Wscript.Echo(resource)
  578.     Else
  579.         resource = GetLocalizedResource("L10610")
  580.         Wscript.Echo(resource)
  581.         Wscript.Echo()
  582.     End If
  583.     
  584. End Sub
  585. ' ****************************************************************************************
  586. '* Function : ViewMultiStringValue()
  587. '*
  588. '* Purpose  : This sub is the generic function to view a multi string registry key.
  589. '*
  590. '* Input:    [in]  strComputer      the name of the computer
  591. '*             [in]  root             The root of the registry entry to update.
  592. '*             [in]  strKeyPath       path to registry entry to update.
  593. '*             [in]  strValueName     value name of registry entry to update.
  594. '* Output:   
  595. '*
  596. ' ****************************************************************************************
  597. Function ViewMultiStringValue(strComputer, root, strKeyPath, strValueName)
  598.     
  599.     dim i, arrValues, strValue, returnValue
  600.     
  601.     Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
  602.         strComputer & "\root\default:StdRegProv")
  603.  
  604.     oReg.GetMultiStringValue root ,strKeyPath, _
  605.         strValueName,arrValues
  606.     
  607.     For Each strValue In arrValues
  608.         returnValue = returnValue & strValue & " " 
  609.     Next
  610.     
  611.     ViewMultiStringValue = returnValue
  612.     
  613. End Function
  614. ' ****************************************************************************************
  615. '* Function : SetStringValue()
  616. '*
  617. '* Purpose  : This sub is the generic function to set a string registry key.
  618. '*
  619. '* Input:    [in]  strComputer      the name of the computer
  620. '*             [in]  root             The root of the registry entry to update.
  621. '*             [in]  strKeyPath       path to registry entry to update.
  622. '*             [in]  strValueName     value name of registry entry to update.
  623. '*             [in]  strValue         value to update.
  624. '* Output:   
  625. '*
  626. ' ****************************************************************************************
  627. Sub SetStringValue(strComputer, root, strKeyPath, strValueName, strValue)
  628.  
  629.     Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
  630.         strComputer & "\root\default:StdRegProv")
  631.  
  632.  
  633.     oReg.CheckAccess root, strKeyPath, _
  634.             KEY_SET_VALUE, bHasAccessRight
  635.  
  636.     If bHasAccessRight = True Then
  637.         oReg.SetStringValue root ,strKeyPath, strValueName, strValue
  638.         resource = GetLocalizedResource("L10440")
  639.         Wscript.Echo(resource)
  640.     Else
  641.         resource = GetLocalizedResource("L10610")
  642.         Wscript.Echo(resource)
  643.         Wscript.Echo()
  644.     End If
  645.  
  646.  
  647.     
  648. End Sub
  649. ' ****************************************************************************************
  650. '* Function : ViewStringValue()
  651. '*
  652. '* Purpose  : This sub is the generic function to view a string registry key.
  653. '*
  654. '* Input:    [in]  strComputer      the name of the computer
  655. '*             [in]  root             The root of the registry entry to update.
  656. '*             [in]  strKeyPath       path to registry entry to update.
  657. '*             [in]  strValueName     value name of registry entry to update.
  658. '* Output:   
  659. '*
  660. ' ****************************************************************************************
  661. Function ViewStringValue(strComputer, root, strKeyPath, strValueName)
  662.     
  663.     dim strValue
  664.     
  665.     Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
  666.         strComputer & "\root\default:StdRegProv")
  667.  
  668.     oReg.GetStringValue root,strKeyPath,strValueName,strValue
  669.  
  670.     ViewStringValue = strValue
  671.     
  672. End Function
  673. ' ****************************************************************************************
  674. '* Function : SetDWORDValue()
  675. '*
  676. '* Purpose  : This sub is the generic function to set a dword registry key.
  677. '*
  678. '* Input:    [in]  strComputer      the name of the computer
  679. '*             [in]  root             The root of the registry entry to update.
  680. '*             [in]  strKeyPath       path to registry entry to update.
  681. '*             [in]  strValueName     value name of registry entry to update.
  682. '*             [in]  dwValue          value to update.
  683. '* Output:   
  684. '*
  685. ' ****************************************************************************************
  686. Sub SetDWORDValue(strComputer, root, strKeyPath, strValueName, dwValue)
  687.     
  688.     dim NewKeyValue, resource, resource2, service, obj, objset
  689.     
  690.     Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
  691.         strComputer & "\root\default:StdRegProv")
  692.  
  693.     oReg.CheckAccess root, strKeyPath, KEY_SET_VALUE, bHasAccessRight
  694.  
  695.     resource2 = GetLocalizedResource("L10780")
  696.  
  697.  
  698.     If bHasAccessRight = True Then
  699.         If resource2 = strValueName then
  700. '            oReg.SetDWORDValue root ,strKeyPath, strValueName, CLng(dwValue)
  701.             Set Service = GetObject("winmgmts:{authenticationLevel=PktPrivacy}!root\cimv2\TerminalServices")
  702.             set objSet=Service.ExecQuery("select * from  Win32_TerminalServiceSetting")
  703.             for each obj in objSet
  704.                 If dwValue = 1 then
  705.                     If obj.AllowTSConnections = 0 Then
  706.                         'already disabled
  707.                     else
  708.                         obj.SetAllowTSConnections 0,0
  709.                     end if
  710.                 else
  711.                     If obj.AllowTSConnections = 1 Then
  712.                         'already enabled
  713.                     else
  714.                         obj.SetAllowTSConnections 1,1
  715.                     end if
  716.                 end if
  717.                     obj.refresh_
  718.             next
  719.             resource = GetLocalizedResource("L10440")
  720.             Wscript.Echo(resource)
  721.         else
  722.             oReg.SetDWORDValue root ,strKeyPath, strValueName, CLng(dwValue)
  723.             resource = GetLocalizedResource("L10440")
  724.             Wscript.Echo(resource)
  725.         end if
  726.     Else
  727.         resource = GetLocalizedResource("L10610")
  728.         Wscript.Echo(resource)
  729.         Wscript.Echo()
  730.     End If
  731.  
  732.     
  733. End Sub
  734. ' ****************************************************************************************
  735. '* Function : ViewDWORDValue()
  736. '*
  737. '* Purpose  : This sub is the generic function to view a dword registry key.
  738. '*
  739. '* Input:    [in]  strComputer      the name of the computer
  740. '*             [in]  root             The root of the registry entry to update.
  741. '*             [in]  strKeyPath       path to registry entry to update.
  742. '*             [in]  strValueName     value name of registry entry to update.
  743. '* Output:   
  744. '*
  745. ' ****************************************************************************************
  746. Function ViewDWordValue(strComputer, root, strKeyPath, strValueName)
  747.  
  748.     dim dwValue
  749.     
  750.     Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
  751.         strComputer & "\root\default:StdRegProv")
  752.  
  753.     oReg.GetDWORDValue root,strKeyPath,strValueName,dwValue
  754.     
  755.     ViewDWordValue = dwValue
  756.     
  757. End Function
  758. ' ****************************************************************************************
  759. '* Function : ConfigureAU()
  760. '*
  761. '* Purpose  : This sub is the function to set AutoUpdate.
  762. '*
  763. '* Input:    [in]  strComputer      the name of the computer
  764. '*             [in]  root             The root of the registry entry to update.
  765. '*             [in]  strKeyPath       path to registry entry to update.
  766. '*             [in]  strValueName     value name of registry entry to update.
  767. '* Output:   
  768. '*
  769. ' ****************************************************************************************
  770. Function ConfigureAU(strValueName)
  771.  
  772.     dim settingChanged, AU, AUSettings
  773.  
  774.     set AU = CreateObject("Microsoft.Update.AutoUpdate")
  775.     set AUSettings = AU.Settings
  776.  
  777.     AUSettings.NotificationLevel=strValueName
  778.     settingChanged = TRUE
  779.     AUSettings.Save
  780.     resource = GetLocalizedResource("L10440")
  781.     Wscript.Echo(resource)
  782.  
  783. End Function
  784. ' ****************************************************************************************
  785. '* Function : CheckArgs()
  786. '*
  787. '* Purpose  : This function checks validity of command line parameters.
  788. '*
  789. '* Input:    [in]  key      passed in quick key
  790. '* Output:   
  791. '*
  792. ' ****************************************************************************************
  793. Function CheckArgs(key)
  794.     Dim p,v, status
  795.     status = true
  796.     For p = 0 to Ubound(arrKeyList)
  797.         If arrKeyList(p)(0) = key Then
  798.             If arrKeyList(p)(3) = "REG_MULTI_SZ" Then
  799.                 If(Ubound(arrKeyList(p)) - 3) = (objArgs.Count - 1) Then
  800.                     For v = 4 To Ubound(arrKeyList(p))
  801.                         If arrKeyList(p)(v) = "REG_SZ" Then
  802.                             If TypeName(objArgs(v - 3)) = "String" Then
  803.                                 'do nothing
  804.                             Else
  805.                                 resource = GetLocalizedResource("L10500")
  806.                                 resource2 = GetLocalizedResource("L10540")
  807.                                 Wscript.Echo(resource & v-3 & ": " & resource2)
  808.                                 status = false
  809.                                 CheckArgs = false
  810.                             End If
  811.                         ElseIf arrKeyList(p)(v) = "REG_DWORD" Then
  812.                             If IsNumeric(objArgs(v - 3)) = True Then
  813.                                 'do nothing
  814.                             Else
  815.                                 resource = GetLocalizedResource("L10500")
  816.                                 resource2 = GetLocalizedResource("L10530")
  817.                                 Wscript.Echo(resource & v-3 & ": " & resource2)
  818.                                 status = false
  819.                                 CheckArgs = false
  820.                             End If
  821.                         End If
  822.                     Next
  823.                 Else
  824.                     resource = GetLocalizedResource("L10510")
  825.                     Wscript.Echo(resource)
  826.                     status = false
  827.                     CheckArgs = false
  828.                 End If
  829.             ElseIf arrKeyList(p)(3) = "REG_SZ" Then
  830.                 If TypeName(objArgs(1)) = "String" Then
  831.                     'do nothing
  832.                 Else
  833.                     resource = GetLocalizedResource("L10500")
  834.                     resource2 = GetLocalizedResource("L10540")
  835.                     Wscript.Echo(resource & " 1 : " & resource2)
  836.                     status = false
  837.                     CheckArgs = false
  838.                 End If
  839.             ElseIf arrKeyList(p)(3) = "REG_DWORD" Then
  840.                 If IsNumeric(objArgs(1)) = True Then
  841.                     'do nothing
  842.                 Else
  843.                     resource = GetLocalizedResource("L10500")
  844.                     resource2 = GetLocalizedResource("L10530")
  845.                     Wscript.Echo(resource & " 1 : " & resource2)
  846.                     status = false
  847.                     CheckArgs = false
  848.                 End If
  849.             End If
  850.         End If
  851.     Next
  852.     
  853.     If status = false Then
  854.         CheckArgs = false
  855.     Else
  856.         CheckArgs = True
  857.     End If
  858. End Function
  859. ' ****************************************************************************************
  860. '* Function : ExpandEnvironmentString()
  861. '*
  862. '* Purpose:This function Expands the Environment Variables
  863. '*
  864. '* Input:    [in]  strOriginalString      the string need to expand for EnvironmentsettingValue
  865. '* Output:   Returns ExpandedEnvironmentString
  866. '*
  867. ' ****************************************************************************************
  868. Private Function ExpandEnvironmentString( ByVal strOriginalString)
  869.  
  870.  ON ERROR RESUME NEXT
  871.  Err.Clear
  872.  
  873. Dim ObjWshShell  ' Object to hold Shell
  874.  
  875. Set ObjWshShell = CreateObject("WScript.Shell")
  876. ExpandEnvironmentString= ObjWshShell.ExpandEnvironmentStrings(strOriginalString)
  877.  
  878. End Function
  879.  
  880.  
  881.  
  882. ' ****************************************************************************************
  883. '* Function : 
  884. '*
  885. '* Purpose: The following functions find the language appropriate strings
  886. '*
  887. '* Input: 
  888. '* Output: 
  889. '*
  890. ' ****************************************************************************************
  891. ' Get a localized resources for 'resourceID' if available; otherwise, get the neutral resource.
  892. Function GetLocalizedResource(resourceID)
  893.     Const ForReading = 1, TristateUseDefault = -2
  894.  
  895.     Dim lang, value, ini
  896.  
  897.     
  898.     lang = GetUILanguage()
  899.  
  900.     ini = langFSO.GetParentFolderName(WScript.ScriptFullName) & "\" _
  901.         & ToHex(lang) & "\" & langFSO.GetBaseName(WScript.ScriptName) &  ".ini"
  902.  
  903.     If langFSO.FileExists(ini) Then
  904.         Dim stream, file
  905.  
  906.         Debug.WriteLine "Using resource file " & ini
  907.  
  908.         Set file = langFSO.GetFile(ini)
  909.         Set stream = file.OpenAsTextStream(ForReading, TristateUseDefault)
  910.         value = ReadResource(stream, resourceID)
  911.     End If
  912.  
  913.     If Not IsEmpty(value) Then
  914.         GetLocalizedResource = value
  915.     Else
  916.         Debug.WriteLine "Falling back to neutral resource in script file"
  917.         GetLocalizedResource = getResource(resourceID)
  918.     End If
  919. End Function
  920.  
  921. ' Read a resource ID from the TextStream
  922. Function ReadResource(stream, resourceID)
  923.     Const ERROR_FILE_NOT_FOUND = 2
  924.     Dim ln, arr, key, value
  925.  
  926.     If Not IsObject(stream) Then Err.Raise ERROR_FILE_NOT_FOUND
  927.  
  928.     Do Until stream.AtEndOfStream
  929.         ln = stream.ReadLine
  930.  
  931.         arr = Split(ln, "=", 2, 0)
  932.         If UBound(arr, 1) = 1 Then
  933.             ' Trim the key and the value first before trimming quotes
  934.             key = Trim(arr(0))
  935.  
  936.             If resourceID = key Then
  937.                 Debug.WriteLine "Found key " & key
  938.                 value = TrimChar(Trim(arr(1)), """")
  939.                 ReadResource = value
  940.                 Exit Do
  941.             End If
  942.         End If
  943.     Loop
  944.  
  945.     stream.Close
  946. End Function
  947.  
  948. ' Trim a character from the text string
  949. Function TrimChar(s, c)
  950.     Const vbTextCompare = 1
  951.  
  952.     ' Trim character from the start
  953.     If Left( s, 1 ) = c Then
  954.         s = Mid(s, 2)
  955.     End If
  956.     
  957.     ' Trim character from the end
  958.     If Right(s, 1) = c Then
  959.         s = Mid(s, 1, Len(s) - 1)
  960.     End If
  961.  
  962.     TrimChar = s
  963. End Function
  964.  
  965. ' Get a 4-digit hexadecimal number
  966. Function ToHex(n)
  967.     Dim s : s = Hex(n)
  968.     ToHex = String(4 - Len(s), "0") & s
  969. End Function
  970.  
  971.  
  972. ' If the localized ini file isn't found, read the resources from the script.
  973. Function getResource(resourceID)
  974.     Const ForReading = 1, TristateUseDefault = -2
  975.  
  976.     Dim lang, value, script
  977.     
  978.     script = langFSO.GetParentFolderName(WScript.ScriptFullName) & "\" & langFSO.GetBaseName(WScript.ScriptName) &  ".wsf"
  979.  
  980.     If langFSO.FileExists(script) Then
  981.         Dim stream, file
  982.  
  983.         Debug.WriteLine "Using resource file " & script
  984.  
  985.         Set file = langFSO.GetFile(script)
  986.         Set stream = file.OpenAsTextStream(ForReading, TristateUseDefault)
  987.         value = ReadResource(stream, resourceID)
  988.     End If
  989.  
  990.     getResource = value
  991. End Function
  992.  
  993.  
  994. </script>
  995.  
  996. <!-- Neutral language resources -->
  997.  
  998. L_UseCscript1_ErrorMessage="This script should be executed from the command prompt using CSCRIPT.EXE. For example:"
  999. L_UseCscript2E_ErrorMessage="        CSCRIPT %systemroot%\system32\SCREGEDIT.WSF "
  1000. L_UseCscript3_ErrorMessage="arguments"
  1001.  
  1002. L10400="View registry setting."
  1003. L10440="Registry has been updated."
  1004. L10450="You must restart the "IPSec Policy Agent" before the change will take effect."
  1005. L10500="Parameter"
  1006. L10510="Expected 3 parameters."
  1007. L10520="Parameter type mismatch"
  1008. L10530="Parameter type mismatch expected DWord."
  1009. L10540="Parameter type mismatch expected string."
  1010. L10565="Value not set."
  1011. L10570="Value should be either 1 or 4"
  1012. L10575="Value should be either 1, 2, or 3"
  1013. L10580="Value should be either 0 or 1"
  1014. L10590="Value should be from 0 through 65535"
  1015. L10600="Invalid switch - run scregedit.wsf /? For the list of supported switches."
  1016. L10610="You do not have permission to modify the registry."
  1017. L10780="fDenyTSConnections"
  1018. L10800="To activate:"
  1019. L10801="     Cscript slmgr.vbs -ato"
  1020. L10802=" "
  1021. L10803="To use KMS volume licensing for activation:"
  1022. L10804="     Configure KMS volume licensing:"
  1023. L10805="          cscript slmgr.vbs -ipk [volume license key]"
  1024. L10806="     Activate KMS licensing"
  1025. L10807="          cscript slmgr.vbs -ato"
  1026. L10808="     Set KMS DNS SRV record"
  1027. L10809="          cscript slmgr.vbs -skma [KMS FQDN]"
  1028. L10810=" "
  1029. L10811="Determine the computer name, any of the following:"
  1030. L10812="     Set c"
  1031. L10813="     Ipconfig /all"
  1032. L10814="     Systeminfo.exe or Hostname.exe"
  1033. L10815=" "
  1034. L10816="Rename the Server Core computer:"
  1035. L10817="     Domain joined:"
  1036. L10818="          Netdom renamecomputer %computername% /NewName:new-name /UserD:domain-username /PasswordD:*"
  1037. L10819="     Not domain joined:"
  1038. L10820="          Netdom renamecomputer %computername% /NewName:new-name"
  1039. L10821=" "
  1040. L10822="Changing workgroups:"
  1041. L10823="     Wmic computersystem where name="%computername%" call  joindomainorworkgroup name="[new workgroup name]" "
  1042. L10824=" "
  1043. L10825="Install a role or optional feature:"
  1044. L10826="     Start /w Ocsetup [packagename]"
  1045. L10827="     Note: For Active Directory, run Dcpromo with an answer file."
  1046. L10828=" "
  1047. L10829="View role and optional feature package names and current installation state:"
  1048. L10830="     oclist"
  1049. L10831=" "
  1050. L10832="Start task manager hot-key: "
  1051. L10833="     ctrl-shift-esc"
  1052. L10834=" "
  1053. L10835="Logoff of a Terminal Services session:"
  1054. L10836="     Logoff"
  1055. L10837=" "
  1056. L10838="To set the pagefile size:"
  1057. L10839="     Disable system pagefile management: "
  1058. L10840="          wmic computersystem where name="%computername%" set AutomaticManagedPagefile=False"
  1059. L10841="     Configure the pagefile:"
  1060. L10842="          wmic pagefileset where name="C:\\pagefile.sys" set InitialSize=500,MaximumSize=1000"
  1061. L10843=" "
  1062. L10844="Configure the timezone, date, or time:"
  1063. L10845="     control timedate.cpl"
  1064. L10846=" "
  1065. L10847="Configure regional and language options:"
  1066. L10848="     control intl.cpl"
  1067. L10849=" "
  1068. L10850="Manually install a management tool or agent:"
  1069. L10851="     Msiexec.exe /i [msipackage]"
  1070. L10852=" "
  1071. L10853="List installed msi applications:"
  1072. L10854="     Wmic product"
  1073. L10855=" "
  1074. L10856="Uninstall msi applications:"
  1075. L10857="     Wmic product get name /value "
  1076. L10858="     Wmic product where name="[name]" call uninstall"
  1077. L10859=" "
  1078. L10860="To list installed drivers:"
  1079. L10861="     Sc query type= driver"
  1080. L10862=" "
  1081. L10863="Install a driver that is not included:"
  1082. L10864="     Copy the driver files to Server Core"
  1083. L10865="     Pnputil ûi ûa [path]\[driver].inf"
  1084. L10866=" "
  1085. L10867="Rename a Network Adapter:"
  1086. L10868="     netsh interface set interface name="Local Area Connection" newname="PrivateNetwork""
  1087. L10869=" "
  1088. L10870="Disable a Network Adapter:"
  1089. L10871="     netsh interface set interface name="Local Area Connection 2" admin=DISABLED"
  1090. L10872=" "
  1091. L10873="Determine a fileÆs version:"
  1092. L10874="     wmic datafile where name="c:\\windows\\system32\\ntdll.dll" get version"
  1093. L10875=" "
  1094. L10876="List of installed patches:"
  1095. L10877="     wmic qfe list"
  1096. L10878=" "
  1097. L10879="Install a patch:"
  1098. L10880="     Wusa.exe [patchame].msu /quiet"
  1099. L10881=" "
  1100. L10882="Configure a proxy:"
  1101. L10883="     Netsh winhttp set proxy [proxy_name]:[port]"
  1102. L10884=" "
  1103. L10885="Add, delete, query a Registry value:"
  1104. L10886="     reg.exe add /?"
  1105. L10887="     reg.exe delete /?"
  1106. L10888="     reg.exe query /?"
  1107.  
  1108. au1="Automatic Updates - Manage Automatic Windows Updates "
  1109. au2="These settings can be used to configure how Automatic Updates are applied to "
  1110. au3="the Windows system. It includes the ability to disable automatic updates and "
  1111. au4="to set the installation schedule."
  1112. au5="/AU [/v][value]"
  1113. au6="    /v    View the current Automatic Update settings"
  1114. au7="    value    value you want to set to."
  1115. au8="    Options:"
  1116. au9="    4 - Enable Automatic Updates "
  1117. au10="    1 - Disable Automatic Updates "
  1118.  
  1119. ar1="Terminal Service - Allow Remote Administration Connections"
  1120. ar2="This allows administrators to connect remotely for administration purposes."
  1121. ar3="/AR [/v][value]"
  1122. ar4="    /v    View the Remote Terminal Service Connection setting"
  1123. ar5="    value    (0 = enabled, 1 = disabled)"
  1124.  
  1125. cs1="Terminal Service - Allow connections from previous versions of Windows"
  1126. cs2="This setting configures CredSSP based user authentication for"
  1127. cs3="Terminal Service connections"
  1128. cs4="/CS  [/v][value]"
  1129. cs5="    /v    View the Terminal Service CredSSP setting"
  1130. cs6="    value    (0 = allow previous versions, 1 = require CredSSP)"
  1131.  
  1132. im1="IP Security (IPSEC) Monitor - allow remote management"
  1133. im2="This setting configures the server to allow the IP Security (IPSEC) Monitor to "
  1134. im3="be able to remotely manage IPSEC."
  1135. im4="/IM [/v][value]"
  1136. im5="   /v    View the IPSEC Monitor setting"
  1137. im6="    value    (0 = do not allow, 1 = allow remote management)"
  1138.  
  1139. dp1="DNS SRV priority - changes the priority for DNS SRV records"
  1140. dp2="This setting configures the priority for DNS SRV records and is only useful "
  1141. dp3="on Domain Controllers."
  1142. dp4="For more information on this setting, search TechNet for LdapSrvPriority"
  1143. dp5="/DP [/v][value]"
  1144. dp6="   /v    View the DNS SRV priority setting"
  1145. dp7="    value    (value from 0 through 65535. The recommended value is 200.)"
  1146.  
  1147. dw1="DNS SRV weight - changes the weight for DNS SRV records"
  1148. dw2="This setting configures the weight for DNS SRV records and is only useful "
  1149. dw3="on Domain Controllers."
  1150. dw4="For more information on this setting, search TechNet for LdapSrvWeight"
  1151. dw5="/DW [/v][value]"
  1152. dw6="   /v    View the DNS SRV weight setting"
  1153. dw7="    value    (value from 0 through 65535. The recommended value is 50.)"
  1154.  
  1155. cli1="Command Line Reference"
  1156. cli2="This setting displays a list of common tasks and how to perform them from"
  1157. cli3="the command line."
  1158. cli4="/CLI"
  1159.  
  1160. reg0="/au,AUOptions,SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update,REG_DWORD,REG_DWORD"
  1161. reg1="/ar,fDenyTSConnections,System\CurrentControlSet\Control\Terminal Server,REG_DWORD,REG_DWORD"
  1162. reg2="/cs,UserAuthentication,System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp,REG_DWORD,REG_DWORD"
  1163. reg3="/im,EnableRemoteMgmt,SYSTEM\CurrentControlSet\Services\PolicyAgent,REG_DWORD,REG_DWORD"
  1164. reg4="/dp,LdapSrvPriority,SYSTEM\CurrentControlSet\Services\Netlogon\Parameters,REG_DWORD,REG_DWORD"
  1165. reg5="/dw,LdapSrvWeight,SYSTEM\CurrentControlSet\Services\Netlogon\Parameters,REG_DWORD,REG_DWORD"
  1166. reg6="/cli,none,none,none,none"
  1167.  
  1168. switch0="/au"
  1169. switch1="/ar"
  1170. switch2="/cs"
  1171. switch3="/im"
  1172. switch4="/dp"
  1173. switch5="/dw"
  1174. switch6="/cli"
  1175.  
  1176. </job>