Start/ Stop SQL Express with .bat

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Start/ Stop SQL Express with .bat

Post by agibsonsw »

On previous laptops I was able to use the following batch file to start and stop SQL Server Express:

Code: Select all

NET START "SQL Server (SQLEXPRESS)"||NET STOP "SQL Server (SQLEXPRESS)"
It doesn't work on my Windows 8 laptop with an error of Access Denied.

When I start the Server Manager I have a UAC message to confirm, so I turned off UAC temporarily but my batch-file still gave the same error.

Do you think I need a Firewall setting, or is there some property of the Server that I should be setting? Or other cause?
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

User avatar
HansV
Administrator
Posts: 78411
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Start/ Stop SQL Express with .bat

Post by HansV »

Try creating a shortcut to the batch file.
Right-click the shortcut and select Properties from the context menu.
Activate the Shortcut tab.
Click Advanced...
Tick the check box "Run as administrator".
Use the shortcut to run the batch file.
Does that work for you?
Best wishes,
Hans

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: Start/ Stop SQL Express with .bat

Post by agibsonsw »

Cool, fab!

All I need to find now is a way to toggle the shortcut icon hint, hint ;)
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

User avatar
HansV
Administrator
Posts: 78411
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Start/ Stop SQL Express with .bat

Post by HansV »

To change a shortcut's icon using VBScript: How Can I Change the Icon for an Existing Shortcut?
Best wishes,
Hans

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: Start/ Stop SQL Express with .bat

Post by agibsonsw »

Thanks Hans.

I'll have to investigate a little further though as I will be putting the shortcut in the notification area. (I'll also have to translate my .bat code to VBS, unless I execute the VBS from the bat.)

I'm sure you can tell where I'm trying to get to ;) I want a red circle in the notification area, that goes green when I click it and start the server. [I might also attempt to hide the console window.. think this might involve > NUL, or sumfink. Added: Actually, this is probably not possible and I'll probably just let it flash open and closed - if it goes green then the server has started.]

I'll report back if I make progress :smile:

I'll just note this here, as I might need it later ;)

Code: Select all

%windir%\System32\cmd.exe /C "Drive:\Folder\Your batchfile.bat"
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

User avatar
HansV
Administrator
Posts: 78411
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Start/ Stop SQL Express with .bat

Post by HansV »

I'm not an expert on this, but I suspect that you'd have to create a compiled application (.exe) in one of the .NET environments for that.
Best wishes,
Hans