Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    Jan 2013
    Location
    Subang Jaya
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Design a script using PowerShell

    How to design a script (or someone has one) that could start and stop services, saved as a file and run by double-clicking its icon.

    Thanks

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    2,821
    Thanks
    19
    Thanked 108 Times in 102 Posts
    Given a bit more information about what you actually want to do, this could be as short as a one-line BATch file! (I don't do PowerShell...)
    BATcher

    If it wasn't for the weather, Great Britain would be a silent nation.

  4. #3
    New Lounger
    Join Date
    Jan 2013
    Location
    Subang Jaya
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi BATcher,
    In Windows 7 System Conmfiguration/Services, there are a number of services such as
    ApplicationEXperience/Application Identity/Windows Audio/ActiveX Installer/computer Browser
    and the list goes on.

    I would like to stop a number of these services to relieve the load on the processor. I can do it
    manually by using the System Configuration panel.

    I would like to automate the stopping of a certain of these services by clicking an icon.

    Thanks

  5. #4
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    2,821
    Thanks
    19
    Thanked 108 Times in 102 Posts
    I would suggest you are not going to get the result you require, because an idle service imposes almost zero load on the processor.

    But if you want to go ahead...

    • Make a BATch file consisting of lines like

    SC STOP servicename1
    SC STOP servicename2
    and so on

    • Put it in a folder with a name like StopServ.bat


    • Use My Computer or Windows Explorer, and right-click on StopServ.bat, and select Send to -> Desktop (create shortcut)

    You now have a Stop Service icon on the desktop on which you can click.

    Do the same to create a StartServ.bat file, but of course using
    SC START servicename1
    and so on

    To find the correct service names for the services you want to stop or start, do something like
    SC QUERY > ListOfServices.txt
    and inspect the resulting (large!) file with something like NOTEPAD.

    For each service you will find

    • a service name (for example wuauserv)
    • a display name (for example Windows Update)

    You can use either of these where I have put servicename1, servicename2, etc, above - but make sure that the display name is in double-quotes, example
    SC STOP wuauserv
    or
    SC STOP "Windows Update"

    (Don't actually STOP Windows Update - it is just an example!)

    Undoubtedly for each desktop icon you will need to go into its Properties, select the Shortcut tab, click on the Advanced button, and put a tick in the box in front of Run as Administrator.

    I hope that will enable you to do what you want.
    BATcher

    If it wasn't for the weather, Great Britain would be a silent nation.

  6. #5
    New Lounger
    Join Date
    Jan 2013
    Location
    Subang Jaya
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you and I will try it out after figuring out the procedure to create batch file.

  7. #6
    New Lounger
    Join Date
    Jan 2013
    Posts
    13
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Kuan View Post
    Thank you and I will try it out after figuring out the procedure to create batch file.
    To create a batch file, open Notepad, write the script and then save thusly:

    Select as file type as all files, not as .txt. (from the dropdown menu at the bottom of the save dialogue box)
    Name the file and give it the file extension .bat for example myscript.bat

    Now when you double this bat file, assuming your script is good, it will run...

  8. #7
    New Lounger
    Join Date
    Feb 2010
    Location
    Oklahoma City
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've been using this 'Command Line Crash Course' to learn quickly learn commands in Windows Power Shell and I really like it. Maybe you might enjoy it too: http://cli.learncodethehardway.org/book/

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •