Home All Groups Group Topic Archive Search About
Author
3 Mar 2007 2:35 AM
Michael Tissington
The following code works ...

Set objWMIService =
GetObject("winmgmts:\\.\root\Microsoft\SqlServer\ComputerManagement")
Set colItems = objWMIService.ExecQuery("SELECT * FROM
ServerNetworkProtocolProperty WHERE PropertyName = 'TcpPort'",,48)
For Each objItem in colItems
    objItem.SetStringValue("1433")
Next

However is a specifiy a named instance like

Set objWMIService =
GetObject("winmgmts:\\.\root\Microsoft\SqlServer\ComputerManagement\Instance_Name")

I always get  back a null object.

How do I specify a named instance of SQL ?

Author
3 Mar 2007 5:23 AM
Steve
Show quote
On Mar 2, 6:35 pm, "Michael Tissington" <mtissing...@newsgroup.nospam>
wrote:
> The following code works ...
>
> Set objWMIService =
> GetObject("winmgmts:\\.\root\Microsoft\SqlServer\ComputerManagement")
> Set colItems = objWMIService.ExecQuery("SELECT * FROM
> ServerNetworkProtocolProperty WHERE PropertyName = 'TcpPort'",,48)
> For Each objItem in colItems
>     objItem.SetStringValue("1433")
> Next
>
> However is a specifiy a named instance like
>
> Set objWMIService =
> GetObject("winmgmts:\\.\root\Microsoft\SqlServer\ComputerManagement\Instanc­e_Name")
>
> I always get  back a null object.
>
> How do I specify a named instance of SQL ?

Google
WMI "SQL Server" InstanceName root\Microsoft\SqlServer
\ComputerManagement

You will get plenty of doe samples
Author
3 Mar 2007 6:23 AM
Michael Tissington
Hmm, I'm not seeing anything that relates to specifying an InstanceName with
SqlServer\ComputerManagement


Show quote
"Steve" <morrisz***@hotmail.com> wrote in message
news:1172899395.780295.14950@t69g2000cwt.googlegroups.com...
On Mar 2, 6:35 pm, "Michael Tissington" <mtissing...@newsgroup.nospam>
wrote:
> The following code works ...
>
> Set objWMIService =
> GetObject("winmgmts:\\.\root\Microsoft\SqlServer\ComputerManagement")
> Set colItems = objWMIService.ExecQuery("SELECT * FROM
> ServerNetworkProtocolProperty WHERE PropertyName = 'TcpPort'",,48)
> For Each objItem in colItems
>     objItem.SetStringValue("1433")
> Next
>
> However is a specifiy a named instance like
>
> Set objWMIService =
> GetObject("winmgmts:\\.\root\Microsoft\SqlServer\ComputerManagement\Instanc­e_Name")
>
> I always get  back a null object.
>
> How do I specify a named instance of SQL ?

Google
WMI "SQL Server" InstanceName root\Microsoft\SqlServer
\ComputerManagement

You will get plenty of doe samples
Author
3 Mar 2007 4:28 PM
Steve
On Mar 2, 10:23 pm, "Michael Tissington"
<mtissing...@newsgroup.nospam> wrote:
Show quote
> Hmm, I'm not seeing anything that relates to specifying an InstanceName with
> SqlServer\ComputerManagement
>
> "Steve" <morrisz***@hotmail.com> wrote in message
>
> news:1172899395.780295.14950@t69g2000cwt.googlegroups.com...
> On Mar 2, 6:35 pm, "Michael Tissington" <mtissing...@newsgroup.nospam>
> wrote:
>
>
>
>
>
> > The following code works ...
>
> > Set objWMIService =
> > GetObject("winmgmts:\\.\root\Microsoft\SqlServer\ComputerManagement")
> > Set colItems = objWMIService.ExecQuery("SELECT * FROM
> > ServerNetworkProtocolProperty WHERE PropertyName = 'TcpPort'",,48)
> > For Each objItem in colItems
> >     objItem.SetStringValue("1433")
> > Next
>
> > However is a specifiy a named instance like
>
> > Set objWMIService =
> > GetObject("winmgmts:\\.\root\Microsoft\SqlServer\ComputerManagement\Instanc­­e_Name")
>
> > I always get  back a null object.
>
> > How do I specify a named instance of SQL ?
>
> Google
> WMI "SQL Server" InstanceName root\Microsoft\SqlServer
> \ComputerManagement
>
> You will get plenty of doe samples- Hide quoted text -
>
> - Show quoted text -

' enum protocols and show status

set wmi = GetObject("WINMGMTS:\\.\root\Microsoft\SqlServer
\ComputerManagement")

for each prop in wmi.ExecQuery("select * " & _

      "from ServerNetworkProtocol " & _

      "where InstanceName = 'mssqlserver'")

WScript.Echo prop.ProtocolName & " - " & _

              prop.ProtocolDisplayName & "  " & _

              prop.Enabled

next

' enable named pipes

for each changeprop in wmi.ExecQuery("select * " & _

      "from ServerNetworkProtocol " & _

      "where InstanceName = 'mssqlserver' and " & _

      "ProtocolName = 'Np'")

changeprop.SetEnable()

next
Author
3 Mar 2007 4:32 PM
Steve
Show quote
On Mar 3, 8:28 am, "Steve" <morrisz***@hotmail.com> wrote:
> On Mar 2, 10:23 pm, "Michael Tissington"
>
>
>
>
>
> <mtissing...@newsgroup.nospam> wrote:
> > Hmm, I'm not seeing anything that relates to specifying an InstanceName with
> > SqlServer\ComputerManagement
>
> > "Steve" <morrisz***@hotmail.com> wrote in message
>
> >news:1172899395.780295.14950@t69g2000cwt.googlegroups.com...
> > On Mar 2, 6:35 pm, "Michael Tissington" <mtissing...@newsgroup.nospam>
> > wrote:
>
> > > The following code works ...
>
> > > Set objWMIService =
> > > GetObject("winmgmts:\\.\root\Microsoft\SqlServer\ComputerManagement")
> > > Set colItems = objWMIService.ExecQuery("SELECT * FROM
> > > ServerNetworkProtocolProperty WHERE PropertyName = 'TcpPort'",,48)
> > > For Each objItem in colItems
> > >     objItem.SetStringValue("1433")
> > > Next
>
> > > However is a specifiy a named instance like
>
> > > Set objWMIService =
> > > GetObject("winmgmts:\\.\root\Microsoft\SqlServer\ComputerManagement\Instanc­­­e_Name")
>
> > > I always get  back a null object.
>
> > > How do I specify a named instance of SQL ?
>
> > Google
> > WMI "SQL Server" InstanceName root\Microsoft\SqlServer
> > \ComputerManagement
>
> > You will get plenty of doe samples- Hide quoted text -
>
> > - Show quoted text -
>
> ' enum protocols and show status
>
> set wmi = GetObject("WINMGMTS:\\.\root\Microsoft\SqlServer
> \ComputerManagement")
>
> for each prop in wmi.ExecQuery("select * " & _
>
>       "from ServerNetworkProtocol " & _
>
>       "where InstanceName = 'mssqlserver'")
>
>  WScript.Echo prop.ProtocolName & " - " & _
>
>               prop.ProtocolDisplayName & "  " & _
>
>               prop.Enabled
>
> next
>
> ' enable named pipes
>
> for each changeprop in wmi.ExecQuery("select * " & _
>
>       "from ServerNetworkProtocol " & _
>
>       "where InstanceName = 'mssqlserver' and " & _
>
>       "ProtocolName = 'Np'")
>
>  changeprop.SetEnable()
>
> next- Hide quoted text -
>
> - Show quoted text -

from http://support.microsoft.com/default.aspx/kb/911839

If oArgs.Count <> 5 Then
               WScript.Echo "Usage: ChangeSQLServiceAccounts.vbs
MachineName InstaNcename ServiceType SQLAccount SQLPassword"
               WScript.Echo "ServiceType = 1 (SQLServer), 2 (Agent), 3
(FTE), 4 (DTS), 5 (AS), 6 (RS), 7 (Browser)"
               WScript.Echo "Example: ChangeSQLServiceAccounts.vbs .
MSSQLServer 1 BuiltIn\System NULL"
               WScript.Quit(1)
Else

' Load the inputs into variables.

               strComputer = oArgs(0)
               strInstanceName = oArgs(1)
               strServiceType = oArgs(2)
               strAccountName = oArgs(3)
               strPassword = oArgs(4)
End If

' Get a WMI object for the SQL namespace.

Set objWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate}!\\" & strComputer & "\ROOT\microsoft
\sqlserver\ComputerManagement")

' Get an instance for this specific service.

Set objSQLService = objWMIService.Get("SqlService.ServiceName=""" &
strInstanceName & """,SQLServiceType=" & strServiceType)

' Obtain an InParameters object specific to the
SQLService.SetServiceAccount method.

Set objInParam =
objSQLService.Methods_("SetServiceAccount").inParameters.SpawnInstance_()

' Add the input parameters to the input object.

objInParam.Properties_.item("ServiceStartName") = strAccountName
objInParam.Properties_.item("ServiceStartPassword") = strPassword

' Call the SetServiceAccount method, and pass in the input object.

Set objOutParams = objSQLService.ExecMethod_("SetServiceAccount",
objInParam)

'Check the return to see whether there were any errors.

If objOutParams.ReturnValue = 0 Then
    Wscript.Echo "The service account was changed to " &
strAccountName
Else
    Wscript.Echo "Could not change the service account to " &
strAccountName & " due to error " & objOutParams.ReturnValue
End If
Author
3 Mar 2007 7:32 PM
Michael Tissington
Thanks Steve.

AddThis Social Bookmark Button