Solved

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

Posted on 2016-08-02
3
41 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 78

Accepted Solution

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

Author Closing Comment

by:powerztom
Comment Utility
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 78

Expert Comment

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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
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…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now