'------------------------------------------- ' Copyright (c) Microsoft Corporation. All rights reserved. ' ' Version 2.0 ' sconfig.vbs - Configuration script used to setup a machine for remote configuration ' '------------------------------------------- const L_Msg001_Text = "无 IP 地址" const L_Msg002_Text = " 无 IP " const L_Msg003_Text = "找不到活动网络适配器。" const L_Msg004_Text = "警告" const L_Msg005_Text = " 服务器配置" const L_Msg006_Text = "1) 域/工作组: " const L_Msg007_Text = "2) 计算机名: " const L_Msg008_Text = "3) 添加本地管理员" const L_Msg009_Text = "8) 网络设置" const L_Msg010_Text = "5) Windows 更新设置: " const L_Msg011_Text = "6) 下载并安装更新 " const L_Msg012_Text = "7) 远程桌面: " const L_Msg013_Text = "所选内容:" const L_Msg014_Text = "9) 日期和时间" const L_Msg015_Text = ") 注销用户" const L_Msg016_Text = ") 重新启动服务器" const L_Msg017_Text = ") 关闭服务器" const L_Msg018_Text = ") 退出到命令行" const L_Msg019_Text = "输入数字以选择选项: " const L_Msg020_Text = "更改域/工作组成员身份" const L_Msg021_Text = "加入域(D)或工作组(W)? (空白=取消) " const L_Msg022_Text = "域" const L_Msg023_Text = "工作组" const L_Msg024_Text = "计算机当前已加入域。" const L_Msg025_Text = "是否要立即将该计算机从当前域中删除?" const L_Msg026_Text = "指定经过授权的域\用户: " const L_Msg027_Text = "正在从当前域中删除计算机..." const L_Msg028_Text = "必须重新启动计算机以应用这些更改。" const L_Msg029_Text = "是否立即重新启动?" const L_Msg030_Text = "重新启动" const L_Msg031_Text = "指定域\用户: " const L_Msg032_Text = "加入域" const L_Msg033_Text = "输入新的计算机名(空白=取消): " const L_Msg034_Text = "计算机名" const L_Msg035_Text = "正在更改计算机名..." const L_Msg036_Text = "输入帐户以加入本地 Administrators 组(空白=取消): " const L_Msg037_Text = "正在添加到本地 Administrators 组..." const L_Msg038_Text = "本地 Administrators 组" const L_Msg039_Text = "已将用户添加到本地 Administrators 组。" const L_Msg040_Text = "输出" const L_Msg043_Text = "Windows 更新当前设置为: " const L_Msg044_Text = "选择自动更新(A)或手动更新(M): " const L_Msg045_Text = "自动" const L_Msg046_Text = "系统将在每天凌晨 3:00 点检查并安装更新。" const L_Msg047_Text = "正在启用自动更新..." const L_Msg048_Text = "手动" const L_Msg049_Text = "系统从不检查更新。" const L_Msg050_Text = "正在禁用自动更新..." const L_Msg051_Text = "Windows 更新设置为 " const L_Msg052_Text = "更新设置" const L_Msg053_Text = "启用(E)或禁用(D)远程桌面? (空白=取消) " const L_Msg054_Text = "1) 仅允许使用网络级别身份验证运行远程桌面的客户端(更安全)" const L_Msg055_Text = "2) 允许运行任何版本的远程桌面的客户端(不太安全)" const L_Msg056_Text = "输入选择: " const L_Msg057_Text = "正在启用远程桌面..." const L_Msg058_Text = "为运行任何版本的远程桌面的客户端启用远程桌面(不太安全)。" const L_Msg059_Text = "远程桌面" const L_Msg060_Text = "仅为使用网络级别身份验证运行远程桌面的客户端启用远程桌面(更安全)。" const L_Msg061_Text = "无法禁用远程桌面。" const L_Msg062_Text = "正在禁用远程桌面..." const L_Msg063_Text = "已禁用远程桌面。" const L_Msg064_Text = "是否确实要注销?" const L_Msg065_Text = "注销" const L_Msg066_Text = "是否确实要重新启动?" const L_Msg067_Text = "是否确实要关闭?" const L_Msg068_Text = "关闭" const L_Msg069_Text = "已启用(所有客户端)" const L_Msg070_Text = "已启用(仅更安全的客户端)" const L_Msg071_Text = "已禁用" const L_Msg072_Text = "--------------------------------" const L_Msg073_Text = " 网络设置" const L_Msg074_Text = "可用的网络适配器" const L_Msg075_Text = "索引编号 IP 地址 描述" const L_Msg076_Text = "选择网络适配器索引编号(空白=取消): " const L_Msg077_Text = " 网络适配器设置" const L_Msg078_Text = "NIC 索引" const L_Msg079_Text = "描述 " const L_Msg080_Text = "IP 地址 " const L_Msg081_Text = "已启用 DHCP" const L_Msg082_Text = "首选 DNS 服务器 " const L_Msg083_Text = "备用 DNS 服务器 " const L_Msg084_Text = "1) 设置网络适配器地址" const L_Msg085_Text = "2) 设置 DNS 服务器" const L_Msg086_Text = "3) 清除 DNS 服务器设置" const L_Msg087_Text = "4) 返回主菜单" const L_Msg088_Text = "选择选项: " const L_Msg089_Text = "选择 DHCP (D)或静态 IP (S) (空白=取消): " const L_Msg090_Text = "设置静态 IP" const L_Msg091_Text = "输入静态 IP 地址: " const L_Msg092_Text = "输入子网掩码(空白 = 默认值 " const L_Msg093_Text = "): " const L_Msg094_Text = "输入默认网关: " const L_Msg095_Text = "正在将 NIC 设置为静态 IP..." const L_Msg096_Text = "无法更改 IP 地址。" const L_Msg097_Text = "网络设置" const L_Msg098_Text = "正在设置 NIC 以使用 DHCP..." const L_Msg099_Text = "DNS 服务器" const L_Msg100_Text = "输入新的首选 DNS 服务器(空白=取消): " const L_Msg101_Text = "已设置首选 DNS 服务器。" const L_Msg102_Text = "输入备用 DNS 服务器(空白=无): " const L_Msg103_Text = "已设置备用 DNS 服务器。" const L_Msg104_Text = "无法设置备用 DNS 服务器。" const L_Msg105_Text = "无法设置首选 DNS 服务器。" const L_Msg106_Text = "已删除 DNS 服务器。将从网络中自动获取 DNS 服务器。" const L_Msg107_Text = "无法删除 DNS 服务器。" const L_Msg108_Text = "无法加入工作组" const L_Msg109_Text = "欢迎使用工作组: " const L_Msg110_Text = "正在参与" const L_Msg111_Text = "正在检查系统..." const L_Msg112_Text = "请指定有效的 IP 地址。" const L_Msg113_Text = "IP 地址 127 无效,因为这些地址是为环回地址保留的。请指定介于 1 和 223 之间的某个其他有效值。" const L_Msg114_Text = "拒绝访问。" const L_Msg115_Text = "参数不正确。" const L_Msg116_Text = "系统无法打开指定的对象。" const L_Msg117_Text = "无法更新密码。" const L_Msg118_Text = "登录失败: 未知用户名或密码。" const L_Msg119_Text = "指定的域不存在或无法连接。" const L_Msg120_Text = "帐户已存在。" const L_Msg121_Text = "计算机已加入域。" const L_Msg122_Text = "计算机当前未加入域。" const L_Msg123_Text = "无法加入域。" const L_Msg124_Text = "要加入的域的名称: " const L_Msg125_Text = "要加入的工作组的名称: " const L_Msg126_Text = "正在加入 " const L_Msg127_Text = "..." const L_Msg128_Text = "===============================================================================" const L_Msg129_Text = "E" '(E)nable const L_Msg130_Text = "D" '(D)isable const L_Msg131_Text = "S" '(S)tatic IP const L_Msg132_Text = "D" '(D)HCP const L_Msg133_Text = "W" '(W)orkgroup const L_Msg134_Text = "D" '(D)omain const L_Msg135_Text = "在域环境中,指定域\用户名。" const L_Msg136_Text = "在工作组环境中,指定用户名。" const L_Msg137_Text = "M" 'Manual const L_Msg138_Text = "A" 'Automatic const L_Msg139_Text = "子网掩码" const L_Msg140_Text = "默认网关" const L_Msg141_Text = "此选项将启用服务器图形用户界面 Shell 并需要重新启动。" const L_Msg142_Text = "12) 还原图形用户界面(GUI)" const L_Msg143_Text = "11) Windows 激活 " const L_Msg144_Text = "键入 SCONFIG 以显示此菜单。" const L_Msg145_Text = "已启用" const L_Msg146_Text = "已禁用" const L_Msg149_Text = "确认" const L_Msg150_Text = "1) 显示许可证信息" const L_Msg151_Text = "2) 激活 Windows" const L_Msg153_Text = "3) 安装产品密钥" const L_Msg155_Text = "4) 返回主菜单" const L_Msg156_Text = "4) 配置远程管理 " const L_Msg157_Text = "1) 启用远程管理" const L_Msg158_Text = "2) 禁用远程管理" const L_Msg161_Text = "4) 返回主菜单" const L_Msg165_Text = "无法重新配置 Windows 防火墙。" const L_Msg166_Text = "已阻止对所有 Windows 防火墙配置文件进行远程管理。" const L_Msg167_Text = "是否要在重新启动计算机之前更改计算机名?" const L_Msg168_Text = "更改计算机名" const L_Msg172_Text = "按 Enter 键继续..." const L_Msg175_Text = "失败" const L_Msg179_Text = " 配置远程管理" const L_Msg186_Text = "IPv6 地址" const L_Msg187_Text = "IPv6 网关" const L_Msg188_Text = "3) 配置服务器的 Ping 响应" const L_Msg189_Text = "是否允许远程计算机对此服务器执行 Ping 操作?" const L_Msg190_Text = "已成功配置为允许 Ping 操作" const L_Msg191_Text = "已成功配置为禁止 Ping 操作" const L_Msg193_Text = "帮助改进 Windows Server! 通过加入客户体验改善计划(CEIP),Windows 将定期收集有关你的系统的统计信息,并将该信息上载到 Microsoft。该计划还定期下载文件,以收集有关你使用 Windows 时可能遇到的问题的信息。收集的信息不会用于识别你或你的公司的身份或者与你或你的公司联系。" const L_Msg194_Text = "如果你参与并随后决定使用此服务器上的映像技术构建其他服务器,这些服务器将包括在 CEIP 中。" const L_Msg195_Text = "有关详细信息,请访问 http://go.microsoft.com/fwlink/?LinkId=285528" const L_Msg196_Text = "有关 Windows 隐私信息,请访问 http://go.microsoft.com/fwlink/?LinkId=280262" const L_Msg197_Text = "10) 通过 CEIP 帮助改进产品 " const L_Msg198_Text = "不参与" const L_Msg199_Text = "是否参与客户体验改善计划?" const L_Msg200_Text = "客户体验改善计划(CEIP)" const L_Msg201_Text = " -- Windows 激活 --" const L_Msg202_Text = "客户体验改善计划(CEIP)设置是由系统管理员管理的,无法进行修改。" const L_Msg203_Text = "无法启用远程桌面。" const L_Msg204_Text = "正在启用远程管理..." const L_Msg205_Text = "正在禁用远程管理..." const L_Msg206_Text = "已成功启用远程管理" const L_Msg207_Text = "无法启用远程管理" const L_Msg208_Text = "已成功禁用远程管理" const L_Msg209_Text = "无法禁用远程管理" const L_Msg210_Text = "当前状态: 已启用远程管理" const L_Msg211_Text = "当前状态: 已禁用远程管理" const L_Msg212_Text = "无法检索远程管理设置" const L_Msg213_Text = "远程管理设置是由系统管理员管理的,无法进行修改。" const L_Msg214_Text = "启用图形用户界面" const L_Msg215_Text = "未知" const L_Msg216_Text = "输入产品密钥" const L_Msg217_Text = "帮助改进 Microsoft Hyper-V Server! 加入客户体验改善计划(CEIP)之后,Windows 将定期收集有关你的系统的统计信息,并将该信息上载到 Microsoft。该计划还会定期下载文件,以收集你在使用 Windows 时可能遇到的问题的相关信息。收集的信息不会用于识别你或你的公司的身份或者与你或你的公司联系。" const L_Msg218_Text = "有关 Microsoft Hyper-V Server 隐私信息,请访问 http://go.microsoft.com/fwlink/?LinkId=227746" const WUA_Script = "cscript WUA_SearchDownloadInstall.vbs" Dim CmdResults Dim pcname Dim group_type Dim groupname Dim InDomain Dim MgmtNIC Dim Autopatch Dim Update_schedule Dim objNetAdapter Dim DNSsetting Dim DisplayIP Dim objWshScriptExec Dim TS_status Dim HVS_SKU Dim CEIP_Status Dim RemoteManagementStatus Set oShell = WScript.CreateObject ("WScript.shell") Set objWMIService = GetObject( "winmgmts:\\.\root\cimv2") 'Force to run with cscript if Instr(1,Wscript.FullName,"Cscript",vbTextCompare)=0 then oShell.Run "cscript " & chr(34) & wscript.ScriptFullName & chr(34) wscript.quit end if Set oUACExec = oShell.Exec("cmd /c " & chr(34) & "whoami /groups | find " & chr(34) & "S-1-16-12288" & chr(34) & chr(34)) Do While (oUACExec.Status = cnWshRunning) WScript.Sleep 100 Loop If oUACExec.ExitCode <> 0 Then Set objShell = CreateObject("Shell.Application") objShell.ShellExecute "cscript", Chr(34) & WScript.ScriptFullName & Chr(34), "", "runas", 1 wscript.quit end if GetInitialStatusValues() Do ' Get NICs Set nics = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration where IPenabled=TRUE") ' Try to select the first NIC with an active IP for each n in nics MgmtNIC= n.index Set objNetAdapter = GetObject("winmgmts:Win32_NetworkAdapterConfiguration=" & MgmtNIC) exit for next ' Deal with case where NICs go away if MgmtNIC="" then 'No active NIC DisplayIP = L_Msg003_Text else Set objNetAdapter = GetObject("winmgmts:Win32_NetworkAdapterConfiguration=" & MgmtNIC) if objNetAdapter.IPenabled then DisplayIP = objNetAdapter.IPAddress(0) else 'No Active NICs DisplayIP = L_Msg003_Text end if end if ' Get Domain status InDomain = GetDomainStatus() ' Get Remote Desktop status CheckRemoteDesktop() ' Get Customer Exp Improvement Program status CheckCEIPstatus() 'Get Remote Mangement status CheckRemoteManagementStatus() wscript.echo wscript.echo L_Msg128_Text '====== wscript.echo L_Msg005_Text 'sconfig wscript.echo L_Msg128_Text '====== wscript.echo wscript.echo L_Msg006_Text & group_type &": " & groupname 'domain/workgroup wscript.echo L_Msg007_Text & pcname 'Computer name wscript.echo L_Msg008_Text 'Add local admin wscript.echo L_Msg156_Text & RemoteManagementStatus 'Configure Remote Access wscript.echo "" wscript.echo L_Msg010_Text & Update_schedule 'Update settings wscript.echo L_Msg011_Text 'Download and Install updates wscript.echo L_Msg012_Text & TS_status 'Remote Desktop wscript.echo "" if MgmtNIC="" then ' Network settings wscript.echo L_Msg009_Text & vbTab & vbTab & vbTab & DisplayIP else wscript.echo L_Msg009_Text end if wscript.echo L_Msg014_Text ' Date and Time wscript.echo L_Msg197_Text & CEIP_Status ' CEIP if HVS_SKU then offset=0 else ' Show Activation and Restore GUI menu items on Server Core wscript.echo L_Msg143_Text ' 11) Windows Activation offset=1 end if wscript.echo "" wscript.echo cstr(11+offset) & L_Msg015_Text ' Logoff wscript.echo cstr(12+offset) & L_Msg016_Text ' Restart wscript.echo cstr(13+offset) & L_Msg017_Text ' Shut Down wscript.echo cstr(14+offset) & L_Msg018_Text ' Exit to cmd line wscript.echo if HVS_SKU then wscript.echo wscript.StdOut.Write L_Msg019_Text OptionSelection = Wscript.StdIn.ReadLine wscript.echo Select Case OptionSelection Case "1" 'Change Domain/workgroup name wscript.echo wscript.echo L_Msg020_Text do wscript.echo wscript.StdOut.Write L_Msg021_Text DorW = Wscript.StdIn.ReadLine loop until ucase(DorW)=ucase(L_Msg134_Text) or ucase(DorW)=ucase(L_Msg133_Text) or DorW="" if ucase(DorW)=ucase(L_Msg133_Text) then 'Join Workgroup 'If in a domain, we need to remove it first before joining a workgroup if InDomain then confirm = msgbox(L_Msg024_Text & vbCRLF & L_Msg025_Text,VBYesNo,L_Msg004_Text) if confirm=vbYes then wscript.StdOut.Write L_Msg026_Text domainuser = Wscript.StdIn.ReadLine wscript.echo wscript.echo L_Msg027_Text targetstr = "netdom remove %computername% /domain:" & NewGroupName & " /userd:" & domainuser & " /passwordd:*" result= oShell.Run(targetstr,1,TRUE) if result=0 then confirm = msgbox(L_Msg028_Text & vbCRLF & L_Msg029_Text, VBYesNo,L_Msg030_Text) if confirm=vbYes then oShell.Run "shutdown /r /t 0",1 else DomainAccessErrorMsg(result) end if end if else JoinWorkgroup() end if end if if ucase(DorW)=ucase(L_Msg134_Text) then 'Joining Domain group_type= L_Msg022_Text wscript.echo wscript.echo L_Msg032_Text wscript.StdOut.Write L_Msg124_Text NewGroupName = Wscript.StdIn.ReadLine wscript.StdOut.Write L_Msg026_Text domainuser = Wscript.StdIn.ReadLine wscript.echo wscript.echo L_Msg126_Text & NewGroupName & L_Msg127_Text wscript.echo targetstr = "netdom join %computername% /domain:" & NewGroupName & " /userd:" & domainuser & " /passwordd:*" result= oShell.Run(targetstr,1,TRUE) if result=0 then confirm = msgbox(L_Msg167_Text, vbYesNo+vbDefaultButton2,L_Msg168_Text) if confirm=vbYes then ChangeComputerName() else confirm = msgbox(L_Msg028_Text & vbCRLF & L_Msg029_Text, VBYesNo,L_Msg030_Text) if confirm=vbYes then oShell.Run "shutdown /r /t 0",1 end if else DomainAccessErrorMsg(result) end if end if Case "2" 'Change Computer Name ChangeComputerName() Case "3" 'Add Account to local admin wscript.echo L_Msg135_Text wscript.echo L_Msg136_Text wscript.echo wscript.StdOut.Write L_Msg036_Text AddUserAcct = Wscript.StdIn.ReadLine if AddUserAcct="" then 'cancel else if not InDomain then 'Handle workgroup case by creating account first targetstr = "net user " & AddUserAcct & " * /add" result= oShell.Run(targetstr,1,TRUE) if result<>0 then 'Show error message RunShowOutput(targetstr) else AddToAdminGroup() end if else AddToAdminGroup() end if end if Case "4" 'Configure for remote management ConfigureRemoteManagement() Case "5" 'Update Settings wscript.echo L_Msg043_Text & Update_schedule wscript.StdOut.Write L_Msg044_Text updateselection = Wscript.StdIn.ReadLine if ucase(updateselection)=ucase(L_Msg138_Text) then 'Make updates automatic Update_schedule= L_Msg045_Text strSchedule= L_Msg046_Text wscript.echo wscript.echo L_Msg047_Text oShell.Run "Cscript %WinDir%\System32\SCregEdit.wsf /AU 4" & NewComputerName,7,TRUE end if if ucase(updateselection)=ucase(L_Msg137_Text) then 'Make updates manual Update_schedule= L_Msg048_Text strSchedule= L_Msg049_Text wscript.echo wscript.echo L_Msg050_Text oShell.Run "Cscript %WinDir%\System32\SCregEdit.wsf /AU 1" & NewComputerName,7,TRUE end if if ucase(updateselection)=ucase(L_Msg137_Text) or ucase(updateselection)=ucase(L_Msg138_Text) then oShell.Run "Net stop wuauserv",7,TRUE oShell.Run "Net start wuauserv",7,TRUE MsgBox L_Msg051_Text & Update_schedule & ". " & strSchedule, vbInformation, L_Msg052_Text end if Case "6" 'Install Security Patches 'Install all patches on seperate thread oShell.Run WUA_Script,1,False Case "7" 'Enable/disable Remote Desktop WScript.Echo wscript.StdOut.Write L_Msg053_Text rd = Wscript.StdIn.ReadLine if ucase(rd)=ucase(L_Msg129_Text) then ' Enable do wscript.echo wscript.echo L_Msg054_Text wscript.echo wscript.echo L_Msg055_Text wscript.echo wscript.StdOut.Write L_Msg056_Text rdsecuritylevel = Wscript.StdIn.ReadLine loop while not (rdsecuritylevel="1" or rdsecuritylevel="2") wscript.echo wscript.echo L_Msg057_Text 'Enable Remote Desktop Admin mode result=oShell.Run("Cscript %WinDir%\System32\Scregedit.wsf /ar 0 " & NewComputerName,7,TRUE) oShell.Run "Cscript %WinDir%\System32\Scregedit.wsf /cs 1 " & NewComputerName,7,TRUE if result=0 then if rdsecuritylevel=2 then 'Allow WinXP and Win 2003 clients oShell.Run "Cscript %WinDir%\System32\Scregedit.wsf /cs 0 " & NewComputerName,7,TRUE msgbox L_Msg058_Text,Information,L_Msg059_Text else msgbox L_Msg060_Text,Information,L_Msg059_Text end if else msgbox L_Msg203_Text,vbCritical,L_Msg059_Text end if end if if ucase(rd)=ucase(L_Msg130_Text) then wscript.echo wscript.echo L_Msg062_Text 'Disable Remote Desktop mode result=oShell.Run("Cscript %WinDir%\System32\Scregedit.wsf /ar 1 " & NewComputerName,7,TRUE) oShell.Run "Cscript %WinDir%\System32\Scregedit.wsf /cs 1 " & NewComputerName,7,TRUE if result=0 then msgbox L_Msg063_Text,vbInformation,L_Msg059_Text else msgbox L_Msg061_Text,vbCritical,L_Msg059_Text end if end if Case "8" 'Change Management NIC Assignment If MgmtNIC<>"" then ManagementNICsettings() else 'Display no active NIC message DisplayIP = L_Msg003_Text end if Case "9" 'Set Date and Time oShell.Run "control timedate.cpl" Case "10" 'Customer Experience Improvement Program DisplayCEIPdialog() Case "11" if not(HVS_SKU) then 'show Activation menu item ActivateInstall() else 'Logoff confirm = msgbox(L_Msg064_Text, vbYesNo+vbDefaultButton2,L_Msg065_Text) if confirm=vbYes then oShell.Run "logoff",7,True end if end if Case "12" if not(HVS_SKU) then 'Log Off confirm = msgbox(L_Msg064_Text, vbYesNo+vbDefaultButton2,L_Msg065_Text) if confirm=vbYes then oShell.Run "logoff",7,True end if else ' Restart confirm = msgbox(L_Msg066_Text, vbYesNo+vbDefaultButton2,L_Msg030_Text) if confirm=vbYes then oShell.Run "shutdown /r /t 0",1 end if end if Case "13" if not(HVS_SKU) then ' Restart confirm = msgbox(L_Msg066_Text, vbYesNo+vbDefaultButton2,L_Msg030_Text) if confirm=vbYes then oShell.Run "shutdown /r /t 0",1 else 'Shut Down confirm = msgbox(L_Msg067_Text, vbYesNo+vbDefaultButton2,L_Msg068_Text) if confirm=vbYes then oShell.Run "shutdown /s /t 0",1 end if Case "14" if not(HVS_SKU) then 'Shut Down confirm = msgbox(L_Msg067_Text, vbYesNo+vbDefaultButton2,L_Msg068_Text) if confirm=vbYes then oShell.Run "shutdown /s /t 0",1 else 'Exit to command line wscript.quit end if Case "15" if not(HVS_SKU) then 'Exit to command line wscript.quit end if Case Else ' end Select Loop 'Loops back to main menu unless exiting wscript.quit sub CheckRemoteDesktop() ' True if Remote Desktop enabled Dim Sh, sKey, sValueName, sValue, nValue Set Sh = CreateObject("WScript.Shell") sKey = "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server\" sValueName = "fDenyTSConnections" sValue = Sh.RegRead(SKey & sValueName) if sValue=0 then nValue= Sh.RegRead(sKey & "WinStations\RDP-Tcp\UserAuthentication") if nValue = 0 then TS_status= L_Msg069_Text else TS_status= L_Msg070_Text end if else TS_status= L_Msg071_Text end if End sub Function LegalNicSelected(pickedNIC) LegalNicSelected=False For Each nic in nics if pickedNIC=CStr(nic.Index) then LegalNicSelected=True end if Next end Function Sub ManagementNICsettings() Set nics = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPenabled=TRUE") Set objNetAdapter = GetObject("winmgmts:Win32_NetworkAdapterConfiguration=" & MgmtNIC) wscript.echo wscript.echo L_Msg072_Text wscript.echo L_Msg073_Text wscript.echo L_Msg072_Text wscript.echo wscript.echo wscript.echo L_Msg074_Text wscript.echo wscript.echo L_Msg075_Text For Each nic in nics if nic.IPenabled then DisplayIP = nic.IPAddress(0) else DisplayIP=L_Msg002_Text end if wscript.echo 'Adjust spacing for non EN-US if instr(L_Msg075_Text,"Index#") then wscript.StdOut.Write " " & nic.Index & VBTab & DisplayIP & VBTab & left(nic.Description,54) else wscript.StdOut.Write " " & nic.Index & VBTab & VBTab & DisplayIP & VBTab & left(nic.Description,47) end if Next wscript.Echo do wscript.Echo wscript.StdOut.Write L_Msg076_Text SelectedNIC = Wscript.StdIn.ReadLine loop until LegalNicSelected(SelectedNIC) or SelectedNIC = "" if SelectedNIC="" then 'Do nothing, Cancel was selected, return to main menu else 'Set the MgmtNIC to a legal value MgmtNIC=SelectedNIC do wscript.echo wscript.echo L_Msg072_Text wscript.echo L_Msg077_Text wscript.echo L_Msg072_Text wscript.echo Set nics = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration where IPenabled=TRUE") Set objNetAdapter = GetObject("winmgmts:Win32_NetworkAdapterConfiguration=" & MgmtNIC) 'Display NIC info (IP, DHCP, DNS) For Each nic in nics if nic.index=cint(MgmtNIC) then if nic.IPenabled then DisplayIP = "" DisplayIP = nic.IPAddress(0) DisplayIPv6 = "" DisplayIPv6 = nic.IPAddress(1) else DisplayIP=L_Msg002_Text end if wscript.echo wscript.echo L_Msg078_Text & vbTab & vbTab & MgmtNIC wscript.echo L_Msg079_Text & vbTab & vbTab & nic.Description wscript.echo L_Msg080_Text & vbTab & vbTab & DisplayIP & vbTab & DisplayIPv6 wscript.echo L_Msg139_Text & vbTab & vbTab & nic.IPSubnet(0) wscript.echo L_Msg081_Text & vbTab & vbTab & nic.DHCPenabled on error resume next DefaultGateway= cstr(nic.DefaultIPGateway(0)) if err<>0 then DefaultGateway = "" end if on error goto 0 on error resume next DisplayIPv6Gateway = cstr(nic.DefaultIPGateway(1)) if err<>0 then DisplayIPv6Gateway = "" end if on error goto 0 wscript.echo L_Msg140_Text & vbTab & vbTab & DefaultGateway & vbTab & DisplayIPv6Gateway on error resume next primarydns= cstr(nic.DNSServerSearchOrder(0)) if err<>0 then primarydns="" end if altdns= cstr(nic.DNSServerSearchOrder(1)) if err<>0 then altdns="" end if on error goto 0 wscript.echo L_Msg082_Text & vbTab & primarydns wscript.echo L_Msg083_Text & vbTab & altdns end if Next 'Display Network Adapter Options wscript.echo wscript.echo L_Msg084_Text wscript.echo L_Msg085_Text wscript.echo L_Msg086_Text wscript.echo L_Msg087_Text wscript.echo wscript.echo do wscript.StdOut.Write L_Msg088_Text NIC_option = Wscript.StdIn.ReadLine loop until (left(NIC_option,1)>= "1" and left(NIC_option,1) <= "4") or NIC_option="" Select Case NIC_option Case "1" ' Set NIC IP to DHCP or Static '---- Set IP for Selected NIC wscript.echo wscript.echo wscript.StdOut.Write L_Msg089_Text IPtypeSelection = Wscript.StdIn.ReadLine Select Case ucase(IPtypeSelection) Case ucase(L_Msg131_Text) 'Set Static IP wscript.echo wscript.echo L_Msg090_Text do wscript.StdOut.Write L_Msg091_Text ip_address = wscript.StdIn.ReadLine loop until CheckStaticIP(ip_address) If IdentifyIPv4(ip_address) then 'Get Netmask wscript.StdOut.Write L_Msg092_Text & DefaultNetmask(ip_address) & L_Msg093_Text netmask = wscript.StdIn.ReadLine if netmask="" then netmask=DefaultNetmask(ip_address) ' Get IPv4 Gateway do wscript.StdOut.Write L_Msg094_Text gateway = wscript.StdIn.ReadLine if gateway="" then exit do loop until CheckStaticIP(gateway) else ' Get IPv6 Gateway end if 'Set the IP address info strIPAddress = Array(ip_address) strSubnetMask = Array(netmask) strGateway = Array(gateway) strGatewayMetric = Array(1) wscript.echo L_Msg095_Text 'clear out all gateway entries first arrClearGateways = Array() errGateways = objNetAdapter.SetGateways(arrClearGateways, null) objNetAdapter.ReleaseDHCPLease errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask) errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric) If errEnable=0 Then Set objNetAdapter = GetObject("winmgmts:Win32_NetworkAdapterConfiguration=" & MgmtNIC) Else msgbox L_Msg096_Text & vbCrLF & errEnable,vbCritical,L_Msg097_Text wscript.echo L_Msg096_Text End If Case ucase(L_Msg132_Text) 'Set DHCP wscript.echo wscript.echo L_Msg098_Text 'clear out all gateway entries first arrClearGateways = Array() errGateways = objNetAdapter.SetGateways(arrClearGateways, null) errEnable = objNetAdapter.EnableDHCP() objNetAdapter.RenewDHCPLease If errEnable = 0 Then Set objNetAdapter = GetObject("winmgmts:Win32_NetworkAdapterConfiguration=" & MgmtNIC) Else msgbox L_Msg096_Text,vbCritical,L_Msg097_Text wscript.echo L_Msg096_Text End If Case Else 'Cancel end Select Case "2" ' Change DNS wscript.echo L_Msg099_Text wscript.echo wscript.StdOut.Write L_Msg100_Text DNSServer = wscript.StdIn.ReadLine strDNSServer=Array(DNSServer) if DNSServer="" then 'Cancelled else 'Set Preferred DNS errDNS = objNetAdapter.SetDNSServerSearchOrder(strDNSServer) If errDNS=0 Then 'Preferred DNS successfully set, set alternate msgbox L_Msg101_Text,vbInformation,L_Msg097_Text wscript.StdOut.Write L_Msg102_Text altDNSServer = wscript.StdIn.ReadLine strDNSServer=Array(DNSServer,altDNSServer) if altDNSServer="" then 'skip entering alternate DNS else errDNS = objNetAdapter.SetDNSServerSearchOrder(strDNSServer) If errDNS=0 Then 'Alternate DNS successfully set msgbox L_Msg103_Text,vbInformation,L_Msg097_Text wscript.echo L_Msg103_Text else msgbox L_Msg104_Text,vbCritical,L_Msg097_Text wscript.echo L_Msg104_Text end If end if else msgbox L_Msg105_Text,vbCritical,L_Msg097_Text end If end if Case "3" ' Remove DNS server settings 'clear out all entries and reset arrDNSServers = Array() errDNS = objNetAdapter.SetDNSServerSearchOrder(arrDNSServers) If errDNS=0 Then 'DNS successfully cleared msgbox L_Msg106_Text,vbInformation,L_Msg097_Text wscript.echo L_Msg106_Text else msgbox L_Msg107_Text,vbCritical,L_Msg097_Text wscript.echo L_Msg107_Text end If Case "4" ' return to Main Menu Case else end Select Loop Until NIC_option="4" or NIC_option="" end if end sub Sub ConfigureRemoteManagement() do wscript.echo wscript.echo L_Msg072_Text wscript.echo L_Msg179_Text wscript.echo L_Msg072_Text wscript.echo wscript.echo wscript.echo resultGet=oShell.Run("configure-smremoting.exe -get",7,TRUE) if resultGet=0 or resultGet=2 then wscript.echo L_Msg210_Text else if resultGet=1 or resultGet=3 then wscript.echo L_Msg211_Text else wscript.echo L_Msg212_Text end if end if wscript.echo wscript.echo L_Msg157_Text ' 1 Enable Remote Management wscript.echo L_Msg158_Text ' 2 Disable Remote Management wscript.echo L_Msg188_Text ' 3 Ping wscript.echo wscript.echo L_Msg161_Text ' 4 Return wscript.echo wscript.StdOut.Write L_Msg056_Text RemoteOption = Wscript.StdIn.ReadLine select case RemoteOption Case "1" ' Enable Remote Management if resultGet=2 or resultGet=3 then msgbox L_Msg213_Text,,L_Msg179_Text else wscript.echo wscript.echo L_Msg204_Text 'Enable Remote Management result=oShell.Run("configure-smremoting.exe -enable",7,TRUE) if result=0 then msgbox L_Msg206_Text,,L_Msg179_Text else msgbox L_Msg207_Text,,L_Msg179_Text end if end if Case "2" ' Disable Remote Management if resultGet=2 or resultGet=3 then msgbox L_Msg213_Text,,L_Msg179_Text else wscript.echo wscript.echo L_Msg205_Text 'Enable Remote Management result=oShell.Run("configure-smremoting.exe -disable",7,TRUE) if result=0 then msgbox L_Msg208_Text,,L_Msg179_Text else msgbox L_Msg209_Text,,L_Msg179_Text end if end if Case "3" 'Allow/Disallow Ping wscript.echo 'Allow Ping? confirm = msgbox(L_Msg189_Text,VBYesNo,L_Msg179_Text) if confirm=vbYes then ' Allow Ping result=oShell.Run("netsh firewall set icmpsetting 8",7,TRUE) if result=0 then wscript.echo L_Msg190_Text 'Successfully allow ping msgbox L_Msg190_Text,,L_Msg179_Text else wscript.echo L_Msg175_Text 'Failure msgbox L_Msg165_Text,vbCritical,L_Msg179_Text end if else 'Disallow Ping result=oShell.Run("netsh firewall set icmpsetting 8 disable",7,TRUE) if result=0 then wscript.echo L_Msg191_Text 'Disallow Ping successfully set msgbox L_Msg191_Text,,L_Msg179_Text else wscript.echo L_Msg175_Text 'Failure msgbox L_Msg165_Text,vbCritical,L_Msg179_Text end if end if Case else end Select loop while RemoteOption="1" or RemoteOption="2" or RemoteOption="3" end sub sub ChangeComputerName() Wscript.echo L_Msg034_Text Wscript.echo wscript.StdOut.Write L_Msg033_Text NewComputerName = Wscript.StdIn.ReadLine if NewComputerName<>"" then wscript.echo L_Msg035_Text wscript.echo InDomain = GetDomainStatus() if not InDomain then 'In workgroup result = oShell.Run("netdom renamecomputer %computername% /force /NewName:" & NewComputerName,7,TRUE) else 'In Domain wscript.StdOut.Write L_Msg026_Text domainuser = Wscript.StdIn.ReadLine result = oShell.Run("netdom renamecomputer %computername% /force /NewName:" & NewComputerName & " /userd:" & domainuser & " /passwordd:*",1,TRUE) end if if result=0 then confirm = msgbox(L_Msg028_Text & vbCRLF & L_Msg029_Text, VBYesNo,L_Msg030_Text) if confirm=vbYes then oShell.Run "shutdown /r /t 0",1 else DomainAccessErrorMsg(result) end if end if end sub sub JoinWorkgroup group_type= L_Msg023_Text wscript.StdOut.Write L_Msg125_Text NewGroupName = Wscript.StdIn.ReadLine wscript.echo wscript.echo L_Msg126_Text & NewGroupName & L_Msg127_Text targetstr = "Wmic computersystem where name=" & chr(34) & "%computername%" & chr(34) & " call joindomainorworkgroup name=" & chr(34) & NewGroupName & chr(34) returncode = oShell.Run(targetstr,7,TRUE) if returncode<>0 then msgbox L_Msg108_Text,VBCritical,L_Msg023_Text else msgbox L_Msg109_Text & NewGroupName,vbInformation,L_Msg023_Text end if end sub Sub GetInitialStatusValues() wscript.echo L_Msg111_Text wscript.echo on error resume next 'Determine if Hyper-V Server SKU HVS_SKU= VerifyHVS() ' Get update settings status AutoPatch = oShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\AUOptions") if AutoPatch=4 then Update_schedule = L_Msg045_Text else Update_schedule = L_Msg048_Text end if Set nics = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration where IPenabled=TRUE") ' Try to select the first NIC with an active IP if MgmtNIC="" then DisplayIP = L_Msg001_Text for each n in nics MgmtNIC= n.index Set objNetAdapter = GetObject("winmgmts:Win32_NetworkAdapterConfiguration=" & MgmtNIC) exit for next end if if MgmtNIC="" then 'Display no active NIC message DisplayIP = L_Msg003_Text Msgbox DisplayIP,vbExclamation,L_Msg004_Text end if End Sub function GetCmdLineOutput() Set objStdOut = objWshScriptExec.StdOut GetCmdLineOutput = objStdOut.ReadAll end function Function CheckStaticIP(ip) on error resume next IPstart = left(ip,instr(ip,".")-1) on error goto 0 if IPstart>=1 and IPstart<224 then CheckStaticIP=TRUE else msgbox L_Msg112_Text,vbCritical,L_Msg097_Text CheckStaticIP=FALSE end if if IPstart=127 then CheckStaticIP=FALSE msgbox L_Msg113_Text,vbCritical,L_Msg097_Text end if end function Function IdentifyIPv4(ip) IdentifyIPv4= TRUE end function Function DefaultNetmask(ip) DefaultNetmask="" on error resume next IPstart = left(ip,instr(ip,".")-1) on error goto 0 if IPstart>=0 and IPstart <127 then DefaultNetmask="255.0.0.0" end if if IPstart>127 and IPstart <224 then DefaultNetmask="255.255.255.0" end if end function Sub DomainAccessErrorMsg(result) Select Case result Case 5 strErrorDescription = L_Msg114_Text Case 87 strErrorDescription = L_Msg115_Text Case 110 strErrorDescription = L_Msg116_Text Case 1323 strErrorDescription = L_Msg117_Text Case 1326 strErrorDescription = L_Msg118_Text Case 1355 strErrorDescription = L_Msg119_Text Case 2224 strErrorDescription = L_Msg120_Text Case 2691 strErrorDescription = L_Msg121_Text Case 2692 strErrorDescription = L_Msg122_Text Case else strErrorDescription = L_Msg123_Text End Select msgbox strErrorDescription,vbCritical,L_Msg022_Text end sub Function GetDomainStatus() Set colItems = objWMIService.ExecQuery( "Select * from Win32_ComputerSystem", , 48 ) For Each objItem in colItems pcname = objItem.Name strComputerDomain = objItem.Domain If objItem.PartOfDomain Then group_type= L_Msg022_Text groupname= strComputerDomain GetDomainStatus=TRUE Else group_type= L_Msg023_Text groupname= strComputerDomain GetDomainStatus=FALSE End If Next end Function Function VerifyHVS() on error resume next OStype = oShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\EditionID") on error goto 0 if Instr(OStype,"ServerHyper") then VerifyHVS=TRUE else VerifyHVS=FALSE end if end Function sub AddToAdminGroup() wscript.echo L_Msg037_Text Set colAccounts = objWMIService.ExecQuery _ ("Select * From Win32_Group Where Domain = '" & pcname & "' AND SID = 'S-1-5-32-544'") For Each objAccount in colAccounts admingroupname = objAccount.Name Next targetstr= "net localgroup " & admingroupname & " /add " & AddUserAcct RunShowOutput(targetstr) end sub sub RunShowOutput(strCommand) Set objWshScriptExec = oShell.Exec("cmd /C " & strCommand & " 2>&1") strStdOut = objWshScriptExec.stdout.readall msgbox strStdOut,,L_Msg040_Text Set objWshScriptExec=nothing end sub sub CheckCEIPstatus() 'Check for policy on error resume next CEIP_Value1= oShell.RegRead("HKLM\Software\Policies\Microsoft\SQMClient\Windows\CEIPEnable") on error goto 0 if CEIP_Value1="" then 'Check for local on error resume next CEIP_Value2= oShell.RegRead("HKLM\Software\Microsoft\SQMClient\Windows\CEIPEnable") if CEIP_Value2="" then CEIP_Value2=0 on error goto 0 if CEIP_Value2=1 then CEIP_Status= L_Msg110_Text 'Participating else CEIP_Status= L_Msg198_Text 'Not Participating end if else if CEIP_Value1=1 then CEIP_Status= L_Msg110_Text 'Participating else CEIP_Status= L_Msg198_Text 'Not Participating end if end if end sub sub CheckRemoteManagementStatus() resultGet=oShell.Run("configure-smremoting.exe -get",0,TRUE) if resultGet=0 or resultGet=2 then RemoteManagementStatus= L_Msg145_Text 'Enabled else if resultGet=1 or resultGet=3 then RemoteManagementStatus= L_Msg146_Text 'Disabled else RemoteManagementStatus= L_Msg215_Text 'Unknown end if end if end sub sub DisplayCEIPdialog() on error resume next CEIP_Value1= oShell.RegRead("HKLM\Software\Policies\Microsoft\SQMClient\Windows\CEIPEnable") on error goto 0 if HVS_SKU then 'Show Hyper-V Server CEIP text confirm = msgbox(L_Msg217_Text & vbCrLf & vbCrLf & L_Msg194_Text & vbCrLf & vbCrLf & L_Msg195_Text & vbCrLf & vbCrLf & L_Msg218_Text & vbCrLf & vbCrLf & L_Msg199_Text,vbYesNo+vbDefaultButton2,L_Msg200_Text ) else 'Show Windows Server CEIP text confirm = msgbox(L_Msg193_Text & vbCrLf & vbCrLf & L_Msg194_Text & vbCrLf & vbCrLf & L_Msg195_Text & vbCrLf & vbCrLf & L_Msg196_Text & vbCrLf & vbCrLf & L_Msg199_Text,vbYesNo+vbDefaultButton2,L_Msg200_Text ) end if if CEIP_Value1<>"" then msgbox L_Msg202_Text,,L_Msg200_Text else if confirm=vbYes then oShell.Exec("%ComSpec% /C serverCEIPOptin /enable") msgbox L_Msg110_Text,,L_Msg145_Text else oShell.Exec("%ComSpec% /C serverCEIPOptin /disable") msgbox L_Msg198_Text,,L_Msg146_Text end if end if end sub Sub ActivateInstall() do wscript.echo wscript.echo L_Msg201_Text wscript.echo wscript.echo L_Msg150_Text '1) Display License info wscript.echo L_Msg151_Text '2) Activate Windows wscript.echo L_Msg153_Text '3) Install Product key wscript.echo L_Msg155_Text '4) Exit wscript.echo wscript.StdOut.Write L_Msg056_Text 'Enter selection: OptionSelection = Wscript.StdIn.ReadLine Select case OptionSelection Case "1" 'Display License information oShell.Run ("%ComSpec% /K cscript %windir%\system32\slmgr.vbs /dli") Case "2" 'Activate Windows oShell.Run ("%ComSpec% /K cscript %windir%\system32\slmgr.vbs /ato") Case "3" 'Install Product key pid= inputbox(L_Msg216_Text, L_Msg216_Text) if pid <> "" then oShell.Run ("%ComSpec% /K cscript %windir%\system32\slmgr.vbs /ipk " & pid) end if Case else end select loop Until OptionSelection="4" end sub