Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using powercfg with vbscript

Posted on 2007-12-06
7
Medium Priority
?
5,791 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 30

Assisted Solution

by:SteveGTR
SteveGTR earned 200 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
Interactive Way of Training for the AWS CSA Exam

An interactive way of learning that will help you visualize core concepts so that you can be more effective when taking your AWS certification exam.  Built for students by a student to help them understand the concepts that they are being taught.

 
LVL 12

Accepted Solution

by:
chandru_sol earned 1800 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to count occurrences of each item in an array.

722 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