views:

152

answers:

1

Hi

I am trying to list all the instances of sqlserver using c++ in vs2005.

How to do this using smo library in c++? give me code example.

Thanks in advance..

+1  A: 

Using the Windows Toolhelp API, you can enumerate the SQL Server processes, this without using the SQL API (which I didn't look).

  • You create a snapshot of your system with CreateToolhelp32Snapshot call.
  • Use Process32Next and Process32First to cycle through the snapshot processes.
  • With each process, query the PROCESSENTRY32 struct members. szExeFile contains the executable filename.

Note that services run under the services.exe executable so if your server is running as service maybe you won't see it with this method.

Hernán