Solved

Services need to be start on Server 2012 also Win 10.

Posted on 2016-08-02
3
63 Views
Last Modified: 2016-08-03
I just want to start off with SqlBrowser it's Startup is Manual I know I can set it to automatic but what I'm getting at is my VB Script no longer works. I tried fooling around in VB.NET with Service Controller no luck. Here is VB Script
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colServiceList = objWMIService.ExecQuery _
    ("Select * from Win32_Service where Name = 'SQLBrowser'")

For Each objService in colServiceList
    If objService.State = "Stopped" Then
        objService.StartService()
        Wscript.Sleep 5000
    objService.ChangeStartMode("Automatic")
End If
   ' errReturnCode = objService.ChangeStartMode("Automatic")   
Next

Open in new window


VB.NET Code
Imports System.ServiceProcess
Public Class Form1

    Private Sub StartStop()
        Dim service As ServiceController = New ServiceController("SQLBrowser")
        If ((service.Status.Equals(ServiceControllerStatus.Stopped)) Or
            (service.Status.Equals(ServiceControllerStatus.StopPending))) Then
            service.Start()
            Me.Close()
        Else
            service.Stop()
            Me.Close()
        End If
    End Sub





    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
        StartStop()
    End Sub
End Class

Open in new window

This code errors out on

Exception:Thrown: "Cannot open SQLBrowser service on computer '.'." (System.InvalidOperationException)
A System.InvalidOperationException was thrown: "Cannot open SQLBrowser service on computer '.'."
Time: 8/2/2016 4:02:40 PM
Thread:<No Name>[4588]
0
Comment
Question by:powerztom
  • 2
3 Comments
 
LVL 80

Accepted Solution

by:
David Johnson, CD, MVP earned 500 total points
ID: 41740002
Your code works, but you have to launch visual studio as an administrator
0
 

Author Closing Comment

by:powerztom
ID: 41740065
Thank You my good man Any idea VB  Script doesn't work VB Script when you right  click  it doesn't allow you  to run   as administrator? Thanks my  Friend
0
 
LVL 80

Expert Comment

by:David Johnson, CD, MVP
ID: 41740326
open cmd prompt as an admin then run the script
1

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

What to do when Windows Update is not working correctly? What tools can I use to detect the cause of the malfunction problem? What does this numeric error code mean? These and other questions that you have been asking in the past are answered here (…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this Micro Tutorial viewers will learn how to use Windows Server Backup to create full image of their system. Tutorial shows how to install Windows Server Backup Feature on Windows 2012R2 and how to configure scheduled Bare Metal Recovery backup.…
This tutorial will walk an individual through the process of configuring basic necessities in order to use the 2010 version of Data Protection Manager. These include storage, agents, and protection jobs. Launch Data Protection Manager from the deskt…

808 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