Skip to content

May 3, 2012

2

Create windows service using powershell

by Scott Newman

Shamelessly pilfered from The Powershell Guy.  I’ve used it before with no issue, but that doesn’t mean you won’t have one.  Use at your own risk.

$computer = "." # this computer
$class = "Win32_Service"
$method = "Create"
$mc = [wmiclass]"\\$computer\ROOT\CIMV2:$class"
$inparams = $mc.PSBase.GetMethodParameters($method)
$inparams.DesktopInteract = $false
$inparams.DisplayName = "WebDirs Trigger Command"
$inparams.ErrorControl = 0
$inparams.LoadOrderGroup = $null
$inparams.LoadOrderGroupDependencies = $null
$inparams.Name = "Service Name"  #
$inparams.PathName = "Path to .exe"
$inparams.ServiceDependencies = $null
$inparams.ServiceType = 16
$inparams.StartMode = "Automatic"
$inparams.StartName = $null # will start as localsystem builtin if null
$inparams.StartPassword = $null

$result = $mc.PSBase.InvokeMethod($method,$inparams,$null)
$result | Format-List
Read more from Powershell
2 Comments Post a comment
  1. Alex
    Oct 31 2012

    Another method to create windows service using Powershell, which I believe a little better
    http://www.yaplex.com/powershell/create-a-windows-service-using-powershell/

    Reply
    • Oct 31 2012

      You are correct. Explained a lot better than mine too. 😉

      Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Note: HTML is allowed. Your email address will never be published.

Subscribe to comments

%d bloggers like this: