There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
DOS/Other
Tag Cloud
access acer asus bios bsod computer crash driver drivers error ethernet excel freeze gaming google gpu hard drive hardware hdmi internet laptop malware memory missing monitor motherboard network operating system printer problem ram registry router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > DOS/Other >
Solved: powercfg - missing operand? huh

Reply  
Thread Tools
scrfix's Avatar
Computer Specs
Member with 337 posts.
 
Join Date: May 2009
Experience: Computer Repair Expert
28-Jun-2009, 04:20 AM #1
Solved: powercfg - missing operand? huh
Code:
@echo off
For /F "Tokens=*" %%A In ('powercfg -getactivescheme^|Findstr /I /C:": "') Do Set /A _ActiveScheme=%%B
powercfg -SETACVALUEINDEX %_ActiveScheme% SUB_NONE CONSOLELOCK 0
powercfg -SETDCVALUEINDEX %_ActiveScheme% SUB_NONE CONSOLELOCK 0
The code:
Code:
'powercfg -getactivescheme
returns to me: Power Scheme GUID: 49ef8fc0-bb7f-488e-b6a0-f1fc77ec649b (Dell Recommended)

This will be different for every computer. All I want is the: 49ef8fc0-bb7f-488e-b6a0-f1fc77ec649b

I thought the above code says to run the command powercfg -getactivescheme, look at everything that is returned to me and then find the string ": " within what is returned and then take the item directly after that and store it into a variable which would be the above however it returns back to me missing operand. Huh?

I am going to try the skip option Jerry showed me yesterday but am I overthinking this?
Am I writing this incorrectly?
Why is this not working?

Thanks,
__________________
Wayne Leiser, Spectacular Computer Repair Computer Repair, Computer Services
World Famous Gift Baskets: Gift Baskets
Resources LLC: Water Treatment Coagulation, Water Recycling
TheOutcaste's Avatar
Computer Specs
Distinguished Member with 9,048 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
28-Jun-2009, 09:52 AM #2
Tokens=* means it will only get one token, %%A. This will be the entire line as you've not specified any delimiters.
There will never be a %%B value with these options.
Also, the /A switch for Set means Set will deal with the data as a number. If it's a text string, the variable will be set to 0.
A GUID is a Hexadecimal number, and Hex numbers must start with 0x or you'll get an error that it's not a valid number.
If it's mixed text and numbers, and has any math symbols, you can get unexpected results, or errors like missing operand or divide by zero.
In this case, since %%B doesn't exist, the variable is not defined.

Use this instead:
Code:
 For /F "Tokens=4 Delims=: " %%A In ('powercfg -getactivescheme') Do Set _ActiveScheme=%%A
The powercfg -getactivescheme command only generates one line of output, so Findstr isn't needed to select one line out of many.
This uses space and : as delimiters, so the line will be parsed like this (I added the equals sign, it's not part of the output):
  1. =Power
  2. =Scheme
  3. =GUID
  4. =49ef8fc0-bb7f-488e-b6a0-f1fc77ec649b
  5. =(Dell
  6. =Recommended)
You want # 4, so specify Tokens=4
If you just use : as a delimiter, you'll get this:
  1. =Power Scheme GUID
  2. = 49ef8fc0-bb7f-488e-b6a0-f1fc77ec649b (Dell Recommended)
Note the leading space on the GUID. This might cause problems depending on what you are doing with the value, plus you have to remove the text after the GUID.

EDIT: Correction, using just : parses the line into just two parts, not three

Jerry
__________________
Microsoft MVP - Windows Expert - Consumer
Of course I know all the answers ; I just don't always match the answers to the right questions


Last edited by TheOutcaste; 28-Jun-2009 at 02:22 PM.. Reason: Correction
Squashman's Avatar
Trusted Advisor with 18,706 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
28-Jun-2009, 12:27 PM #3
I see that is a Vista only option.
What are you using this batch file for?
scrfix's Avatar
Computer Specs
Member with 337 posts.
 
Join Date: May 2009
Experience: Computer Repair Expert
28-Jun-2009, 02:03 PM #4
Jerry,

Utilizing that batch, it says : was unexpected at this time.

Squashman,

I am utilizing it to turn on or off the password option for that screen.
I already know how t o perform this in XP. In Vista however I need the active profile name in order to accomplish this task.
__________________
Wayne Leiser, Spectacular Computer Repair Computer Repair, Computer Services
World Famous Gift Baskets: Gift Baskets
Resources LLC: Water Treatment Coagulation, Water Recycling
TheOutcaste's Avatar
Computer Specs
Distinguished Member with 9,048 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
28-Jun-2009, 02:22 PM #5
Opps, I swapped the order of the delims when I typed it. That's what I get for not copying and pasting. If you want a space as a delimiter, it has to be last, so that should be "Tokens=4 Delims=: ". I'll correct it above.
scrfix's Avatar
Computer Specs
Member with 337 posts.
 
Join Date: May 2009
Experience: Computer Repair Expert
28-Jun-2009, 05:10 PM #6
I actually took out the Delims= :" and it worked perfectly. I found that out while my wife was driving so this is the first chance I have had to report it.

The code below works perfectly without spaces.

To anybody utilizing this code. The below is ONLY compatible with Vista and possibly Windows 7. It has not been tested with Windows 7 but since that is just an upgrade to Vista I am sure it will work.

Code:
For /F "Tokens=4 Delims= " %%A In ('powercfg -getactivescheme') Do Set _ActiveScheme=%%A
__________________
Wayne Leiser, Spectacular Computer Repair Computer Repair, Computer Services
World Famous Gift Baskets: Gift Baskets
Resources LLC: Water Treatment Coagulation, Water Recycling
TheOutcaste's Avatar
Computer Specs
Distinguished Member with 9,048 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
28-Jun-2009, 05:25 PM #7
True. Without the colon as a delimiter, it becomes part of the GUID token. Removing the Delims= part completely means it will use the defaults of tab and space, so you can leave it out or specify the space. Some commands do use a tab in their output (at least they used to) so that can sometimes affect how the line is parsed. Can't tell from the Command Prompt if a tab was used.
__________________
Microsoft MVP - Windows Expert - Consumer
Of course I know all the answers ; I just don't always match the answers to the right questions

scrfix's Avatar
Computer Specs
Member with 337 posts.
 
Join Date: May 2009
Experience: Computer Repair Expert
28-Jun-2009, 05:29 PM #8
That's a good point.

I can set powercfg -getactivescheme>power.txt or something to the similar and check it that way.

They are all spaces, at least in Vista. I have not tested Win 7.
scrfix's Avatar
Computer Specs
Member with 337 posts.
 
Join Date: May 2009
Experience: Computer Repair Expert
13-Jul-2009, 12:52 PM #9
Marked this unsolved only because I have another question on this. I am utilizing an IF statement to tell what OS I am on, Vista or XP. The FOR statement I would like to put within the IF statement however it keeps telling me invalid parameters.

The code for turning controlling the item below is different on both XP and Vista.

The code with all of the extras removed not to confuse the situation here looks something to the following:

Code:
If %OS% == Vista (
For /F "Tokens=4 Delims= " %%A In ('powercfg -getactivescheme') Do Set _ActiveScheme=%%A
powercfg -SETACVALUEINDEX %_ActiveScheme% SUB_NONE CONSOLELOCK 0
powercfg -SETDCVALUEINDEX %_ActiveScheme% SUB_NONE CONSOLELOCK 0
Goto _Wherever
)
The vista code is giving me the errors because of the FOR statement. Is there something that I need to add or is it a physical impossiblity that a FOR statment can go within an IF statment?

Thanks,
__________________
Wayne Leiser, Spectacular Computer Repair Computer Repair, Computer Services
World Famous Gift Baskets: Gift Baskets
Resources LLC: Water Treatment Coagulation, Water Recycling
scrfix's Avatar
Computer Specs
Member with 337 posts.
 
Join Date: May 2009
Experience: Computer Repair Expert
14-Jul-2009, 04:06 AM #10
I figured out a different way of accomplishing this. I put the FOR statement under a different label and then just sent it there. After the IF statement I put a second label skipping over the FOR statement in case the IF statement was false.

This works.
TheOutcaste's Avatar
Computer Specs
Distinguished Member with 9,048 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
14-Jul-2009, 03:53 PM #11
You need to use Delayed Expansion. Remember, the If statement is one long line, so when variables are expanded for the line, _ActiveScheme has not yet been set by the For loop.
Your powercfg command is missing the _ActiveScheme parameter because of that, so the command becomes this:

Code:
powercfg -SETACVALUEINDEX    SUB_NONE CONSOLELOCK 0
This will work:
Code:
SetLocal EnableDelayedExpansion
If %OS% == Vista (
For /F "Tokens=4 Delims= " %%A In ('powercfg -getactivescheme') Do Set _ActiveScheme=%%A
powercfg -SETACVALUEINDEX !_ActiveScheme! SUB_NONE CONSOLELOCK 0
powercfg -SETDCVALUEINDEX !_ActiveScheme! SUB_NONE CONSOLELOCK 0
Goto _Wherever
)
__________________
Microsoft MVP - Windows Expert - Consumer
Of course I know all the answers ; I just don't always match the answers to the right questions

Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 09:50 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.