Solved

how to let my pc start and shut down automatic....

Posted on 2002-07-06
34
372 Views
Last Modified: 2010-04-13
os is win 2k,
i want my pc start at time A and shut down at time B. who can help me??
0
Comment
Question by:phiton
  • 15
  • 8
  • 7
  • +3
34 Comments
 
LVL 44

Expert Comment

by:CrazyOne
ID: 7133970
Well you can schedule a shutdown using a script and the task scheduler. But you can't within the OS schedule when the machine will restart. I am unaware of any BIOS settings that have a setting to schedule starting the machine although maybe the newer BIOS's have a setting like this. The only thing I can think of is using physical clock timer with the machine plugged into it and the time set to the time you want to turn on the machine. Of course doing this could raise other issues and problems.


The Crazy One
0
 
LVL 8

Expert Comment

by:steinmto
ID: 7135537
I know that Dell computers have setting in the bios to turn them on and off.  

Tom
0
 
LVL 7

Expert Comment

by:jmiller47
ID: 7136899
What kind of computer / motherboard do you have?
0
 

Author Comment

by:phiton
ID: 7136929
p2 400 gigabyte motherboard 6bxe..quite old....
os is win 2k
0
 
LVL 7

Expert Comment

by:jmiller47
ID: 7136951
You probably will not have the ability in your BIOS to select an autostartup time. You can look though at the options in the BIOS
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 7136952
Unfortunately it doesn't look like you are going to be able to do it through the BIOS.
0
 

Author Comment

by:phiton
ID: 7136959
then how, what can i do???
0
 

Author Comment

by:phiton
ID: 7136966
can anyone tell me how to write the shutdown script??i need more details...

thx
0
 

Author Comment

by:phiton
ID: 7136976
crazyone ,can you help me to write the script....if I am able to shutdown my pc auto, i will accept your comments as answer...can?? thank you very much
0
 
LVL 7

Expert Comment

by:jmiller47
ID: 7136979
If you have the Windows 2000 Resource kit it's easy. Do you have the Resource Kit?
0
 

Author Comment

by:phiton
ID: 7136983
i dont have it...how??
0
 

Author Comment

by:phiton
ID: 7136985
can do it for me? jmiller47 i am waiting for you answer now.......
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 7137004
I don't really do scripting mainly because I use Delphi as my language of choice so I am bit rusty on VB. I write full applications and services (exe's, dll's, ocx's etc). I do have an application that initiates a shutdown. The problem is that I don't have a Web site to upload to so it can be downloaded. EE frowns on experts emailing solutions because the solution needs to be available to all who uses the site. If someone was willing to allow me to use their site to give the application a somewhat of a permanent home I would be glad to do that way.
0
 

Author Comment

by:phiton
ID: 7137017
is it very complicated to write the script? can u teach me or just tell me the link where i can find ..
0
 

Author Comment

by:phiton
ID: 7137020
or tell me some reference i can read and learn by myself..i know c,  vc a little....
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 7137045
Well for know (got to get some sleep) the best I can do is to post the raw code I have written in Delphi. Since you know C you should be able to decipher this and it is mainly Windows API's involved.

unit ShutDown;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  rl: Cardinal;
  hToken: Cardinal;
  tkp: TOKEN_PRIVILEGES;

begin
  if not OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,
  hToken) then
    ShowMessage('Cannot open process token.')
  else begin
    if LookupPrivilegeValue(nil, 'SeShutdownPrivilege', tkp.Privileges[0].Luid) then begin
      tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
      tkp.PrivilegeCount           := 1;
      AdjustTokenPrivileges(hToken, False, tkp, 0, nil, rl);
      if GetLastError <> ERROR_SUCCESS then
        ShowMessage('Error adjusting process privileges.');
    end
    else
      ShowMessage('Cannot find privilege value.');
  end;

  InitiateSystemShutdown(nil, nil, 10, True, False);

end;

end.
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 7137046
I got to go to bed but I will be back later. :>)
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:phiton
ID: 7137051
thx..i will try my best..
0
 

Author Comment

by:phiton
ID: 7137056
wah..i cant understand this la....too much different from C and VC...I still need help..

to crazyone....have a nice sleep....
0
 
LVL 7

Expert Comment

by:jmiller47
ID: 7138456
You can use the Shutdown tool from the MS Windows 2000 Resource Kit. The file you need is located here:
http://www.pc-pipeline.com/files/SHUTDOWN.EXE

The syntax is as follows:

Usage: SHUTDOWN [/?][\\Computer][/A][/R][/T:xx]["MSG][/C]

SHUTDOWN with no parameters brings up the GUI.

/?           Shows the Help Dialog
\\Computer   Specifies a remote computer to shut down.
/A           Aborts a system shutdown. Note, this is only possible during the timeout period. If this switch is used, all others are ignored.
/L           Specifies the local computer. Note, if you use this parameter, all others are ignored.
/R           Specifies that the computer should reboot after shutdown.
/T:xx        Sets the timers for System Shutdown in seconds. [30 sec. default]
"Msg]        Specifies additional message. [max. 127 characters]
/C           Forces running applications to close.



Place this file on your hard drive and call it using Scheduled tasks in control panel. Make sure to use the /L parameter.

I hope this helps.
0
 

Author Comment

by:phiton
ID: 7140798
hi, i have downloaded the file and put it in schedule task already. however it doesnt work.  how to use the syntax, where to write the syntax .....
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 7142427
phiton
I think the problem is with the task scheduler. I tested both the shutdown.exe and my program. Both don't fully shutdown the machine. Instead when running it from the scheduler they both throw a message stating "It is ok to safely shutdown the computer".
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 7142484
Well I found out why it doesn't directily shutdown the machine. I changed this line in my code

InitiateSystemShutdown(nil, nil, 10, True, False);
to
ExitWindowsEx(EWX_FORCE + EWX_POWEROFF, 0);

And this change does turn off the machine. I susupect Shutdown.exe is using the InitiateSystemShutdown API which if it is then that is the cause for it not turning off the machine.
0
 
LVL 7

Expert Comment

by:jmiller47
ID: 7142653
This vbs script will power off the computer

Set colOperatingSystems = GetObject("winmgmts:{(Shutdown)}").ExecQuery("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
   ObjOperatingSystem.Win32Shutdown(8)
Next

This direct command will power it off also.

%windir%\System32\rundll32.exe shell32.dll,SHExitWindowsEx 8

Notic the 8 at the end. This means power off.

0 preform logoff
1 shutdown
4 forced shutdown (don't allow to save)
8 powers down the machine

This was from an article worth reading on www.winnetmag.com if you have a subscription that is.

http://www.winnetmag.com/Articles/Index.cfm?ArticleID=25339&

Here is a snipet:

1. Automatically log off a user or shut down your machine. You can incorporate Rundll32 into your Windows Script Host (WSH) or command-shell scripts to log off the current user or shut down and restart the computer. The value in the command's last parameter controls the action that will occur: 0 performs a logoff, 1 performs a shutdown, 2 performs a reboot, 4 performs a forced shutdown, and 8 powers down the machine. The following example performs a logoff:

rundll32.exe shell32.dll,
SHExitWindowsEx 0
0
 
LVL 7

Expert Comment

by:jmiller47
ID: 7142657
The first vbs script is found in the new Technet catagory "Technet Script Center" under Computer Management

http://www.microsoft.com/technet/scriptcenter/default.asp
0
 

Author Comment

by:phiton
ID: 7142726
ok, i need to install VB to test your code, so there need sometime for me to try......and for dephi code, cos i didn't understand it very much...i am sorry....i wont test it...if i have any problem i will contact you again..wait for my result..thx...
0
 

Author Comment

by:phiton
ID: 7142763
wah...it really works...thank you very much. this is my first time to run vb scripts...so i think i make stupid mistake in above comments, there is not need install VB.....thank you all very much.....as crazyone said, when i run the script, it will promt a window stated "It is ok to safely shutdown the computer"
how to avoid this message when i use the vb script?? any way....i think i almost find the answer, this is the last part i want to know.

by the way to crazyone, how to run your code? in what environment? i am not from computer science, instead,i am from RF and communication division....
0
 
LVL 7

Accepted Solution

by:
jmiller47 earned 100 total points
ID: 7143035
phiton, I'm not sure if you have this working yet or not by your last message but if not, you can try this.

Create a new text document on your desktop.

Rename it to shutdown.vbs

Right-click on it and choose edit.

Copy and paste the following code into the document and save it.

Set colOperatingSystems = GetObject("winmgmts:{(Shutdown)}").ExecQuery("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
  ObjOperatingSystem.Win32Shutdown(8)
Next

You can now schedule shutdown.vbs to run whenever you want.

This should when run close everything, shut down, and power off. Although, if CrazyOne's suggestion works, please give him the points.

I hope this helps
0
 

Author Comment

by:phiton
ID: 7143059
thanks a lot to jmiller47, as well as crazyone...now i can schedule to shut down my pc, thx very much....
0
 
LVL 7

Expert Comment

by:jmiller47
ID: 7143077
When you upgrade your computer, your BIOS hopefully will allow a timed power on...
0
 

Expert Comment

by:stewsterl
ID: 7563236
phiton,

Just write a windows service.... Services run whether someone is logged in or not.
0
 
LVL 1

Expert Comment

by:blazeking
ID: 8606481
yes thank you to everyone for helping phiton, it helped me too!

i can shutdown my computer via a scheduled .vbs

but is there a .vbs that will restart it?
0
 

Author Comment

by:phiton
ID: 8606951
hi, blazeking, that is highly depend on your BIOS property....
0
 
LVL 1

Expert Comment

by:blazeking
ID: 8607629
thanks for the rapid response phiton...              but i did some more searching...

i found that changing the shutdown variable allowed me to do more than just power off:

Value         Meaning
0                Log Off
0 + 4          Forced Log Off
1                Shutdown
1 + 4          Forced Shutdown
2                Reboot
2 + 4          Forced Reboot
8                Power Off
8 + 4          Forced Power Off

So, the "8" value in the following:  

Set colOperatingSystems = GetObject("winmgmts:{(Shutdown)}").ExecQuery("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
 ObjOperatingSystem.Win32Shutdown(8)
Next

"8" forces a shutdown.  "2" initiates a reboot.

Again thank you to everyone here!!  Copy and paste does wonders.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Moving applications to the cloud or switching services to cloud-based ones, is a stressful job.  Here's how you can make it easier.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now