Using powercfg with vbscript

Hi Experts
i have a piece of code here need some help, i couldnt get it run smoothly. my objective is to set the power management option with vbs. is there anything wrong with my sytax?

Dim objShell:Set objShell=CreateObject("Wscript.Shell")
On Error Resume Next
With objShell
  .Run "cmd powercfg /setactive "Home/Office Desk""
  .Run "cmd powercfg /x "Home/Office Desk" /monitor-timeout-ac 0"
  .Run "cmd powercfg /x "Home/Office Desk" /monitor-timeout-dc 0"
  .Run "cmd powercfg /x "Home/Office Desk" /disk-timeout-ac 0"
  .Run "cmd powercfg /x "Home/Office Desk" /disk-timeout-dc 0"
  .Run "cmd powercfg /x "Home/Office Desk" /standby-timeout-ac 0"
  .Run "cmd powercfg /x "Home/Office Desk" /standby-timeout-dc 0"
  .Run "cmd powercfg /x "Home/Office Desk" /hibernate-timeout-ac 0"
  .Run "cmd powercfg /x "Home/Office Desk" /hibernate-timeout-dc 0"
End With

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Use the /c switch:

.Run "cmd /c powercfg /setactive "Home/Office Desk"

ManfredtooAuthor Commented:
thanks steve got it =)
ManfredtooAuthor Commented:
steve: i tried again, it shows me error: expected end of statement.
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

Hope this will help

Set oShell = CreateObject("Wscript.Shell")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
OS = LEFT(objOperatingSystem.Version,3)
If( UCase( Trim( OS ) ) = UCase( Trim( 5.1 ) ) ) Then
oShell.Run "powercfg.exe -change ""Home/Office Desk"" -monitor-timeout-ac 15", 0, True
oShell.Run "powercfg.exe -change ""Home/Office Desk"" -disk-timeout-ac 25", 0, True
oShell.Run "powercfg.exe -change ""Home/Office Desk"" -standby-timeout-ac 0", 0, True
oShell.Run "powercfg.exe -change ""Home/Office Desk"" -hibernate-timeout-ac 0", 0, True
oShell.Run "powercfg.exe -hibernate off", 0, True
oShell.Run "powercfg.exe -setactive ""Home/Office Desk""", 0, True
End If

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ManfredtooAuthor Commented:
chandru: it works great =) thanks alot. hey been seeing u helping me quite a few times. really appreciate it
Glad i was of help! No worries

ManfredtooAuthor Commented:
powercfg with vbs
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.