Windows Script Introduction
Windows scripts can be used to automatically manage computer settings. It is based on explanations and can interact with windows shell resources. The next generation of windows scripts is power shell, which is more powerful and useful.
Problem:
When developing B/s programs, you may encounter security issues that require special settings for IE. The ideal situation is that you are familiar with ie, so you only need to write the instructions in the help and set IE according to the instructions. However, the actual situation is that most users cannot complete the settings even if the IE settings help. So what should we do? Let the customer service staff help set the user, for B/s. This is unrealistic because the customer base is huge. This problem can also be solved if there is a simple way for users to set it. For example, you can download an object and double-click it to execute it. In this case, windows scripts are the best choice.
Solution:
Case:
Set IE attributes on the client:
1. Add a site to a trusted site;
2. initialize the Security activeX Code that is not marked as a trusted site, and disable the prompt message of activeX initialization.
The script is as follows:
'----------------------------------------------------------------------------
'Ie client setting script
'Write by hbb0b0
'2017-09-04
'----------------------------------------------------------------------------
IP = "xxx. xxx"
Const HKEY_CURRENT_USER = & H80000001
StrComputer = "."
Set StdOut = WScript. StdOut
Set oReg = GetObject ("winmgmts: {impersonationLevel = impersonate }! """&_
StrComputer & "" root "default: StdRegProv ")
StrKeyRanges = "Software" "Microsoft" "Windows" "CurrentVersion" "Internet Settings" "ZoneMap" "Ranges"
OReg. EnumKey HKEY_CURRENT_USER, strKeyRanges, arrSubKeys
Dim strKeyName
Dim strValue
HasIP = false
'Check whether the IP address has been added to the trusted site
For Each subkey In arrSubKeys
''Stdout. WriteLine subkey
StrKeyName = strKeyRanges + "+ subkey
OReg. GetStringValue HKEY_CURRENT_USER, strKeyName, ": Range", strValue
'Stdout. WriteLine "Name:" & subKey + "value:" & strValue
If strValue = IP Then
HasIP = True
Exit
End If
Next
'If the IP address is not added to a trusted site, add the Ip address to the trusted site.
If hasIP = false Then
RangeName1 = strKeyRanges + "+" Range100"
''Stdout. WriteLine "hello" + rangeName1
OReg. CreateKey HKEY_CURRENT_USER, rangeName1
RangeName2 = ": Range"
''Stdout. WriteLine "hello" + rangeName2
OReg. SetStringValue HKEY_CURRENT_USER, rangeName1, rangeName2, IP
RangeName3 = "http"
RangeName3Value = 2
''Stdout. WriteLine "hello" + rangeName3
OReg. SetDWORDValue HKEY_CURRENT_USER, rangeName1, rangeName3, rangeName3Value
'Stdout. WriteLine "added to trusted site" + IP
End If
'Trusted site allows untrusted activeX Initialization
StrKeyActiveX = "Software" "Microsoft" "Windows" "CurrentVersion" "Internet Settings" "Zones" "2"
'Check whether activeX Initialization is set
Dim str1201Value
HasActiveXInit = False
OReg. GetDWORDValue HKEY_CURRENT_USER, strKeyActiveX, 1201, str1201Value
'Stdout. WriteLine strKeyActiveX + "1201:" + Cstr (str1201Value)
IF str1201Value = 0 Then
HasActiveXInit = True
End If
If hasActiveXInit = False Then
OReg. SetDWORDValue HKEY_CURRENT_USER, strKeyActiveX, 1,,0
OReg. GetDWORDValue HKEY_CURRENT_USER, strKeyActiveX, 1201, str1201NewValue
'Stdout. WriteLine strKeyActiveX + "1201 (new):" + Cstr (str1201NewValue)
End If
'Set the IE prompt for disabling trusted IE sites
'Check whether the activeX prompt is disabled
Dim str2201Value
HasActiveXWarning = False
OReg. GetDWORDValue HKEY_CURRENT_USER, strKeyActiveX, 2201, str2201Value
'Stdout. WriteLine strKeyActiveX + "2201:" + Cstr (str2201Value)
IF str2201Value = 0 Then
HasActiveXWarning = True
End If
'Close if the activeX prompt is not closed
If hasActiveXWarning = False Then
OReg. SetDWORDValue HKEY_CURRENT_USER, strKeyActiveX, 2,,0
OReg. GetDWORDValue HKEY_CURRENT_USER, strKeyActiveX, 2201, str2201NewValue
'Stdout. WriteLine strKeyActiveX + "2201 (new):" + Cstr (str2201NewValue)
End If
Note:
The Windows Script Host has two versions: Windows-based version (Wscript.exe), which provides the attribute list used to set the script attributes, and command prompt-based version (Cscript.exe ), it provides command line switches for setting script properties. Enter Wscript.exe or Cscript.exe at the command prompt to run one of them.
If you run:
Set StdOut = WScript. StdOut
StdOut. WriteLine "hello world"
StdOut reports an error, which is always empty. It can only be initialized in Cscript. Console output objects are available only in command line execution mode.