Solved

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

Posted on 2016-08-02
3
73 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
[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
  • 2
3 Comments
 
LVL 82

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 82

Expert Comment

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

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

I don't know if many of you have made the great mistake of using the Cisco Thin Client model with the management software VXC. If you have then you are probably more then familiar with the incredibly clunky interface, the numerous work arounds, and …
OfficeMate Freezes on login or does not load after login credentials are input.
In this Micro Tutorial viewers will learn how to use Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…
In this Micro Tutorial viewers will learn how to restore their server from Bare Metal Backup image created with Windows Server Backup feature. As an example Windows 2012R2 is used.

623 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