Solved

Window xp powercfg.exe script

Posted on 2014-04-07
9
868 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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 42

Expert Comment

by:Rob Jurd, EE MVE
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 42

Expert Comment

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

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

770 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