?
Solved

SQL Instances Script

Posted on 2013-12-18
4
Medium Priority
?
473 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 2000 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
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 …

765 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