Solved

SQL Instances Script

Posted on 2013-12-18
4
458 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
ID: 39728751
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
ID: 39728902
open command prompt and then
osql -L

or SQLCMD -L
0
 

Author Comment

by:Prasadkosana
ID: 39730016
Hi,

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

Thanks,
Prasad.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL 2016: choose separate instances for software install; performance 19 24
SQL Pivot table 2 42
sql update 2 36
access to sql migration 5 20
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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 backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

713 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