I want a shortcut to toggle a service in Win10

Welcome Forums General PowerShell Q&A I want a shortcut to toggle a service in Win10

This topic contains 6 replies, has 3 voices, and was last updated by

Joe
 
Participant
8 months, 2 weeks ago.

  • Author
    Posts
  • #94999
    Joe

    Participant
    Points: 0
    Rank: Member

    I've been told the code I should use and reproduce it below, but have NO idea how to apply it, so I need help.

    "To stop a service run the following command:
    Stop-Service ServiceName
    To start a service run the following command:
    Start-Service ServiceName

    You can add that code to separate .PS1 files, or use the PowerShell editor to create your scripts."

    Since I have no idea about .PS1 files, but CAN launch the Powershell editor – the second option might suit me best.
    I can launch Powershell editor – but it evaporates after a few seconds.

  • #95001

    Keymaster
    Points: 1,624
    Helping HandTeam Member
    Rank: Community Hero

    It might be worth doing some basic learning on PowerShell first, but a .ps1 file is just a text file that PowerShell regards as an executable script. You fill it with commands you want to run, and it runs them in order.

    I'm afraid I doin't understand "evaporates" in terms of software, but any text editor will do.

    If PowerShell's going to be part of your life, I respectfully suggest you read "Learn Windows PowerShell in a Month of Lunches." It's a short, easy read, and it'll get you very much not he right track with a lot less grief.

  • #95007
    Joe

    Participant
    Points: 0
    Rank: Member

    I have experience with TRYING to write Macros and VBscript – and while I had success, it was only because I got models to adapt my needs to. I found it VERY time consuming.

    I infer from your hints that if I put
    "To stop a service run the following command:
    Stop-Service ServiceName
    To start a service run the following command:
    Start-Service ServiceName"
    into a text file and save it as PS1
    I have a script that Powershell can execute.

    This is where we run into the 'evaporates' problem.
    After I launch Powershell, a DOS like window open for a few seconds, then closes – Powershell 'evaporates'.
    I have no idea what is SUPPOSED to happen, but a disappeared window give me NO options to proceed.
    I hope you will take mercy on my predicament, and help me further.

    I do NOT expect the Powershell is going to be 'part of my life', but since 'using Powershell' has been the only suggestion I got when asking for a shortcut to toggling ONE service, I did start reading the introduction to Powershell – that did NOT reduce my perplexity.

  • #95025

    Participant
    Points: 22
    Rank: Member

    If you don't see powershell as part of your life then maybe you would be better sticking with native windows commands. The Sc.exe command can start and stop a service for you, and no powershell is required.

  • #95095
    Joe

    Participant
    Points: 0
    Rank: Member

    I am not fussy about the mechanism to achieve a single click toggle for one service. e.g. I would be happy with a macro or a batch file but I have never heard of an sc.exe command. If sc.exe can do what I want, I would much appreciate some detail about how to apply it.

  • #95098

    Participant
    Points: 22
    Rank: Member
  • #95101
    Joe

    Participant
    Points: 0
    Rank: Member

    Well, at least I now know that sc means Service Control. The rest of that referred post is gobbledgook to me.

The topic ‘I want a shortcut to toggle a service in Win10’ is closed to new replies.