Solved

Problem with Shutdown command over batch file

Posted on 2011-03-02
10
2,031 Views
Last Modified: 2012-06-21
Hi all, im using the software (winpower) that came with an UPS  (forza SL-51)  to manage the events when the power suply AC fails, what im trying to do is to run a batch file when defined time is out to turn of a remote computer using shutdown command, the software gives this option  Config dialog and the batch file halt.bat  Batch file , the problem comes when time over the and the batch file execute nothing happend and return this message on the log.txt  error message on log.txt, i already check that the user name runing the winpower has the same username with administrative permition to shutdown the remote computer, in fact if i run the command over cmd it works.

Any ideas=?
thanks in advance.
0
Comment
Question by:Marck911
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 16

Expert Comment

by:sjklein42
ID: 35020936
I am concerned about the

>log.txt

in your batch file.

It assumes a working directory that you can write into.

It is not clear what the working directory of this batch job will be when it executes.

Try using

shutdown.exe -m \\pcname -f -s -t 30>c:\log.txt

Open in new window


or whereever you want the log file to go explicitly


0
 
LVL 4

Author Comment

by:Marck911
ID: 35020985
the write directory its the same of shutdown command and it works,
i tryed and same result,
thanks for the quick response
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 35021105
Here's another place to look for shutdown privileges:

Start/Run --> gpedit.msc

Go to
Computer Configuration\Windows Settings\Security Settings
\Local Policies\User Rights Assignment\

Double click on "Shut down the system"

Verify that the following groups are listed:

Administrators
Backup Operators
Power Users
Users

Then do the same thing for

 "Force shutdown from a remote system"

and be sure Power Users and Administrators is in the list.  Users, too, just in case.


See this article for the discussion leading to this suggestion:

http://www.pcreview.co.uk/forums/shutdown-exe-doesnt-run-due-lack-privileges-t179004.html

0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 69

Assisted Solution

by:Qlemo
Qlemo earned 50 total points
ID: 35021148
Obviously (since the batch file runs when called manually) the batch is not called as the correct user. Try to provide user and password in the shutdown command.
0
 
LVL 23

Expert Comment

by:Danny Child
ID: 35021211
I'd also consider looking at the PSshutdown tool from WinInternals (who Microsoft liked so much, they bought them...)

http://technet.microsoft.com/en-us/sysinternals/bb897541

very similar in a lot of ways, but more robust.

Do you know what context the application is running in?  It may not have the same permissions that you do...
You can explicitly add login details to the command line, but it's a hideous security breach to leave your login and password in plain text forever.  Might be handy for the troubleshooting though.  
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 35021486
Adding credentials in the batch was suggested for troubleshooting only, of course.
0
 
LVL 4

Author Comment

by:Marck911
ID: 35022667
Thankyou all, I'll test and post the result tomorrow...
0
 
LVL 4

Author Comment

by:Marck911
ID: 35028452
guys I tryed with the domain controller user using this command:
psshutdown.exe \\pcname -u USER -p PASS -k -t 100 -m " Shutting Down..." 1>output.log 2>error.log
and again return message was: Access Denied.
I ran the command manually and it works.
If i set the winpower to launch batch file with the above command-> Access Denied.
If i set the winpower to launch the command directly -> Access Denied.

also I tryed sjklein42's idea with gpedit.msc and added two different users and notting.

any ideas?
0
 
LVL 16

Accepted Solution

by:
sjklein42 earned 450 total points
ID: 35028792
Further investigation yields a little more insight:

I think the "process" that needs the privileges is actually the service that psshutdown creates and uses to do the shutdown.

PsShutdown extracts a Windows service executable to the system that it will control through that system's Admin$ share, starts the service, then sends the service a command that reflects the options you've specified. The service uninstalls after it completes the command.

http://www.windowsitpro.com/article/administration-tools2/psshutdown.aspx

The default account for services probably does not have remote shutdown rights (which is what is needed here, I believe).   Running it outside of a service would use your login; and thus could have remote shutdown rights.

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/59d3f312-eb4c-4878-a19b-e41e79757a5a/

Ordinarily, we could set the shutdown service "logon" properties, but psshutdown creates, starts and runs the service on the fly, when needed, so it becomes problematic settings a non-default account for it to run under.

I think we need to set privileges on the "Local Service" account.  For a discussion of Services permissions, see this:

http://technet.microsoft.com/en-us/library/cc782435(WS.10).aspx

And if that doesn't work,this article suggests an alternative using VB script to do the shutdown:

http://www.404techsupport.com/2008/12/04/restarting-without-admin-privileges/

0
 
LVL 4

Author Closing Comment

by:Marck911
ID: 35032843
Thanks to all, the right way was adding the user to the winpower service. because its based on java the javaw process started with the user with permition to turn off the remote computer.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

How can you create a game plan that lets you focus on special projects instead of running from cubicle to cubicle every day and feeling like you’ve accomplished nothing? Try these strategies for prioritizing your tasks, offloading what you can, and …
Not many admins are aware that GPOs can be activated and deactivated time-based. Time to change that :)
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 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