home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 May / PCpro_2006_05.ISO / files / free_security / msshared / Shared_Computer_Toolkit_ENU.msi / FileInclude010 < prev    next >
Encoding:
Text (UTF-16)  |  2005-09-02  |  44.3 KB  |  568 lines

  1. ' ***
  2. ' *** ------------------------------------------------------------------------------
  3. ' *** Filename:        Common.vbs
  4. ' *** ------------------------------------------------------------------------------
  5. ' *** Description:    The Shared Computer Toolkit for Windows XP Common file for HTA 
  6. ' ***               and Wsf functions 
  7. ' *** ------------------------------------------------------------------------------
  8. ' *** Version:        1.0
  9. ' *** Notes:        
  10. ' *** ------------------------------------------------------------------------------
  11. ' *** Copyright (C) Microsoft Corporation 2005, All Rights Reserved
  12. ' *** ------------------------------------------------------------------------------
  13. ' *** 
  14.  
  15. ' ~~~ 
  16. ' ~~~ Force variables to be declared 
  17. ' ~~~ 
  18. Option Explicit
  19.  
  20. ' ~~~ ------------------------------------------------------
  21. ' ~~~ Build number
  22. ' ~~~ ------------------------------------------------------
  23. Const BUILDNUMBER = "106"
  24.  
  25. ' ~~~ ------------------------------------------------------
  26. ' ~~~ URL for WGA check
  27. ' ~~~ ------------------------------------------------------
  28. Const WGACHECKURL = "http://go.microsoft.com/fwlink/?LinkId=51033"
  29.  
  30. ' ~~~ ------------------------------------------------------
  31. ' ~~~ Title and Message Box text
  32. ' ~~~ 
  33. ' ~~~ Tagged accordingly for localization
  34. ' ~~~ 
  35. ' ~~~ ------------------------------------------------------
  36.  
  37. ' ~~~ 
  38. ' ~~~ Declare global variables
  39. ' ~~~ 
  40. Dim L_sToolkitTitle_TEXT, L_sAdminErrorMsg_TEXT 
  41. Dim sCommonValidate, L_sCommonValidate1_TEXT, L_sCommonValidate2_TEXT, L_sTitleValidate_TEXT
  42. Dim L_PassTitle_TEXT, L_PassPolicy_TEXT, L_PassNote_TEXT, L_PassWarnTitle_TEXT, L_PassWarn_TEXT, L_DomainTitle_TEXT, L_DomainNote_TEXT
  43. Dim L_WDPblocked_TEXT, L_WDPblockedTitle_TEXT
  44. Dim L_sManageTitle_TEXT, L_sRestrictTitle_TEXT, L_sProtectDrives_TEXT
  45. Dim L_sLogOffLink_TEXT, L_sBeforeUnloadWarning_TEXT, L_sSafeModeErrorMsg_TEXT
  46. Dim L_sScriptingEngineFailure_TEXT, L_sWINNTFailure_TEXT, L_sWMIFailure_TEXT
  47.  
  48. Const LANGCODE   = "ENU"
  49.  
  50. L_sToolkitTitle_TEXT        = "Shared Computer Toolkit Version 1.0"
  51. L_sAdminErrorMsg_TEXT        = "You have to be an administrator to use this tool."
  52. L_sSafeModeErrorMsg_TEXT    = "This tool does not run while running in Safe Mode."
  53.  
  54. ' ~~~ Used in Common.vbs
  55. L_sCommonValidate1_TEXT        = "To use this tool, please take a moment to validate your genuine Microsoft Windows installation."
  56. L_sCommonValidate2_TEXT        = "Validation assures that you are running an authentic and fully-licensed copy of Windows."
  57. sCommonValidate                = L_sCommonValidate1_TEXT & Chr(13) & Chr(10) & Chr(10) & L_sCommonValidate2_TEXT
  58. L_sTitleValidate_TEXT        = "Validation Required"
  59.  
  60. ' ~~~ Used in Getting Started for the password test.
  61. L_PassTitle_TEXT     = "Password Test Passed"
  62. L_PassPolicy_TEXT    = "This computer has a password policy in place to help ensure strong passwords. Password test passed."
  63. L_PassNote_TEXT      = "Could not guess the password on this account. Password test passed."
  64. L_PassWarnTitle_TEXT = "Password Test Failed - Security Warning"
  65. L_PassWarn_TEXT      = "This account has an easily guessable password. The Toolkit administrator account should have a strong password. Change the password of this account before the computer is made available to others."
  66. L_DomainTitle_TEXT   = "No Password Test for Domain Accounts"
  67. L_DomainNote_TEXT    = "Password test is not performed on domain accounts."
  68.  
  69. ' ~~~ Used by clsDiskProtect.vbs for script blocking error conditions
  70. L_WDPblockedTitle_TEXT        = "Windows Disk Protection Script Blocked"
  71. L_WDPblocked_TEXT        = "Allow WDP.CMD to execute through the script blocking tool and then click OK."
  72.  
  73. ' ~~~ Used in UserAccounts.vbs for title.
  74. L_sManageTitle_TEXT        = "Select an Account to Manage"
  75. L_sRestrictTitle_TEXT        = "Select a Profile to Restrict"
  76.  
  77. ' ~~~ Used in SelectDrives.hta for title
  78. L_sProtectDrives_TEXT        = "Select Drives to Restrict"
  79.  
  80. ' ~~~ Used in clsRestrictions.vbs
  81. L_sLogOffLink_TEXT = "- Log Off -"
  82.  
  83. ' ~~~ Used in libHTA.vbs
  84. L_sBeforeUnloadWarning_TEXT    = "Processing is underway - closing the tool now is not recommended. Click Ok to close the tool, or Cancel to continue processing."
  85.  
  86. ' ~~~ Used in Common.vbs
  87. L_sScriptingEngineFailure_TEXT  = "Windows Scripting might be missing or damaged... the Toolkit will not function properly. The following web page will help you fix this error: http://support.microsoft.com/kb/905288"
  88. L_sWINNTFailure_TEXT        = "Unable to create the WinNT object... the Toolkit will not function properly."
  89. L_sWMIFailure_TEXT        = "WMI might be missing or damaged... the Toolkit will not function properly. The following web page will help you fix this error: http://support.microsoft.com/kb/905287"
  90.  
  91. ' ~~~ Declare common variables and constants
  92. Dim oShell, oNetwork, oWMIService, oFso, oWmiReg, oAccounts, sComputer
  93.  
  94. Const TOOLKITKEY = "HKLM\Software\Microsoft\Shared Computer Toolkit\"
  95. Const HKEY_CURRENT_USER = &H80000001
  96. Const HKEY_LOCAL_MACHINE = &H80000002
  97. Const HKEY_USERS = &H80000003
  98.  
  99.  
  100. ' ~~~ ------------------------------------------------------------------------------
  101. ' ~~~ Description:    DEBUG = True turns VBScript error messages on
  102. ' ~~~                 DEBUG = False turns VBScript error messages off
  103. ' ~~~ ------------------------------------------------------------------------------
  104. Dim DEBUG
  105.  
  106. ' ~~~ DEBUG is set using registry value in Main() of libHTA.vbs
  107. DEBUG = False
  108.  
  109. ' *** 
  110. ' *** ------------------------------------------------------------------------------
  111. ' *** Name:            CheckWGA()
  112. ' *** ------------------------------------------------------------------------------
  113. ' *** Purpose:        Runtime check for previously validated Windows
  114. ' ***                 messagebox:True Windows pop up message for hta 
  115. ' ***                 messagebox:False script commandline message
  116. ' *** ------------------------------------------------------------------------------
  117. ' *** 
  118.  
  119. Function CheckWGA(messagebox)
  120.     Dim oLegit, strMsg, iResult 
  121.  
  122.     ' ~~~ Turn on error checking to see if we can open LegitCheckControl.LegitCheck
  123.     On Error Resume Next
  124.  
  125.     iResult = 2
  126.     Err.Clear
  127.  
  128.     Set oLegit = CreateObject("LegitCheckControl.LegitCheck")
  129.     If Err.Number = 0 Then        
  130.         iResult = oLegit.LegitCheck
  131.     Else
  132.         Err.Clear
  133.     End If
  134.  
  135.     ' ~~~ Turn off error handling - so we see any errors in the remainder of the script
  136.     On Error Goto 0
  137.  
  138.     If iResult <> 0 Then
  139.         if messagebox = True Then
  140.             MsgBox sCommonValidate, vbCritical, L_sTitleValidate_TEXT
  141.         Else
  142.             strMsg = sCommonValidate
  143.             wscript.echo strMsg
  144.         End If
  145.         Call oShell.Run (WGACHECKURL)
  146.         CheckWGA = False
  147.     Else
  148.         ' ~~~ Passed WGA check
  149.         CheckWGA = True
  150.     End If
  151.  
  152.     Set oLegit = Nothing
  153. End Function
  154.  
  155. ' *** 
  156. ' *** ------------------------------------------------------------------------------
  157. ' *** Name:            IsAppRunning(AppName)
  158. ' *** ------------------------------------------------------------------------------
  159. ' *** Purpose:        This function checks the application status
  160. ' ***                If the application is opened returns true else false
  161. ' *** ------------------------------------------------------------------------------
  162. ' *** 
  163. Function IsAppRunning(AppName)
  164.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  165.     Dim applen,strComputer,colProcesses,oProcess
  166.     applen = len(AppName)
  167.     strComputer = "."
  168.     IsAppRunning = False
  169.     
  170.     Set colProcesses = oWMIService.ExecQuery _
  171.         ("SELECT * FROM Win32_Process WHERE Name='MSHTA.EXE'")
  172.  
  173.     For Each oProcess in colProcesses
  174.         ' ~~~ Get the application name
  175.         If AppName = left(Right(oProcess.CommandLine,applen+2),applen) Then
  176.         IsAppRunning = True
  177.         Exit Function
  178.         End If
  179.     Next
  180. End Function
  181.  
  182. ' *** 
  183. ' *** ------------------------------------------------------------------------------
  184. ' *** Name:            InitialiseAllObjects()
  185. ' *** ------------------------------------------------------------------------------
  186. ' *** Purpose:        This function Initialises all the objects required
  187. ' *** ------------------------------------------------------------------------------
  188. ' *** 
  189. Sub InitialiseAllObjects()
  190.     Dim bScriptEngineFailure, bWMIFailure, bWINNTFailure
  191.  
  192.     ' ~~~ Turn on error handling
  193.     On Error Resume Next
  194.  
  195.     bScriptEngineFailure = False
  196.     bWMIFailure = False
  197.     bWINNTFailure = False
  198.  
  199.     ' ~~~ Create objects
  200.     Set oShell = createobject("wscript.shell")
  201.     If TypeName(oShell) <> "IWshShell3" Then bScriptEngineFailure = True
  202.  
  203.     Set oNetwork = CreateObject("Wscript.Network")
  204.     If TypeName(oNetwork) <> "IWshNetwork2" Then bScriptEngineFailure = True
  205.  
  206.     Set oFso = CreateObject("Scripting.FileSystemObject")
  207.     If TypeName(oFso) <> "FileSystemObject" Then bScriptEngineFailure = True
  208.  
  209.     sComputer  = oNetwork.ComputerName
  210.     Set oAccounts = GetObject("WinNT://" & sComputer & "")    
  211.     If TypeName(oAccounts) <> "Object" Then bWINNTFailure = True
  212.  
  213.     Set oWmiReg = GetObject("winmgmts:" _
  214.     & "{impersonationLevel=impersonate}!\\" & "." & "\root\default:StdRegProv")
  215.     If TypeName(oWmiReg) <> "SWbemObjectEx" Then bWMIFailure = True
  216.  
  217.     Set oWMIService = GetObject("winmgmts:" _
  218.     & "{impersonationLevel=impersonate}!\\" & "." & "\root\cimv2")
  219.     If TypeName(oWMIService) <> "SWbemServicesEx" Then bWMIFailure = True
  220.  
  221.     If bScriptEngineFailure Then 
  222.         MsgBox L_sScriptingEngineFailure_TEXT, vbOKOnly + vbCritical, L_sToolkitTitle_TEXT
  223.         call Self.Close
  224.         Exit Sub
  225.     End If    
  226.  
  227.     If bWINNTFailure Then 
  228.         MsgBox L_sWINNTFailure_TEXT, vbOKOnly + vbCritical, L_sToolkitTitle_TEXT
  229.         call Self.Close
  230.         Exit Sub
  231.     End If    
  232.  
  233.     If bWMIFailure Then 
  234.         MsgBox L_sWMIFailure_TEXT, vbOKOnly + vbCritical, L_sToolkitTitle_TEXT
  235.         call Self.Close
  236.         Exit Sub
  237.     End If    
  238.  
  239.  
  240.  
  241.     On Error Goto 0
  242. End Sub
  243.  
  244. ' *** 
  245. ' *** ------------------------------------------------------------------------------
  246. ' *** Name:            UnLoadObjects()
  247. ' *** ------------------------------------------------------------------------------
  248. ' *** Purpose:        This function Uninitialises all the objects
  249. ' *** ------------------------------------------------------------------------------
  250. ' *** 
  251. Function UnLoadObjects()
  252.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  253.     Set oShell = Nothing
  254.     Set oNetwork = Nothing    
  255.     Set oWMIService = Nothing
  256.     Set oFso = Nothing
  257.     Set oWmiReg = Nothing
  258. End Function
  259.  
  260. ' *** 
  261. ' *** ------------------------------------------------------------------------------
  262. ' *** Name:            DomainMember()
  263. ' *** ------------------------------------------------------------------------------
  264. ' *** Purpose:        Determines if machine is a member of a Windows Domain
  265. ' *** ------------------------------------------------------------------------------
  266. ' *** 
  267. Function DomainMember()
  268.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  269.     Dim oComputer, oComputers
  270.  
  271.     Set oComputers  = oWMIService.ExecQuery("Select DomainRole from Win32_ComputerSystem")
  272.     For Each oComputer in oComputers
  273.         If oComputer.DomainRole=1 Then
  274.             DomainMember = True
  275.         Else
  276.             DomainMember = False
  277.         End If
  278.     Next
  279. End Function
  280.  
  281. ' *** 
  282. ' *** ------------------------------------------------------------------------------
  283. ' *** Name:            IsAdministrator()
  284. ' *** ------------------------------------------------------------------------------
  285. ' *** Purpose:        Determines if the user is an administrator
  286. ' *** ------------------------------------------------------------------------------
  287. ' *** 
  288. Function IsAdministrator(bMessagebox)
  289.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  290.     Dim strKeyPath, bIsAdmin
  291.     CONST KEY_SET_VALUE = &H0002
  292.  
  293.  
  294.     ' ~~~ Now check for error
  295.     strKeyPath = Right((TOOLKITKEY),(Len(TOOLKITKEY) - 5))
  296.  
  297.     oWmiReg.CheckAccess HKEY_LOCAL_MACHINE, strKeyPath, KEY_SET_VALUE, bIsAdmin
  298.  
  299.     ' ~~~ Display message
  300.     If Not(bIsAdmin) Then
  301.         If bMessagebox Then
  302.             Call MsgBox(L_sAdminErrorMsg_TEXT, vbOKOnly + vbCritical, L_sToolkitTitle_TEXT)
  303.         Else 
  304.             Wscript.echo L_sAdminErrorMsg_TEXT
  305.         End If
  306.     End If
  307.  
  308.     ' ~~~ Return setting
  309.     IsAdministrator = bIsAdmin
  310.  
  311.     ' ~~~ Turn off error handling
  312.     On Error Goto 0
  313.  
  314. End Function
  315.  
  316. ' *** 
  317. ' *** ------------------------------------------------------------------------------
  318. ' *** Name:            InSafeMode()
  319. ' *** ------------------------------------------------------------------------------
  320. ' *** Purpose:        Determines if XP is in Safe Mode
  321. ' *** ------------------------------------------------------------------------------
  322. ' *** 
  323. Function InSafeMode(bMessagebox)
  324.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  325.     Dim bInSafeMode
  326.  
  327.     bInSafeMode = False
  328.  
  329.     ' ~~~ Create shell, attempt registry write, destroy shell
  330.     If RegRead("HKLM\SYSTEM\CurrentControlSet\Control\SafeBoot\Option\OptionValue") <> "" then bInSafeMode = True
  331.  
  332.     ' ~~~ Display message
  333.     If bInSafeMode Then
  334.         If bMessagebox Then
  335.             Call MsgBox(L_sSafeModeErrorMsg_TEXT, vbOKOnly + vbCritical, L_sToolkitTitle_TEXT)
  336.         Else 
  337.             Wscript.echo L_sSafeModeErrorMsg_TEXT
  338.         End If
  339.     End If
  340.  
  341.     ' ~~~ Return setting
  342.     InSafeMode = bInSafeMode
  343.  
  344.     ' ~~~ Turn off error handling
  345.     On Error Goto 0
  346. End Function
  347.  
  348. ' *** 
  349. ' *** ------------------------------------------------------------------------------
  350. ' *** Name:            RegDelete(sRegKey)
  351. ' *** ------------------------------------------------------------------------------
  352. ' *** Purpose:        Deletes a registry key. Deals with non-existent keys.
  353. ' *** ------------------------------------------------------------------------------
  354. ' *** 
  355. Function RegDelete(sRegKey)
  356.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  357.  
  358.     ' ~~~ Turn on error 'handling'
  359.     On Error Resume Next
  360.  
  361.     ' ~~~ Attempt to delete key    
  362.     Call oShell.RegDelete(sRegKey)
  363.  
  364.     ' ~~~ If error, key does not exist, clear error
  365.     If err.number <> 0 Then err.Clear
  366.  
  367.     ' ~~~ Turn off error handling
  368.     On Error Goto 0
  369. End Function
  370.  
  371. ' *** 
  372. ' *** ------------------------------------------------------------------------------
  373. ' *** Name:            RegRead(strRegKeypath )
  374. ' *** ------------------------------------------------------------------------------
  375. ' *** Purpose:        Reads a registry key using WMI. Deals with non-existent keys.
  376. ' *** -----------------------------------------------------------------------------
  377. ' *** 
  378. Function RegRead(strRegKeypath)
  379.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  380.     
  381.     Dim sRegHive, sRegPath, sRegKey, iReturn
  382.     Dim strValue, strNoValue, iCharStart, iCharEnd, arrValues, strTempValue
  383.     
  384.     iCharStart = InStr(strRegKeypath,"\")
  385.     ' ~~~ Get HKLM\HKCU\HKU
  386.     sRegHive = Left( strRegKeypath , iCharStart-1)
  387.         
  388.     iCharEnd = InStrRev(strRegKeypath,"\")
  389.     ' ~~~ Store the registry key for which the value has to be read
  390.     sRegKey = Right( strRegKeypath , Len(strRegKeypath) - iCharEnd)
  391.     
  392.     ' ~~~ Store the registry path
  393.     sRegPath = Mid( strRegKeypath, iCharStart+1 , iCharEnd - iCharStart-1 )  
  394.     
  395.     Select Case sRegHive
  396.         Case "HKLM", "HKEY_LOCAL_MACHINE"
  397.             ' ~~~ Read from registry
  398.             oWmiReg.GetDWORDValue HKEY_LOCAL_MACHINE,sRegPath,sRegKey,strValue
  399.             If IsNull(strValue) then oWmiReg.GetStringValue HKEY_LOCAL_MACHINE,sRegPath,sRegKey,strValue
  400.             If IsNull(strValue) then oWmiReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,sRegPath,sRegKey,strValue
  401.             If IsNull(strValue) then 
  402.                 iReturn = oWmiReg.GetMultiStringValue(HKEY_LOCAL_MACHINE,sRegPath,sRegKey,arrValues)
  403.                 If (iReturn = 0) And (Err.Number = 0) Then 
  404.                     For Each strTempValue In arrValues
  405.                         strValue = strValue & "," & strTempValue
  406.                     Next
  407.                     strValue = strValue & ","
  408.                     If strValue = "," then strValue = NULL
  409.                 Else
  410.                     strValue = NULL
  411.                 End If
  412.             End If
  413.         Case "HKCU", "HKEY_CURRENT_USER"
  414.             ' ~~~ Read from registry
  415.             oWmiReg.GetDWORDValue HKEY_CURRENT_USER,sRegPath,sRegKey,strValue
  416.             If IsNull(strValue) then oWmiReg.GetStringValue HKEY_CURRENT_USER,sRegPath,sRegKey,strValue
  417.             If IsNull(strValue) then oWmiReg.GetExpandedStringValue HKEY_CURRENT_USER,sRegPath,sRegKey,strValue
  418.         Case "HKU", "HKEY_USERS"
  419.             ' ~~~ Read from registry
  420.             oWmiReg.GetDWORDValue HKEY_USERS,sRegPath,sRegKey,strValue
  421.             If IsNull(strValue) then oWmiReg.GetStringValue HKEY_USERS,sRegPath,sRegKey,strValue
  422.             If IsNull(strValue) then oWmiReg.GetExpandedStringValue HKEY_USERS,sRegPath,sRegKey,strValue
  423.     End Select
  424.  
  425.     ' ~~~ Return Result
  426.     RegRead = strValue
  427.     
  428. End Function
  429.  
  430. ' ***
  431. ' *** ------------------------------------------------------------------------------
  432. ' *** Name:            RegWrite(sRegKey, sValue, sType)
  433. ' *** ------------------------------------------------------------------------------
  434. ' *** Purpose:        Writes a registry key using WMI
  435. ' *** ------------------------------------------------------------------------------
  436. ' ***
  437. Function RegWrite(sRegKey, sValue, sType)
  438.     If NOT DEBUG Then On Error Resume Next Else On Error Goto 0
  439.     
  440.     Dim sRegHive, iCharStart, sRegKeyPath, sRegKeyName, iCharEnd, iReturn 
  441.     
  442.     ' ~~~ Turn on error 'handling'
  443.     On Error Resume Next
  444.     
  445.     iReturn = 0
  446.  
  447.     iCharStart = InStr(sRegKey, "\")
  448.     ' ~~~ Get HKLM\HKCU\HKU
  449.     sRegHive = Left( sRegKey , iCharStart-1 )
  450.     
  451.     iCharEnd = InStrRev( sRegKey, "\")
  452.     ' ~~~ Store the reg key for which the value has to be updated
  453.     sRegKeyName = Right( sRegKey, Len( sRegKey) - iCharEnd )
  454.     
  455.     ' ~~~ Store the registry path of the key 
  456.     sRegKeyPath = Mid( sRegKey , iCharStart+1 , iCharEnd - iCharStart-1  ) 
  457.     
  458.     Select Case sType
  459.         Case "REG_SZ"
  460.             If sRegHive = "HKLM" OR sRegHive = "HKEY_LOCAL_MACHINE" Then
  461.                 iReturn = oWmiReg.SetStringValue( HKEY_LOCAL_MACHINE, sRegKeyPath , sRegKeyName , sValue )
  462.                 If iReturn <> 0 Then 
  463.                     oWmiReg.CreateKey HKEY_LOCAL_MACHINE, sRegKeyPath 
  464.                     oWmiReg.SetStringValue HKEY_LOCAL_MACHINE, sRegKeyPath , sRegKeyName , sValue
  465.                 End If
  466.             ElseIf sRegHive = "HKCU" OR sRegHive = "HKEY_CURRENT_USER" Then
  467.                 iReturn = oWmiReg.SetStringValue( HKEY_CURRENT_USER, sRegKeyPath , sRegKeyName , sValue)
  468.                 If iReturn <> 0 Then
  469.                     oWmiReg.CreateKey HKEY_CURRENT_USER, sRegKeyPath 
  470.                     oWmiReg.SetStringValue HKEY_CURRENT_USER, sRegKeyPath , sRegKeyName , sValue
  471.                 End If
  472.             ElseIf sRegHive = "HKU" OR sRegHive = "HKEY_USERS" Then
  473.                 iReturn = oWmiReg.SetStringValue( HKEY_USERS, sRegKeyPath , sRegKeyName , sValue )
  474.                 If iReturn <> 0 Then
  475.                     oWmiReg.CreateKey HKEY_USERS, sRegKeyPath 
  476.                     oWmiReg.SetStringValue HKEY_USERS, sRegKeyPath , sRegKeyName , sValue
  477.                 End If
  478.             End If
  479.         Case "REG_MULTI_SZ"
  480.             If sRegHive = "HKLM" OR sRegHive = "HKEY_LOCAL_MACHINE" Then
  481.                 iReturn = oWmiReg.SetMultiStringValue( HKEY_LOCAL_MACHINE, sRegKeyPath , sRegKeyName , sValue )
  482.                 If iReturn <> 0 Then 
  483.                     oWmiReg.CreateKey HKEY_LOCAL_MACHINE, sRegKeyPath 
  484.                     oWmiReg.SetMultiStringValue HKEY_LOCAL_MACHINE, sRegKeyPath , sRegKeyName , sValue
  485.                 End If
  486.             ElseIf sRegHive = "HKCU" OR sRegHive = "HKEY_CURRENT_USER" Then
  487.                 iReturn = oWmiReg.SetMultiStringValue( HKEY_CURRENT_USER, sRegKeyPath , sRegKeyName , sValue)
  488.                 If iReturn <> 0 Then
  489.                     oWmiReg.CreateKey HKEY_CURRENT_USER, sRegKeyPath 
  490.                     oWmiReg.SetMultiStringValue HKEY_CURRENT_USER, sRegKeyPath , sRegKeyName , sValue
  491.                 End If
  492.             ElseIf sRegHive = "HKU" OR sRegHive = "HKEY_USERS" Then
  493.                 iReturn = oWmiReg.SetMultiStringValue( HKEY_USERS, sRegKeyPath , sRegKeyName , sValue )
  494.                 If iReturn <> 0 Then
  495.                     oWmiReg.CreateKey HKEY_USERS, sRegKeyPath 
  496.                     oWmiReg.SetMultiStringValue HKEY_USERS, sRegKeyPath , sRegKeyName , sValue
  497.                 End If
  498.             End If
  499.         Case "REG_EXPAND_SZ"
  500.             If sRegHive = "HKLM" OR sRegHive = "HKEY_LOCAL_MACHINE" Then
  501.                 iReturn = oWmiReg.SetExpandedStringValue( HKEY_LOCAL_MACHINE, sRegKeyPath , sRegKeyName , sValue)
  502.                 If iReturn <> 0 Then
  503.                     oWmiReg.CreateKey HKEY_LOCAL_MACHINE, sRegKeyPath 
  504.                     oWmiReg.SetExpandedStringValue HKEY_LOCAL_MACHINE, sRegKeyPath , sRegKeyName , sValue
  505.                 End If
  506.             ElseIf sRegHive = "HKCU" OR sRegHive = "HKEY_CURRENT_USER" Then
  507.                 iReturn =     oWmiReg.SetExpandedStringValue( HKEY_CURRENT_USER, sRegKeyPath , sRegKeyName , sValue )
  508.                 If iReturn <> 0 Then
  509.                     oWmiReg.CreateKey HKEY_CURRENT_USER, sRegKeyPath 
  510.                     oWmiReg.SetExpandedStringValue HKEY_CURRENT_USER, sRegKeyPath , sRegKeyName , sValue
  511.                 End If
  512.             ElseIf sRegHive = "HKU" OR sRegHive = "HKEY_USERS" Then
  513.                 iReturn =     oWmiReg.SetExpandedStringValue( HKEY_USERS, sRegKeyPath , sRegKeyName , sValue )
  514.                 If iReturn <> 0 Then
  515.                     oWmiReg.CreateKey HKEY_USERS, sRegKeyPath 
  516.                     oWmiReg.SetExpandedStringValue HKEY_USERS, sRegKeyPath , sRegKeyName , sValue
  517.                 End If
  518.             End If
  519.         Case "REG_DWORD" 
  520.             If Not(IsNumeric(sValue)) Then sValue="0"
  521.             
  522.             If sRegHive = "HKLM" OR sRegHive = "HKEY_LOCAL_MACHINE" Then
  523.                 iReturn = oWmiReg.SetDWORDValue( HKEY_LOCAL_MACHINE, sRegKeyPath , sRegKeyName , Int(sValue) )
  524.                 If iReturn <> 0 Then
  525.                     oWmiReg.CreateKey HKEY_LOCAL_MACHINE, sRegKeyPath 
  526.                     oWmiReg.SetDWORDValue  HKEY_LOCAL_MACHINE, sRegKeyPath , sRegKeyName , Int(sValue)
  527.                 End If
  528.             ElseIf sRegHive = "HKCU" OR sRegHive = "HKEY_CURRENT_USER" Then
  529.                 iReturn =     oWmiReg.SetDWORDValue( HKEY_CURRENT_USER, sRegKeyPath , sRegKeyName , Int(sValue) )
  530.                 If iReturn <> 0 Then
  531.                     oWmiReg.CreateKey HKEY_CURRENT_USER, sRegKeyPath 
  532.                     oWmiReg.SetDWORDValue  HKEY_CURRENT_USER, sRegKeyPath , sRegKeyName , Int(sValue)
  533.                 End If
  534.             ElseIf sRegHive = "HKU" OR sRegHive = "HKEY_USERS" Then
  535.                 iReturn = oWmiReg.SetDWORDValue( HKEY_USERS, sRegKeyPath , sRegKeyName , Int(sValue))
  536.                 If iReturn <> 0 Then
  537.                     oWmiReg.CreateKey HKEY_USERS, sRegKeyPath 
  538.                     oWmiReg.SetDWORDValue  HKEY_USERS, sRegKeyPath , sRegKeyName , Int(sValue)
  539.                 End If
  540.             End If
  541.         Case "REG_BINARY"
  542.                         
  543.             If sRegHive = "HKLM" OR sRegHive = "HKEY_LOCAL_MACHINE" Then
  544.                 iReturn = oWmiReg.SetBinaryValue( HKEY_LOCAL_MACHINE, sRegKeyPath , sRegKeyName , sValue )
  545.                 If iReturn <> 0 Then
  546.                     oWmiReg.CreateKey HKEY_LOCAL_MACHINE, sRegKeyPath 
  547.                     oWmiReg.SetBinaryValue HKEY_LOCAL_MACHINE, sRegKeyPath , sRegKeyName , sValue
  548.                 End If
  549.             ElseIf sRegHive = "HKCU" OR sRegHive = "HKEY_CURRENT_USER" Then
  550.                 iReturn = oWmiReg.SetBinaryValue( HKEY_CURRENT_USER, sRegKeyPath , sRegKeyName , sValue )
  551.                 If iReturn <> 0 Then
  552.                     oWmiReg.CreateKey HKEY_CURRENT_USER, sRegKeyPath 
  553.                     oWmiReg.SetBinaryValue HKEY_CURRENT_USER, sRegKeyPath , sRegKeyName , sValue
  554.                 End If
  555.             ElseIf sRegHive = "HKU" OR sRegHive = "HKEY_USERS" Then
  556.                 iReturn = oWmiReg.SetBinaryValue( HKEY_USERS, sRegKeyPath , sRegKeyName , sValue)
  557.                 If iReturn <> 0 Then
  558.                     oWmiReg.CreateKey HKEY_USERS, sRegKeyPath 
  559.                     oWmiReg.SetBinaryValue HKEY_USERS, sRegKeyPath , sRegKeyName , sValue
  560.                 End If
  561.             End If
  562.             
  563.             
  564.     End Select    
  565.          
  566. End Function
  567.  
  568.