Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2016-08-02
3
Medium Priority
?
80 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 84

Accepted Solution

by:
David Johnson, CD, MVP earned 2000 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 84

Expert Comment

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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
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...
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 steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
Suggested Courses

971 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