BAT file to restart WSearch service

User avatar
StuartR
Administrator
Posts: 12601
Joined: 16 Jan 2010, 15:49
Location: London, Europe

BAT file to restart WSearch service

Post by StuartR »

I need to stop and restart the Windows Search service on a laptop running Windows 10, so that it will index a disk drive that isn't present at boot time.

I can do this manually from the Services applet, by right clicking and choosing restart.

I tried a BAT file that simply has
NET STOP WSearch
NET START WSearch
(with a ping in between to add a bit of a delay).

This doesn't seem to work properly. Sometimes it says that it can't stop the service. Other times the stop seems to work, but the start says the service is already running.

The service startup is set to "Automatic (Delayed Start)", and this would be perfect if I could change the delay time, but I have no idea how to do that.

Any suggestions on the best way to proceed?
StuartR


User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: BAT file to restart WSearch service

Post by Rudi »

Only a suggestion (based on a find to disable and enable (in stead of stop and start).
Whether this is helpful of not, or gives you a pointer to a solution, I dunno...but see here...

Addition:
...or here for comprehensive info (Win10 not mentioned though).
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

User avatar
Leif
Administrator
Posts: 7208
Joined: 15 Jan 2010, 22:52
Location: Middle of England

Re: BAT file to restart WSearch service

Post by Leif »

Leif

User avatar
StuartR
Administrator
Posts: 12601
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: BAT file to restart WSearch service

Post by StuartR »

I should have just tried it.

When I ran the BAT file manually it gave the results I said. I just added it to task scheduler and it seems to be working fine. Life is strange.
StuartR


User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: BAT file to restart WSearch service

Post by Rudi »

Now you can REALLY claim all the credit! :grin:
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

User avatar
StuartR
Administrator
Posts: 12601
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: BAT file to restart WSearch service

Post by StuartR »

:laugh:
StuartR


User avatar
John Gray
PlatinumLounger
Posts: 5405
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: BAT file to restart WSearch service

Post by John Gray »

StuartR wrote:When I ran the BAT file manually it gave the results I said. I just added it to task scheduler and it seems to be working fine. Life is strange.
Possibly due to a difference in the accounts and/or privileges under which this ran?
John Gray

"(or one of the team)" - how your appointment letter indicates you won't be seeing the Consultant...

User avatar
StuartR
Administrator
Posts: 12601
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: BAT file to restart WSearch service

Post by StuartR »

I was running the BAT file as Administrator. I suspect it is to do with the Autorestart feature in the Windows service manager. I have a feeling that the service doesn't really need to be restarted because Windows does that automatically when you stop it with Net Stop. This could also account for the command thinking it has failed, as it sees the service is still running.
StuartR


User avatar
John Gray
PlatinumLounger
Posts: 5405
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: BAT file to restart WSearch service

Post by John Gray »

Maybe investigating some of the SC options (like SC STOP <servicename> then SC QUERY <servicename>) would assist in debugging? [Check the syntax!]

NET STOP/START is a bit of a do-it-and-hope method in comparison...
John Gray

"(or one of the team)" - how your appointment letter indicates you won't be seeing the Consultant...

User avatar
StuartR
Administrator
Posts: 12601
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: BAT file to restart WSearch service

Post by StuartR »

Thank you John, I will look that up
StuartR


User avatar
StuartR
Administrator
Posts: 12601
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: BAT file to restart WSearch service

Post by StuartR »

That was informative John. After SC stop Wsearch, I tried SC query WSearch very quickly a few times and the status was STOP PENDING for a very short time and then START PENDING and then RUNNING, which confirms my suspicion that it was auto-restarting very quickly
StuartR


User avatar
John Gray
PlatinumLounger
Posts: 5405
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: BAT file to restart WSearch service

Post by John Gray »

SC can be very useful, but in BATch files one has to deal with the complicated output.
Glad it has brought enlightenment!
John Gray

"(or one of the team)" - how your appointment letter indicates you won't be seeing the Consultant...

User avatar
StuartR
Administrator
Posts: 12601
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: BAT file to restart WSearch service

Post by StuartR »

In any case, I am a happy bunny because I can now index this transient disk drive.
StuartR