Solved

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

Posted on 2016-08-02
3
70 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 81

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 81

Expert Comment

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

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Understanding the various editions available is vital when you decide to purchase Windows Server 2012. You need to have a basic understanding of the features and limitations in each edition in order to make a well-informed decision that best suits y…
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 (…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
This tutorial will walk an individual through the process of installing of Data Protection Manager on a server running Windows Server 2012 R2, including the prerequisites. Microsoft .Net 3.5 is required. To install this feature, go to Server Manager…

751 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