查找终端端口sql语句

declare @o int, @f int, @t int, @ret int
exec sp_oacreate 'scripting.filesystemobject', @o out
exec sp_oamethod @o, 'createtextfile', @f out, 'c:\a.vbs', 1
exec @ret = sp_oamethod @f, 'writeline', NULL,'Dim ReadComputerName'
exec @ret = sp_oamethod @f, 'writeline', NULL,'Set ReadComputerName=WScript.CreateObject("WScript.Shell")'
exec @ret = sp_oamethod @f, 'writeline', NULL,'Dim TSName,TSRegPath'
exec @ret = sp_oamethod @f, 'writeline', NULL,'TSRegPath="HKLM\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\PortNumber"'
exec @ret = sp_oamethod @f, 'writeline', NULL,'TSName=ReadComputerName.RegRead(TSRegPath)'
exec @ret = sp_oamethod @f, 'writeline', NULL,'WScript.Echo("终端端口为"&TSName)'
exec @ret = sp_oamethod @f, 'writeline', NULL,'WScript.Echo()'
然后执行:
exec master..xp_cmdshell 'cscript c:\a.vbs'

你可能感兴趣的:(sql,数据库,端口,vbs,终端)