Solved

Window xp powercfg.exe script

Posted on 2014-04-07
9
884 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 500 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need to overwrite data when copy job is run 4 47
How can i echo a ! to end of a file? 8 23
Selecting Right Partition 6 68
BATCH to EXE Converter 2 35
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.
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

861 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