Solved

Using powercfg with vbscript

Posted on 2007-12-06
7
5,632 Views
Last Modified: 2012-08-14
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?

cheers
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
 

wscript.quit

Open in new window

0
Comment
Question by:Manfredtoo
  • 4
  • 2
7 Comments
 
LVL 30

Assisted Solution

by:SteveGTR
SteveGTR earned 50 total points
ID: 20421087
Use the /c switch:

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

0
 

Author Comment

by:Manfredtoo
ID: 20421284
thanks steve got it =)
0
 

Author Comment

by:Manfredtoo
ID: 20421411
steve: i tried again, it shows me error: expected end of statement.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 12

Accepted Solution

by:
chandru_sol earned 450 total points
ID: 20421466
Hope this will help

regards
Chandru
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)

next
 

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

0
 

Author Comment

by:Manfredtoo
ID: 20421517
chandru: it works great =) thanks alot. hey been seeing u helping me quite a few times. really appreciate it
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20421538
Glad i was of help! No worries

cheers
Chandru
0
 

Author Closing Comment

by:Manfredtoo
ID: 31413189
powercfg with vbs
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now