View Single Post
Old 01-23-2008   #3 (permalink)
Shay Levi


 
 

Re: How to start a remote service under a different user name


Try the Change method, you can get more info on it here:
http://msdn2.microsoft.com/en-us/library/aa384901.aspx


## Specify $null if you are not changing the password.
## Specify an empty string if the service has no password.
## When changing a service from a local system to a network, or from a network
to a
## local system, StartPassword must be an empty string ("") and not $null.

$user="domain\username"
$psw = "password"

$svc = Get-WmiObject win32_service -ComputerName computer -filter "name='alerter'"
$svc.change($null,$null,$null,$null,$null,$null,$user,$psw,$null,$null,$null)
# restart the service
$svc.StopService()
$svc.StartService()




-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> Flea# wrote:
>
Quote:

>> Hello,
>>
>> I need to be able to start a service a remote server under a
>> different logon name using PowerShell. If you right click on a
>> service and choose properties you can click on the 'Log On' tab and
>> by default it uses a system account but gives you the option to run
>> it as a different account. Is there a way to do this using PowerShell
>> and probably WMI?
>>
>> I was looking at the ServiceController.Start Method (String[]) which
>> allows you to pass parameters but I could not find examples of what
>> parameters you could pass. Does anyone know if this is possible?
>>
>> Thanks,
>> Flea
> I haven't checked other options, but there doesn't seem to be any
> option to pass along.
>
> I wasn't able to confirm either that the Start method accepted any
> kind of argument.
>
> http://msdn2.microsoft.com/en-us/lib...rocess.service
> controller_members.aspx
>
> No solution, but it might be possible.
>
> At the very least, maybe the 'log on' name can be changed directly,
> then the service started?
>
> Marco
>
> PowerGadgets MVP
> http://www.powergadgets.com/mvp
> Blog:
> http://marcoshaw.blogspot.com

My System SpecsSystem Spec