Windows Vista Forums
Vista Forums Home Join Vista Forums Webcasts Windows 7 Forum Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Help with script on service

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 05-15-2007   #1 (permalink)
Damon
Guest


 

Help with script on service

Hey all,
I have been playing with powershell for a few weeks now but I need to write
a script that is way beyond my knowledge so far.

I need to change the service "Remote Procedure Call" to log in with local
system account.

Is there an easy way to do this in powershell?
I have a list workstations.txt I can call to run WMI against but I do not
know the command to change the value.
Thanks for any help


My System SpecsSystem Spec
Old 05-15-2007   #2 (permalink)
Brandon Shell
Guest


 

Re: Help with script on service

To be completely honest with you... what you are asking for AFAICT should be
strait forward... I was actually ready just to post the code, but alas... I
cannot find a method to do what your want with .NET or WMI... Actually that
is not entirely accurate... I found a way to set the value with WMI, but it
does not commit to the actual service just the object. I am sure there is a
way to do it, but I would just use sc.exe and save your self the time.

example or something similar:
$cmd = "sc.exe \\$server config $service obj= `"user`" password=
`"password`""
invoke-expression $cmd

Here is an article to help.
http://support.microsoft.com/kb/166819

p.s. If anyone else has got this work using native Powershell.. I would love
to know how.

"Damon" <Damon@discussions.microsoft.com> wrote in message
news:66770754-90A2-47A8-B068-D5863CA0CE23@microsoft.com...
> Hey all,
> I have been playing with powershell for a few weeks now but I need to
> write
> a script that is way beyond my knowledge so far.
>
> I need to change the service "Remote Procedure Call" to log in with local
> system account.
>
> Is there an easy way to do this in powershell?
> I have a list workstations.txt I can call to run WMI against but I do not
> know the command to change the value.
> Thanks for any help
>


My System SpecsSystem Spec
Old 05-15-2007   #3 (permalink)
Brandon Shell
Guest


 

Re: Help with script on service

OMG... I searched my own site and came up with.
http://mow001.blogspot.com/2005/12/p...meters-to.html

This should do it for you.

"Brandon Shell" <tshell.mask@gmail.com> wrote in message
news:%23NDKmvwlHHA.1624@TK2MSFTNGP02.phx.gbl...
> To be completely honest with you... what you are asking for AFAICT should
> be strait forward... I was actually ready just to post the code, but
> alas... I cannot find a method to do what your want with .NET or WMI...
> Actually that is not entirely accurate... I found a way to set the value
> with WMI, but it does not commit to the actual service just the object. I
> am sure there is a way to do it, but I would just use sc.exe and save your
> self the time.
>
> example or something similar:
> $cmd = "sc.exe \\$server config $service obj= `"user`" password=
> `"password`""
> invoke-expression $cmd
>
> Here is an article to help.
> http://support.microsoft.com/kb/166819
>
> p.s. If anyone else has got this work using native Powershell.. I would
> love to know how.
>
> "Damon" <Damon@discussions.microsoft.com> wrote in message
> news:66770754-90A2-47A8-B068-D5863CA0CE23@microsoft.com...
>> Hey all,
>> I have been playing with powershell for a few weeks now but I need to
>> write
>> a script that is way beyond my knowledge so far.
>>
>> I need to change the service "Remote Procedure Call" to log in with local
>> system account.
>>
>> Is there an easy way to do this in powershell?
>> I have a list workstations.txt I can call to run WMI against but I do not
>> know the command to change the value.
>> Thanks for any help
>>

>


My System SpecsSystem Spec
Old 05-15-2007   #4 (permalink)
Brandon Shell
Guest


 

Re: Help with script on service

Here is a function that should help (Password can be null for built-in
accounts like LocalSystem and NetworkService)

function Change-ServicePassword{
Param([string]$server,[string]$service,[string]$user,[string]$password)

# Setup for WMI
$class = "Win32_Service"
$method = "change"
$computer = $server
$filter = "Name=`'$service`'"

# Getting Service Via WMI
$MyService = get-WmiObject $class -computer $computer -filter $filter

# Setting Parameters for Change Method
$inparams = $MyService.psbase.GetMethodParameters($method)
$inparams["StartName"] = $user
$inparams["StartPassword"] = $password

# Calling Change Method and Return $results
$result = $MyService.psbase.InvokeMethod($method,$inparams,$null)
$result.ReturnValue
}



"Brandon Shell" <tshell.mask@gmail.com> wrote in message
news:%23NDKmvwlHHA.1624@TK2MSFTNGP02.phx.gbl...
> To be completely honest with you... what you are asking for AFAICT should
> be strait forward... I was actually ready just to post the code, but
> alas... I cannot find a method to do what your want with .NET or WMI...
> Actually that is not entirely accurate... I found a way to set the value
> with WMI, but it does not commit to the actual service just the object. I
> am sure there is a way to do it, but I would just use sc.exe and save your
> self the time.
>
> example or something similar:
> $cmd = "sc.exe \\$server config $service obj= `"user`" password=
> `"password`""
> invoke-expression $cmd
>
> Here is an article to help.
> http://support.microsoft.com/kb/166819
>
> p.s. If anyone else has got this work using native Powershell.. I would
> love to know how.
>
> "Damon" <Damon@discussions.microsoft.com> wrote in message
> news:66770754-90A2-47A8-B068-D5863CA0CE23@microsoft.com...
>> Hey all,
>> I have been playing with powershell for a few weeks now but I need to
>> write
>> a script that is way beyond my knowledge so far.
>>
>> I need to change the service "Remote Procedure Call" to log in with local
>> system account.
>>
>> Is there an easy way to do this in powershell?
>> I have a list workstations.txt I can call to run WMI against but I do not
>> know the command to change the value.
>> Thanks for any help
>>

>


My System SpecsSystem Spec
Old 05-15-2007   #5 (permalink)
Don Jones [MVP]
Guest


 

Re: Help with script on service

Query the Win32_Service class from WMI and use its Change() method.

--
Don Jones
Windows PowerShell MVP
Founder: www.ScriptingAnswers.com
Co-Author: "Windows PowerShell: TFM"

"Damon" <Damon@discussions.microsoft.com> wrote in message
news:66770754-90A2-47A8-B068-D5863CA0CE23@microsoft.com...
> Hey all,
> I have been playing with powershell for a few weeks now but I need to
> write
> a script that is way beyond my knowledge so far.
>
> I need to change the service "Remote Procedure Call" to log in with local
> system account.
>
> Is there an easy way to do this in powershell?
> I have a list workstations.txt I can call to run WMI against but I do not
> know the command to change the value.
> Thanks for any help
>


My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can a Windows Service run a visual basic script? David .NET General 2 03-26-2008 07:04 AM
Script that emails out a service failure notification Ian_1 PowerShell 8 10-24-2007 10:08 PM
script as a service lonervamp PowerShell 6 10-16-2007 07:47 AM
Script Host Client launched from Windows Service DavidRF Vista security 4 06-27-2007 04:01 PM
Powershell Script as Windows Service tobias.kuhn@gmail.com PowerShell 5 02-08-2007 12:00 PM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51