1.

Solve : Power Plan import windows 7?

Answer»

Hi,

I am trying to have my batch file import a customized power plan I created. The MACHINES will be windows 7 x64, but would like it to work with x86 also. Here's my batch so far:


@Echo OFF
powercfg -import "\\reagan\mis$\Standard Install\Win7 Configs\Files for Scripts\WonderGroup Desktop PowerPlan.pow"
pause


Now, the problem is 2 things:

1. UNC paths are not accepted
2. There's the actual power plan file to import (path seen in the batch file)

The question is, How do I reference the correct path within the batch file since I cannot use UNC paths? Thanks!
@Echo OFF
Pushd "\\reagan\mis$\Standard Install\Win7 Configs\Files for Scripts\"

powercfg -import "PowerPlan.pow"
pauseQuote from: Squashman on May 22, 2012, 07:20:50 PM

@Echo OFF
Pushd "\\reagan\mis$\Standard Install\Win7 Configs\Files for Scripts\"

powercfg -import "PowerPlan.pow"
pause

You know...., I wrote that up earlier but didn't end up even trying it because of this:
http://www.sevenforums.com/tutorials/75562-power-plans-export-import.html

This guide didn't have an option for just: powercfg -import "PowerPlan.pow"
For the record I almost tried that! I will try it and post back. Thanks!Z:\Standard Install\Win7 Configs\Files for Scripts>powercfg -import "WonderGroup Desktop PowerPlan.pow"
The file could not be found.

Yeah, it didn't work unfortunately. I even tried the file without quotes. I looked at the parameters with the help flag and it states that you MUST specify the actual path:
-IMPORT Imports all power settings from the specified file.

Usage: POWERCFG -IMPORT

Specify a fully-qualified path to a file generated by
using "PowerCfg -EXPORT parameter".

Any other ideas? Thanks for your help!Hmm, Powercfg must work differently on Windows 7. Windows XP says you need to use the /File switch to pull from an existing config file and it doesn't say anything about having to use the fullpath to the file name either. XP also uses slashes and not hyphens for the switches. I hate it when Microsoft keeps switching back and forth on that crap. They did that with FORFILES when Server 2003 came out.

Ever here of the %CD% variable!


C:\>pushd \\Server\volume\FTPTEMP

Z:\FTPTEMP>echo %CD%
Z:\FTPTEMPQuote from: Squashman on May 23, 2012, 08:25:10 AM
Hmm, Powercfg must work differently on Windows 7. Windows XP says you need to use the /File switch to pull from an existing config file and it doesn't say anything about having to use the fullpath to the file name either. XP also uses slashes and not hyphens for the switches. I hate it when Microsoft keeps switching back and forth on that crap. They did that with FORFILES when Server 2003 came out.

Ever here of the %CD% variable!


C:\>pushd \\Server\volume\FTPTEMP

Z:\FTPTEMP>echo %CD%
Z:\FTPTEMP

I'm not sure what you're getting at . How can I apply these commands to my batch?The %CD% variable is the full path to the CURRENT DIRECTORY you are in. You said you needed the full path to your Power Configuration file.Quote from: Squashman on May 23, 2012, 12:55:36 PM
The %CD% variable is the full path to the CURRENT DIRECTORY you are in. You said you needed the full path to your Power Configuration file.

Oh, I understand what you mean. I'm sorry, what I meant is I have the full path and it will never change... but the file path is located on a network drive so therefore I cannot include the path to the power plan file in the batch as indicated below:

@Echo OFF
powercfg -import "\\reagan\mis$\Standard Install\Win7 Configs\Files for Scripts\WonderGroup Desktop PowerPlan.pow"
pause

~And the batch that we tried (below) didn't work because it needs the full path to the file whilst using the import command:

@Echo OFF
Pushd "\\reagan\mis$\Standard Install\Win7 Configs\Files for Scripts\"

powercfg -import "WonderGroup Desktop PowerPlan.pow"
pause

I just need to import the "WonderGroup Desktop PowerPlan.pow" file using the powercfg -import command, but it doesn't work because it's a UNC path. I am not needing to Echo/Print/Show the path name in the batch file. I just need the batch file to import the file located on the UNC drive.

Got it? . I hope I clarified my question! HAHAH. You are not understanding what the Pushd command does and what the %CD% variable is.
The pushd command maps a drive letter to your unc path and then makes that drive letter and directory the current working directory!

Powercfg -import "%CD%\Wonder Group Desktop PowerPlan.Pow"

Do you see the light!Quote
The pushd command maps a drive letter to your unc path and then makes that drive letter and directory the current working directory!

Not quite. The pushd <directory> command puts the current directory on the stack and changes to the directory indicated. The companion command (popd) PULLS a directory entry from the stack using a last-in first-out (LIFO) method and makes that the current directory. Nothing is mapped. Pushd can be used to save the directory where the batch file originated, and popd can be used to restore it for the user. In between the batch file can change directories as needed without leaving the user lost in the directory structure.

I think it would be better to use the net use command to map the UNC to a regular drive:\path notation and go from there.

Code: [Select]net use Z: \\reagan\mis$
powercfg -import "Z:\Standard Install\Win7 Configs\Files for Scripts\WonderGroup Desktop PowerPlan.pow"
net use Z: /d

I know what PUSHD and POPD does, but trying to explain it to him for this exercise was becoming futile. I am trying to explain it to him in layman's terms so he understands because obviously he is not understanding.

I do this all the time in my scripts where a command will not accept a UNC path.

The only issue with using the NET USE command is that you cannot guarantee that DRIVE Letter is not already in USE unless you sit there and use a FOR LOOP to check what drive letters are already in use. PUSHD and the %CD% variable is the perfect solution for this problem.Thank you all for the help. I am no expert with CMD but I am familiar with the %CD% AND pushd/popd commands .

1. [Powercfg -import "%CD%\Wonder Group Desktop PowerPlan.Pow"] doesn't work as it throws an error (I tried it after your initial post)
2. net use could work, but as squashman notated - someone might have the drive z: already mapped

So, I'm still stuck

FYI:

C:\Users\cfash>pushd "\\reagan\mis$\Standard Install\Win7 Configs\Files for Scripts\"

Z:\Standard Install\Win7 Configs\Files for Scripts>powercfg -import "%CD%\WonderGroup Desktop PowerPlan.pow"
An UNEXPECTED error condition has occurred. Unable to perform operation. You m
ay not have permission to perform this operation.Well to make sure it really is not a Permissions issue, manually map a drive letter to that UNC path and then run the powercfg command. You should just be able to type all that at the cmd prompt without creating a batch file just to check if it is a permissions issue.

We can use the NET USE command, it will just add a lot of extra code to your script. You can tell NET USE to map to the next available drive letter and then we can rerun the NET USE command inside a FOR LOOP to find out what drive letter got mapped to that share.As suggested, you can use "NET USE" to obtain a drive letter:

Code: [Select]@Echo Off
for /f "tokens=1-2" %%a in ('net use * \\reagan\mis$ ^| find "is now connected to"') do set netDrive=%%b
powercfg -import "%netDrive%\Standard Install\Win7 Configs\Files for Scripts\WonderGroup Desktop PowerPlan.pow"
net use %netDrive% /d
Pause


Discussion

No Comment Found