Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Window xp powercfg.exe script

Posted on 2014-04-07
9
Medium Priority
?
984 Views
Last Modified: 2014-04-30
Hi,
I've create a script which change power profile name and edit 5 minutes in turn off power monitor.this script i've configured in group policy.it working well on all user Active directory profile.

script is
@echo off
Powercfg.exe /CREATE "Power Saving"
Powercfg.exe /CHANGE "Power Saving" /monitor-timeout-ac-5
Powercfg.exe /SETACTIVE "Power Saving"
Hostname >> C:\Hostname.txt

Now the issue, i want to configure if else statement in it.
like:-if script work then it create a file in C: drive and print computer name & PASS msg in file.if suppose script not run in user profile then print computer name & Fail msg in file.

i hope you understand what i'm saying.

Thanks,
0
Comment
Question by:xeroxzerox
  • 3
  • 2
  • 2
9 Comments
 
LVL 13

Accepted Solution

by:
stergium earned 2000 total points
ID: 39982459
Hello.
to my understanding your problem can be solved with checking the error level after the last powercfg.exe
if %errorlevel% equ 1 (
echo " fail"  >> c:\hostname.txt
) else (
echo "pass" >> c:\hostname.txt
)
i hope that helps
0
 
LVL 6

Author Comment

by:xeroxzerox
ID: 39982478
Hi,

@echo off
Powercfg.exe /CREATE "Power Saving"
Powercfg.exe /CHANGE "Power Saving" /monitor-timeout-ac-5
Powercfg.exe /SETACTIVE "Power Saving"
if %errorlevel% equ 1 (
echo " fail"  >> c:\hostname.txt
) else (
echo "pass" >> c:\hostname.txt
)

I've execute this script but it unable to create file.
0
 
LVL 13

Expert Comment

by:stergium
ID: 39982486
that is a bit odd.
try ommiting the c:\ (for debugging purposes only) and feedback the results please.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 6

Author Comment

by:xeroxzerox
ID: 39982493
i'm unable to understand, you mean is
if %errorlevel% equ 3

but now i've change the errorlevel to 2
now file create in c drive and it print hostname and pass.i've check power setting in control panal.it fine.
Now if i run again this script,it should give me fail or print fail msg in file because setting already implemented before running this script.
but it print pass in both conditions.
0
 
LVL 43

Expert Comment

by:Rob
ID: 40025120
Now if i run again this script,it should give me fail or print fail msg in file because setting already implemented before running this script.
but it print pass in both conditions.

I can understand why you'd think this but it's not the case.  The script runs fine and POWERCFG is able to set the power config even if it is the same setting.  So as far as POWERCFG is concerned there is no error.

make sense?
0
 
LVL 6

Author Closing Comment

by:xeroxzerox
ID: 40031284
Thanks
0
 
LVL 43

Expert Comment

by:Rob
ID: 40031405
Can you clarify exactly what the solution is as you've accepted the first post.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

885 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