当前位置:主页>仓库管理软件> 列表

200分 求运行后自动重启计算机的程序代码(98 XP 2 找esale服装进销存

库存管理软件版1楼: 求运行后自动重启计算机的程序代码
要求在以下系统都可以使用 XP 2K 98
没有窗口! 运行后就重启电脑的

在线等候~~~~~

2楼: 学习! 如医药管理软件

3楼: 可以调用system32下的shotdown.exe文件
shellexecute(handle,''open'',''shutdown.exe'',pchar(sd),'''',sw_shownormal);
sd:=''/l'';//注销
sd:=''/r'';//重启
sd:=''/s'';//关机

4楼: icehome
朋友 可以将全部代码贴出来吗?(本人新手,菜的要命)

还有就是你这种方法能在98 ME XP 2K通用吗?

5楼: 应该是98,me一种方法
2000,xp,2003一种方法

具体方法用这里的全文检索就可以找到了

6楼: 简单的的就是:
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
shellexecute(handle,''open'',''shutdown.exe'',pchar(/r),'''',sw_shownormal);
end;
shotdown.exe最好放在一个文件夹里,可以COPY出来

库存管理软件版7楼: 可以在程序判断当前是什么操作系统的
不同的系统使用不同的方法

8楼: 大哥 你这个代码编译不了啊!

9楼: 没有在其他系统里试过,只是曾经看过并且试过。


还有很多方法的,网上都有的,不过实现起来有一定难度,有兴趣我可以给LZ代码的。

10楼: 头文件要加shellapi

11楼: 顶啊

12楼: 这是以前的帖子 有能看明白的 帮我解决一下吧



xuhao1 (2004-05-25 21:16:54)
函数原型如下:
BOOL ExitWindowsEx(UINT uFlags, DWORD dwReserved );
参数:
uFlags
指定关闭类型,可使用下列常量:
EWX_FORCE 强制关闭,不会询问应用程序是否可以关闭,可造成数据丢失
EWX_LOGOFF 注销当前用户
EWX_POWEROFF 关闭电源, 需要ATX电源支持
EWX_REBOOT 重新启动计算机,对于Windows NT: 必须有 SE_SHUTDOWN_NAME 的安全特权方可进行此项操作
EWX_SHUTDOWN 正常关闭,在关闭之前所有缓冲区的内容都能被安全的存盘,所有进程都将被停止。对于Windows NT: 必须有 SE_SHUTDOWN_NAME 的安全特权方可进行此项操作
dwReserved
保留;忽视这个参数。
返回值:
如果函数成功返回True(非0),否则返回False(0)。调用GetLastError.取得错误信息。
实例:
新建Project,在 Form1添加三个 Button1、Button2、Button3,分别将其Caption属性改为‘关闭’、‘重启’、‘注销’,并给每个 Button 增加OnClick事件,代码如下:


procedure TForm1.Button1Click(Sender: TObject);
begin
ExitWindowsEx(EWX_SHUTDOWN,0); //正常关闭
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
ExitWindowsEx(EWX_REBOOT,0); //重新启动计算机
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
ExitWindowsEx(EWX_ LOGOFF,0); //注销当前用户
end;








xuhao1 (2004-05-25 22:42:07)
function SetPrivilege(privilegeName: string; enable: boolean): boolean;
var tpPrev,
tp : TTokenPrivileges;
token : THandle;
dwRetLen : DWord;
begin
if GetOSVerInfo=''WIN_9X'' then
begin
result := True;
exit;
end;
result := False;
OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, token);
tp.PrivilegeCount := 1;
if LookupPrivilegeValue(nil, pchar(privilegeName), tp.Privileges[0].LUID) then
begin
if enable then
tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED

else
tp.Privileges[0].Attributes := 0;
dwRetLen := 0;
result := AdjustTokenPrivileges(token, False, tp, SizeOf(tpPrev), tpPrev, dwRetLen);
end;
CloseHandle(token);
if Result=False then ShowError(''你必须有''+privilegeName+''特权。'');
end;

//设置权限
SetPrivilege(''SeSHUTDOWNPrivilege'', true); 如客户关系管理软件

13楼: ddddddddddddd

库存管理软件版14楼: procedure operatecomputer(statue:longword);
Var
HToken: THandle;
Tkp: TOKEN_PRIVILEGES;
ReturnLength : DWord;
begin
If (not OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES
or TOKEN_ALL_ACCESS or TOKEN_QUERY, hToken))then
begin
Application.Terminate;
end;
LookupPrivilegeValue(nil,''SeShutdownPrivilege'',tkp.Privileges[0].Luid);
Tkp.PrivilegeCount := 1;
Tkp.Privileges[0].Attributes :=SE_PRIVILEGE_ENABLED;
ReturnLength :=0;
AdjustTokenPrivileges(hToken, FALSE, tkp, 0,nil,ReturnLength);
if (GetLastError() <> ERROR_SUCCESS) then
begin
Application.Terminate;
end;
If (not ExitWindowsEx(statue, 0)) then
begin
Application.Terminate;
end;
end;

Function KillTask(ExeFileName: string): integer;//killtask
const
PROCESS_TERMINATE = $0001;
var
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
result := 0;
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
while integer(ContinueLoop) <> 0 do
begin
if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =
UpperCase(ExeFileName))
or (UpperCase(FProcessEntry32.szExeFile) = UpperCase(ExeFileName))) then
Result := Integer(TerminateProcess(OpenProcess(
PROCESS_TERMINATE, BOOL(0),


FProcessEntry32.th32ProcessID), 0));
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
end;

Procedure C_logoff; //ewx_logoff 为注销
begin
if win32platform =ver_platform_win32_windows then
exitwindowsex(ewx_force+ewx_shutdown+ewx_poweroff,32);
if win32platform =ver_platform_win32_NT then
operatecomputer(ewx_logoff);
End;

Procedure C_poweroff; //ewx_poweroff 为关机
begin
if win32platform =ver_platform_win32_windows then
exitwindowsex(ewx_force+ewx_shutdown+ewx_poweroff,32);
if win32platform =ver_platform_win32_NT then
operatecomputer(ewx_poweroff);
end;

Procedure C_reboot; //ewx_reboot 为重启
begin
if win32platform =ver_platform_win32_windows then
exitwindowsex(ewx_force+ewx_shutdown+ewx_poweroff,32);
if win32platform =ver_platform_win32_NT then
operatecomputer(ewx_reboot);
end;

15楼: FProcessEntry32: TProcessEntry32;
编译到这里就停了 怎么回事? 我是新手 刚学的 大哥麻烦你帮忙解释啊

16楼: 自己顶吧

17楼: 分情况判断吧,98的话,用API(例子网上多得是)


NT以上都有 shutdown.exe
直接 winexec(''shutdown -r''); 了事。

18楼: 还是没有解决啊! 哪位大哥帮忙弄个完整点的代码啊! 没有窗口的 ! 运行后就重启电脑的!~~

19楼: 我还有90分 谁能解决了这个问题我都加上 拜托大虾出手帮一下吧! 我在线等

20楼: 留下信箱,我发示例给你。

库存管理软件版21楼: 我的信箱
mx8001@126.com

22楼: 大哥 发了吗? 我在线 如esale服装进销存

23楼: 555555555

24楼: 已发。

25楼: 谢谢你的代码啊!!!问题解决了!十分感谢!

26楼: 接受答案了.