phiton
asked on
how to let my pc start and shut down automatic....
os is win 2k,
i want my pc start at time A and shut down at time B. who can help me??
i want my pc start at time A and shut down at time B. who can help me??
I know that Dell computers have setting in the bios to turn them on and off.
Tom
Tom
What kind of computer / motherboard do you have?
ASKER
p2 400 gigabyte motherboard 6bxe..quite old....
os is win 2k
os is win 2k
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
Unfortunately it doesn't look like you are going to be able to do it through the BIOS.
ASKER
then how, what can i do???
ASKER
can anyone tell me how to write the shutdown script??i need more details...
thx
thx
ASKER
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
If you have the Windows 2000 Resource kit it's easy. Do you have the Resource Kit?
ASKER
i dont have it...how??
ASKER
can do it for me? jmiller47 i am waiting for you answer now.......
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.
ASKER
is it very complicated to write the script? can u teach me or just tell me the link where i can find ..
ASKER
or tell me some reference i can read and learn by myself..i know c, vc a little....
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(GetCurren tProcess, 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].Attribut es := SE_PRIVILEGE_ENABLED;
tkp.PrivilegeCount := 1;
AdjustTokenPrivileges(hTok en, 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.
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
var
rl: Cardinal;
hToken: Cardinal;
tkp: TOKEN_PRIVILEGES;
begin
if not OpenProcessToken(GetCurren
hToken) then
ShowMessage('Cannot open process token.')
else begin
if LookupPrivilegeValue(nil, 'SeShutdownPrivilege', tkp.Privileges[0].Luid) then begin
tkp.Privileges[0].Attribut
tkp.PrivilegeCount := 1;
AdjustTokenPrivileges(hTok
if GetLastError <> ERROR_SUCCESS then
ShowMessage('Error adjusting process privileges.');
end
else
ShowMessage('Cannot find privilege value.');
end;
InitiateSystemShutdown(nil
end;
end.
I got to go to bed but I will be back later. :>)
ASKER
thx..i will try my best..
ASKER
wah..i cant understand this la....too much different from C and VC...I still need help..
to crazyone....have a nice sleep....
to crazyone....have a nice sleep....
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.
http://www.pc-pipeline.com/files/SHUTDOWN.EXE
The syntax is as follows:
Usage: SHUTDOWN [/?][\\Computer][/A][/R][/
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.
ASKER
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 .....
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".
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".
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.
InitiateSystemShutdown(nil
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.
This vbs script will power off the computer
Set colOperatingSystems = GetObject("winmgmts:{(Shut down)}").E xecQuery(" Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Win32Sh utdown(8)
Next
This direct command will power it off also.
%windir%\System32\rundll32 .exe shell32.dll,SHExitWindowsE x 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
Set colOperatingSystems = GetObject("winmgmts:{(Shut
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Win32Sh
Next
This direct command will power it off also.
%windir%\System32\rundll32
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
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
http://www.microsoft.com/technet/scriptcenter/default.asp
ASKER
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...
ASKER
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....
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....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks a lot to jmiller47, as well as crazyone...now i can schedule to shut down my pc, thx very much....
When you upgrade your computer, your BIOS hopefully will allow a timed power on...
phiton,
Just write a windows service.... Services run whether someone is logged in or not.
Just write a windows service.... Services run whether someone is logged in or not.
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?
i can shutdown my computer via a scheduled .vbs
but is there a .vbs that will restart it?
ASKER
hi, blazeking, that is highly depend on your BIOS property....
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:{(Shut down)}").E xecQuery(" Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Win32Sh utdown(8)
Next
"8" forces a shutdown. "2" initiates a reboot.
Again thank you to everyone here!! Copy and paste does wonders.
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:{(Shut
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Win32Sh
Next
"8" forces a shutdown. "2" initiates a reboot.
Again thank you to everyone here!! Copy and paste does wonders.
The Crazy One