Solved

SQL Instances Script

Posted on 2013-12-18
4
465 Views
Last Modified: 2013-12-19
Please provide a vbscript to find SQL instances of remote machine.
0
Comment
Question by:Prasadkosana
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:Ramesh Babu Vavilla
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

707 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