Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- netsh firewall set portopening protocol = TCP port = 1433 name = SQLPort mode = ENABLE scope = SUBNET profile = CURRENT
- ALTER LOGIN [sa] WITH PASSWORD='*****newPassword****'
- SQLCMD -U sa -P newPassword -S 192.168.0.120SQLEXPRESS,1433
- set wmiComputer = GetObject( _
- "winmgmts:" _
- & "\.rootMicrosoftSqlServerComputerManagement10")
- set tcpProtocols = wmiComputer.ExecQuery( _
- "select * from ServerNetworkProtocol " _
- & "where InstanceName = 'SQLEXPRESS' and ProtocolName = 'Tcp'")
- if tcpProtocols.Count = 1 then
- ' set tcpProtocol = tcpProtocols(0)
- ' I wish this worked, but unfortunately
- ' there's no int-indexed Item property in this type
- ' Doing this instead
- for each tcpProtocol in tcpProtocols
- dim setEnableResult
- setEnableResult = tcpProtocol.SetEnable()
- if setEnableResult <> 0 then
- Wscript.Echo "Failed!"
- end if
- next
- end if
- set wmiComputer = GetObject( _
- "winmgmts:" _
- & "\.rootMicrosoftSqlServerComputerManagement10")
- set tcpProperties = wmiComputer.ExecQuery( _
- "select * from ServerNetworkProtocolProperty " _
- & "where InstanceName='SQLEXPRESS' and " _
- & "ProtocolName='Tcp' and IPAddressName='IPAll'")
- for each tcpProperty in tcpProperties
- dim setValueResult, requestedValue
- if tcpProperty.PropertyName = "TcpPort" then
- requestedValue = "3456"
- elseif tcpProperty.PropertyName ="TcpDynamicPorts" then
- requestedValue = ""
- end if
- setValueResult = tcpProperty.SetStringValue(requestedValue)
- if setValueResult = 0 then
- Wscript.Echo "" & tcpProperty.PropertyName & " set."
- else
- Wscript.Echo "" & tcpProperty.PropertyName & " failed!"
- end if
- next
- SQLCMD -U sa -P newPassword -S 192.168.0.120,3456
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement