Solved

SQL Instances Script

Posted on 2013-12-18
4
446 Views
Last Modified: 2013-12-19
Please provide a vbscript to find SQL instances of remote machine.
0
Comment
Question by:Prasadkosana
4 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
Comment Utility
Hi,
here a sample script:
' Please adjust to your server name
strServerName = "RAINERJDEV"

' Default variables
defaultInstanceName = "MSSQLSERVER"
strMsg = "Installed instances on " & strServerName & ":" & vbcrlf
Const HKEY_LOCAL_MACHINE = &H80000002

' Now start by reading reg key
Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strServerName & "\root\default:StdRegProv")
strMSSQLRootKeyPath = "SOFTWARE\Microsoft\Microsoft SQL Server"
strInstanceKey = "InstalledInstances"
objRegistry.GetMultiStringValue HKEY_LOCAL_MACHINE, strMSSQLRootKeyPath, strInstanceKey,arrOfInstances
If IsNull(arrOfInstances) = false Then 
	' We have a SQL Server
	For Each strRegValue In arrOfInstances
		If UCase(strRegValue) <> defaultInstanceName Then 
			strSQLInstanceName = strServerName & "\" & strRegValue
		Else
			strSQLInstanceName = strServerName
		End If
		strMsg = strMsg & strSQLInstanceName & vbcrlf
	Next
Else
	strMsg = strMsg & "No SQL Server installed!"
End If
Set objRegistry = Nothing
Msgbox strMsg

Open in new window


Displays all instances (or if default instance the machine name) on that machine.
You just have to ensure that you have proper permissions to access and read the remote registry.

HTH
Rainer
0
 
LVL 10

Expert Comment

by:sqlservr
Comment Utility
open command prompt and then
osql -L

or SQLCMD -L
0
 

Author Comment

by:Prasadkosana
Comment Utility
Hi,

  Can you also help me to integrate the above vbscript in system cneter orchetsrator?

Thanks,
Prasad.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now