November 14, 2008 at 9:59 am
Has anyone written an Installscript that identifies all SQL Servers local to the Destination machine and on the network. For example, when you open SQL Server Service Manager it knows all SQL Servers on your network and local on your machine. I am trying to write a script to identify the server and allow the installer log into a selected server and run a script on the server to install a scripted database. I have found this code that locates all SQL Servers but it only finds the ones on a selected domain or on the default domain. Anyone have any ideas how I can expand this code to locate the local instances on the destination machine?
/**************************************************************************\
FUNCTION: Get_All_SQLServer(ServerList)
DESCRIPTION: retrieves all available SQL Servers in the current domain
IN: stringlist for SQL Servers
OUT: saves names of all SQL Servers in
AUTHOR: Sebastian [neo] Angermann
09/jan/2003
Thanks to Joe Baumgarten (jbaumgar@nxtrend.com)
and Damien Carbery (daymobrew@yahoo.com)
for sourcecode update!
NOTE: NETAPI32 (Get_All_SQLServer) works only on WinNT!
\***************************************************************************/
function Get_All_SQLServer( ServerList )
STRING aktSQLServer[255];
NUMBER i,nResult, ReadEntries, TotalEntries, Handle,Buffer,Laenge,l,pTestStr2;
SV ServerStructure;
SV POINTER pServerStructure;
SERVERSTR ServerName;
SERVERSTR POINTER pServerName;
NUMBER nBufferPointer, nBuff;
STRING szComputerName;
begin
// Retrieval method is different on NT/2k/XP and 95/98/Me.
GetSystemInfo( OS, nResult, aktSQLServer );
if ( nResult == IS_WINDOWSNT )
then
pServerStructure = &ServerStructure; // points to structure
pServerName = &ServerName;
//Get computer name
nBuff = 255;
nResult = MsiGetProperty(ISMSI_HANDLE,"ComputerName",szComputerName,nBuff);
//get server list
nResult = NetServerEnum( NULL, 100, Buffer, -1, ReadEntries, TotalEntries, SV_TYPE_SQLSERVER , NULL, Handle );
nBufferPointer = Buffer;
i = 0;
while( i < ReadEntries )
RtlMoveMemory( pServerStructure, nBufferPointer, 8 ); // copy address
l = pServerStructure->name;
Laenge = lstrlenW( l )*2; // calculate stringsize
if Laenge then
RtlMoveMemory( pServerName, l, Laenge); // copy servername
endif;
// Important! Unicode servername convert to ANSI
WideCharToMultiByte( 0, 0, pServerName, -1, aktSQLServer, Laenge/2, NULL, NULL );
ListAddString( ServerList, aktSQLServer, AFTER );
nBufferPointer = nBufferPointer + 8; // inc buffer
i++;
aktSQLServer = ""; // delete last servername
endwhile;
NetApiBufferFree( Buffer ); // free buffer
else
// Windows 95/98/Me.
// Get list of used SQL Servers from the registry.
// get used SQL Servers
if ( RegDBQueryKey( "SOFTWARE\\Microsoft\\MSSQLServer\\Client\\TDS",REGDB_NAMES, ServerList ) < 0 ) then
return -1;
endif;
// delete empty entries
nResult=ListGetFirstString( ServerList, aktSQLServer );
while ( nResult != END_OF_LIST )
if ( aktSQLServer = "" ) then
ListDeleteString( ServerList );
endif;
nResult = ListGetNextString( ServerList, aktSQLServer );
endwhile;
endif;
return 0;
end;
Any help would be appreciated.
Thanks,
William Strutts
Viewing post 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply