难道这里真的没有人知道这个吗????真没高手吗???能回答的分马上送上 300分!!
难道这里真的没有人知道这个吗????真没高手吗???能回答的分马上送上 300分!!
楼主syalan(南瓜饼)2001-12-12 09:33:41 在 VB / 基础类 提问如何让WIN2K休眠(软关机,不是睡眠啊),随便什么方法都行,最好是调用API。 问题点数:0、回复次数:34Top
1 楼basey(千错万错都是我的错)回复于 2001-12-12 10:18:11 得分 0
很容易嘛,呵呵。等等先。Top
2 楼syalan(南瓜饼)回复于 2001-12-12 11:45:15 得分 0
我等到花儿也谢了Top
3 楼mmzxg(超级笨蛋)回复于 2001-12-12 11:53:07 得分 0
haha,还是等高手Top
4 楼NowCan(城市浪人)回复于 2001-12-12 13:07:30 得分 0
?Top
5 楼blow_jj(阿俊)回复于 2001-12-12 14:06:47 得分 0
sorry.i don"t know
Top
6 楼syalan(南瓜饼)回复于 2001-12-12 16:51:26 得分 0
up~Top
7 楼csdncb(iter)回复于 2001-12-12 19:28:43 得分 0
rundll32 直接调用相应的APITop
8 楼Arcan(Arcan)回复于 2001-12-12 21:29:04 得分 0
什么叫软关机,是不是就是win2000在关闭对话框中选择休眠的那种休眠?我不用API可以实现,虽然办法笨了一点。Top
9 楼Bardo(巴顿(永远只有一个))回复于 2001-12-12 21:51:47 得分 0
如果是关机:
Public Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Parameters
uFlags
Specifies the type of shutdown. This parameter must include one of the following values. Value Meaning
EWX_LOGOFF Shuts down all processes running in the security context of the process that called the ExitWindowsEx function. Then it logs the user off.
EWX_POWEROFF Shuts down the system and turns off the power. The system must support the power-off feature.
Windows NT/2000: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section.
EWX_REBOOT Shuts down the system and then restarts the system.
Windows NT/2000: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section.
EWX_SHUTDOWN Shuts down the system to a point at which it is safe to turn off the power. All file buffers have been flushed to disk, and all running processes have stopped.
Windows NT/2000: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section.
This parameter can optionally include the following values. Value Meaning
EWX_FORCE Forces processes to terminate. When this flag is set, the system does not send the WM_QUERYENDSESSION and WM_ENDSESSION messages. This can cause the applications to lose data. Therefore, you should only use this flag in an emergency.
EWX_FORCEIFHUNG Windows 2000: Forces processes to terminate if they do not respond to the WM_QUERYENDSESSION or WM_ENDSESSION message. This flag is ignored if EWX_FORCE is used.
Top
10 楼ssxc(星驰)回复于 2001-12-12 21:58:28 得分 0
显示属性-屏幕保护程序-电源-休眠-还需要什么?Top
11 楼syalan(南瓜饼)回复于 2001-12-13 09:13:10 得分 0
to csdncb(csdncai),Arcan(Arcan)
请说的详细点好吗?Top
12 楼syalan(南瓜饼)回复于 2001-12-13 13:43:36 得分 0
up~Top
13 楼syalan(南瓜饼)回复于 2001-12-14 09:10:19 得分 0
第三天。。Top
14 楼cuiyxy(Passerby_001)回复于 2001-12-14 09:25:49 得分 0
ExitWindowsEx Function
Declare Function ExitWindowsEx Lib "user32.dll" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Platforms: Win 95/98, Win NT
ExitWindowsEx shuts down or reboots the user"s computer. Of course, since the shutdown/reboot process will begin once the function is called, there won"t normally be much left for your program to do. The function returns 0 if an error occured, or 1 if successful.
uFlags
One or more of the following flags specifying how to shut down or reboot the computer:
EWX_FORCE = 4
Force any applications to quit instead of prompting the user to close them.
EWX_LOGOFF = 0
Log off the network.
EWX_POWEROFF = 8
Shut down the system and, if possible, turn the computer off.
EWX_REBOOT = 2
Perform a full reboot of the system.
EWX_SHUTDOWN = 1
Shut down the system.
dwReserved
Reserved for future versions of Windows. Always set to 0.
Example:
" Reboot the computer, forcing any open programs to close
Dim retval As Long " return value
retval = ExitWindowsEx(EWX_REBOOT Or EWX_FORCE, 0)
If retval = 0 Then Debug.Print "Reboot attempt failed."
Top
15 楼mamaye(marki)回复于 2001-12-14 09:45:38 得分 0
我寫過這樣一個小程序,附下(節選,自已看吧)
Option Explicit
" 宣告最上層顯示sub
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, Y, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const HWND_TOP = 0
Private Const HWND_BOTTOM = 1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Enum HowExitConst
EWX_FORCE = 4 " 強制關機
EWX_LOGOFF = 0 " 登出
EWX_REBOOT = 2 " 重開機
EWX_SHUTDOWN = 1 " 關機
End Enum
Const TOKEN_ADJUST_PRIVILEGES = &H20
Const TOKEN_QUERY = &H8
Const SE_PRIVILEGE_ENABLED = &H2
Const ANYSIZE_ARRAY = 1
Private Type LUID
lowpart As Long
highpart As Long
End Type
Private Type LUID_AND_ATTRIBUTES
pLuid As LUID
Attributes As Long
End Type
Private Type TOKEN_PRIVILEGES
PrivilegeCount As Long
Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES
End Type
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, _
ByVal dwReserved As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias _
"LookupPrivilegeValueA" (ByVal lpSystemName As String, _
ByVal lpName As String, lpLuid As LUID) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" _
(ByVal TokenHandle As Long, ByVal DisableAllPrivileges As Long, _
NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Long, _
PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long
Private Declare Function OpenProcessToken Lib "advapi32.dll" _
(ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, _
TokenHandle As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
" 設置按鈕樣式消息 ( C++ 樣式按鈕,無獲得焦點時那討厭的黑圈 )
" 設置按鈕樣式消息
Private Const BM_SETSTYLE = &HF4 "&
" 有效的按鈕按下時的樣式
Private Const BS_DEFPUSHBUTTON = &H1& "標準樣式
Private Const BS_PUSHBUTTON = &H0& "API 樣式
"2. AdjustToken 副程式:
Private Sub AdjustToken()
Dim hdlProcessHandle As Long
Dim hdlTokenHandle As Long
Dim tmpLuid As LUID
Dim tkp As TOKEN_PRIVILEGES
Dim tkpNewButIgnored As TOKEN_PRIVILEGES
Dim lBufferNeeded As Long
hdlProcessHandle = GetCurrentProcess()
OpenProcessToken hdlProcessHandle, (TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY), _
hdlTokenHandle
"Get the LUID for shutdown privilege.
LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid
tkp.PrivilegeCount = 1 " One privilege to set
tkp.Privileges(0).pLuid = tmpLuid
tkp.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED
"Enable the shutdown privilege in the access token of this process.
AdjustTokenPrivileges hdlTokenHandle, False, tkp, Len(tkpNewButIgnored), _
tkpNewButIgnored, lBufferNeeded
End Sub
Private Sub Command1_Click()
If (Option1.Item(0).Value) Or (Option1.Item(3).Value) Then
Else
If Not Folder_Exist("c:\boot\tw\") Then
MakeDirs "C:\Boot\Tw\"
End If
If Not Folder_Exist("c:\boot\cn\") Then
MakeDirs "C:\Boot\Cn\"
End If
If Not File_Exist("c:\boot\tw\msdos.sys") Then
MsgBox "Refer to Ver MSDOS.SYS TW_Windows not exist ", , App.ProductName
Exit Sub
End If
If Not File_Exist("c:\boot\cn\msdos.sys") Then
MsgBox "Refer to Ver MSDOS.SYS CN_Windows not exist", , App.ProductName
Exit Sub
End If
End If
If Option1.Item(0).Value Then
AdjustToken
Call ExitWindowsEx(EWX_LOGOFF, 0)
"how 等於 EWX_LOGOFF 、 EWX_REBOOT 、 EWX_SHUTDOWN、 或EWX_FORCE
End If
If Option1.Item(1).Value Then
If Option2.Item(0).Value Then
Copy_File "C:\boot\tw\msdos.sys", "C:\"
End If
If Option2.Item(1).Value Then
Copy_File "C:\boot\CN\msdos.sys", "C:\"
End If
AdjustToken
Call ExitWindowsEx(EWX_REBOOT, 0)
End If
If Option1.Item(2).Value Then
If Option2.Item(0).Value Then
Copy_File "C:\boot\tw\msdos.sys", "C:\"
End If
If Option2.Item(1).Value Then
Copy_File "C:\boot\CN\msdos.sys", "C:\"
End If
AdjustToken
Call ExitWindowsEx(EWX_SHUTDOWN, 0)
End If
If Option1.Item(3).Value Then
AdjustToken
Call ExitWindowsEx(EWX_FORCE, 0)
End If
Unload Me
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
" 呼叫的範例:
" AdjustToken
" Call ExitWindowsEx(how, 0)
"how 等於 EWX_LOGOFF 、 EWX_REBOOT 、 EWX_SHUTDOWN、 或EWX_FORCE
"在 Windows 95 底下呼叫了 AdjustToken 也沒關係,因為 Windows 95 並不會理會安全性的設定。
"*************************************************************************************
" OnTop()
" 目 的: 設置窗口為最頂層窗口
" 輸 入: 窗口名
" 返 回 值: 無
"*************************************************************************************
Public Sub OnTop(ByVal lngValue As Long)
SetWindowPos lngValue, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
End Sub
"*************************************************************************************
" 目 的: 將指定按鈕變為 C++ 按鈕樣式 但怎作怎不象
" 輸 入: 引用的按鈕
" 返 回 值: 無 (改變其外觀)
"*************************************************************************************
Public Sub ButtonStyle(TheButton As CommandButton)
Dim hCmd As Long
"hCmd = FindWindow("Button", TheButton.Caption)
"SendMessage hCmd, BM_SETSTYLE, BS_PUSHBUTTON, 0&
"SendMessage TheButton.hWnd, BM_SETSTYLE, BS_DEFPUSHBUTTON, 0&
"TheButton.Style = vbButtonGraphical
SendMessage TheButton.hwnd, BM_SETSTYLE, BS_PUSHBUTTON, 0&
End Sub
Private Sub Form_Load()
Dim cpACP As Long
cpACP = GetACP()
If cpACP = 950 Then
Label3.Caption = LoadResString(133)
Else
Label3.Caption = LoadResString(134)
End If
" If cpACP = 950 Then
" Me.Caption = "計算機重啟選項" "LoadResString(100 + 1)
" Option1.Item(0).Caption = "登出 使用者" "LoadResString(100 + 2)
" Option1.Item(1).Caption = "重新啟動計算機" "LoadResString(100 + 3)
" Option1.Item(2).Caption = "關閉 計算機" "LoadResString(100 + 4)
" Option1.Item(3).Caption = "強制關閉計算機" "LoadResString(100 + 5)
"
" Frame1.Caption = "啟動何種作業系統" "LoadResString(100 + 6)
"
" Option2.Item(0).Caption = "繁體" "LoadResString(100 + 7)
" Option2.Item(1).Caption = "簡體" "LoadResString(100 + 8)
"
" Label1.Caption = "編製部門: 厚泰模具東莞分公司電腦部" "LoadResString(100 + 9)
" Label2.Caption = "編 制 人: Marki,Benson" "LoadResString(100 + 10)
"
" Command1.Caption = "確定" "LoadResString(100 + 11)
" Command2.Caption = "取消" "LoadResString(100 + 12)
Me.Caption = LoadResString(100 + 1)
Option1.Item(0).Caption = LoadResString(100 + 2)
Option1.Item(1).Caption = LoadResString(100 + 3)
Option1.Item(2).Caption = LoadResString(100 + 4)
Option1.Item(3).Caption = LoadResString(100 + 5)
Frame1.Caption = LoadResString(100 + 6)
Option2.Item(0).Caption = LoadResString(100 + 7)
Option2.Item(1).Caption = LoadResString(100 + 8)
Label1.Caption = LoadResString(100 + 9)
Label2.Caption = LoadResString(100 + 10)
Command1.Caption = LoadResString(100 + 11)
Command2.Caption = LoadResString(100 + 12)
" Else
"
" Me.Caption = LoadResString(120 + 1)
" Option1.Item(0).Caption = LoadResString(120 + 2)
" Option1.Item(1).Caption = LoadResString(120 + 3)
" Option1.Item(2).Caption = LoadResString(120 + 4)
" Option1.Item(3).Caption = LoadResString(120 + 5)
"
" Frame1.Caption = LoadResString(120 + 6)
"
" Option2.Item(0).Caption = LoadResString(120 + 7)
" Option2.Item(1).Caption = LoadResString(120 + 8)
"
" Label1.Caption = LoadResString(120 + 9)
" Label2.Caption = LoadResString(120 + 10)
"
" Command1.Caption = LoadResString(120 + 11)
" Command2.Caption = LoadResString(120 + 12)
"
" End If
OnTop Me.hwnd
ButtonStyle Command1
ButtonStyle Command2
" Option1.Item(0).Value = True
Option1.Item(1).Value = True
" Option1.Item(2).Value = True
" Option1.Item(3).Value = True
Option2.Item(0).Value = True
" Option2.Item(1).Value = True
End Sub
Private Sub Option1_Click(Index As Integer)
If (Index = 0) Or (Index = 3) Then
Option2.Item(0).Enabled = False
Option2.Item(1).Enabled = False
Else
Option2.Item(0).Enabled = True
Option2.Item(1).Enabled = True
End If
End Sub
Top
16 楼syalan(南瓜饼)回复于 2001-12-14 10:03:26 得分 0
谢谢,可我要的是WIN2K的休眠啊。Top
17 楼mamaye(marki)回复于 2001-12-14 10:38:02 得分 0
300分我要了 :)
Public oldProcAddress As Long
Public Enum enPowerBroadcastType
PBT_APMQUERYSUSPEND = &H0
PBT_APMQUERYSTANDBY = &H1
PBT_APMQUERYSUSPENDFAILED = &H2
PBT_APMQUERYSTANDBYFAILED = &H3
PBT_APMSUSPEND = &H4
PBT_APMSTANDBY = &H5
PBT_APMRESUMECRITICAL = &H6
PBT_APMRESUMESUSPEND = &H7
PBT_APMRESUMESTANDBY = &H8
End Enum
Public Const BROADCAST_QUERY_DENY = &H424D5144
Public Const WM_POWER = &H48
Public Const WM_POWERBROADCAST = &H218
Public Const PWR_SUSPENDREQUEST = 1
Public Const GWL_WNDPROC = (-4)
Public Const PWR_FAIL = (-1)
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Function VB_WindowProc(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
On Local Error Resume Next
Dim lRet As Long
If wMsg = WM_POWER And wParam = PWR_SUSPENDREQUEST Then
VB_WindowProc = PWR_FAIL
ElseIf wMsg = WM_POWERBROADCAST And wParam = PBT_APMQUERYSUSPEND Then
VB_WindowProc = BROADCAST_QUERY_DENY
Else
VB_WindowProc = CallWindowProc(oldProcAddress, hWnd, wMsg, wParam, lParam)
End If
End Function
Private Sub Form_Load()
oldProcAddress = SetWindowLong(Me.hWnd, GWL_WNDPROC, AddressOf VB_WindowProc)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call SetWindowLong(Me.hWnd, GWL_WNDPROC, oldProcAddress)
End Sub
Top
18 楼syalan(南瓜饼)回复于 2001-12-14 11:11:20 得分 0
to mamaye(mamaye)
执行休眠的函数如何调用啊,能说一下吗?是VB_WindowProc吗,参数怎么添??Top
19 楼tiaozi2000(VC)回复于 2001-12-14 11:26:13 得分 0
要得到关机权限灵牌才可以关闭WIN2KTop
20 楼mamaye(marki)回复于 2001-12-14 11:41:43 得分 0
有分嗎~
"---------------------------------
" 聲明(函數及常量) 應放在 bas 文件中
"---------------------------------
" -------------------------------------------
" 其余可自己組織~
"
" -------------------------------------------
" VB_WindowProc 參數說明
" typedef LRESULT (CALLBACK* WNDPROC)
" (HWND, UINT, WPARAM, LPARAM);
" 參數:
" hwnd - window 句柄
" wMsg - window 消息 (WM_..等)
" wParam - 第一個消息參數
" lParam - 第二個消息參數
" 注意: ~,根據自己的情況來看,注意回調的地址~
" ------------------------------------
Top
21 楼yigenhuochai(solmyr)回复于 2001-12-14 11:48:48 得分 0
easyTop
22 楼syalan(南瓜饼)回复于 2001-12-14 11:54:02 得分 0
TO mamaye(mamaye)
我只要实现WIN2K 休眠的功能,麻烦写一下吧,能用了马上给分!!!!Top
23 楼syalan(南瓜饼)回复于 2001-12-14 13:55:12 得分 0
up~Top
24 楼mamaye(marki)回复于 2001-12-14 15:43:38 得分 0
hi
最後補充,上面的程式功能在于限制電腦休眠,要注意不能直接套用
Top
25 楼syalan(南瓜饼)回复于 2001-12-14 16:36:47 得分 0
to mamaye(mamaye)
老兄玩笑开大了吧Top
26 楼mamaye(marki)回复于 2001-12-14 17:30:55 得分 0
別誤會,我的意思只是想拋磚引玉而已
其實道理差不多,重點在三個方面
其一,了解 WM_POWER;WM_POWERBROADCAST等
這類消息(可查相關資料)
其二,注意系統挂起時各窗口狀態及信息的設置
其三,喚醒時狀態的恢復
其時,我也只是業余時思考一下,并未著手去作這個程式,
因考慮可能麻煩很多,亦并不是很實用
我曾經有一個想法是,在WIN9X的機器當操作人离開時,通過一個熱鍵
將電腦挂起,喚醒時需輸入密碼,起到保護和省電作用,但限制電腦挂起則
容易多了,如上,你說是嗎~ 
Top
27 楼mamaye(marki)回复于 2001-12-14 17:32:44 得分 0
別誤會,我的意思只是想拋磚引玉而已
其實道理差不多,重點在三個方面
其一,了解 WM_POWER;WM_POWERBROADCAST等
這類消息(可查相關資料)
其二,注意系統挂起時各窗口狀態及信息的設置
其三,喚醒時狀態的恢復
其時,我也只是業余時思考一下,并未著手去作這個程式,
因考慮可能麻煩很多,亦并不是很實用
我曾經有一個想法是,在WIN9X的機器當操作人离開時,通過一個熱鍵
將電腦挂起,喚醒時需輸入密碼,起到保護和省電作用,但限制電腦挂起則
容易多了,如上,你說是嗎~ 
Top
28 楼syalan(南瓜饼)回复于 2001-12-15 09:44:50 得分 0
第四天..Top
29 楼syalan(南瓜饼)回复于 2001-12-17 09:18:04 得分 0
第六天Top
30 楼syalan(南瓜饼)回复于 2001-12-17 13:17:15 得分 0
现在宣布:给此贴UP者每次奖10分,没人一天限一次。。
大家帮帮忙啊~~~~~~~~~~~~~Top
31 楼fraser01(王晓栋)回复于 2001-12-17 13:23:03 得分 0
不用休眠了,我都快冬眠了。Top
32 楼syalan(南瓜饼)回复于 2001-12-18 10:02:13 得分 0
痛苦中~~~~~~~~~~Top
33 楼syalan(南瓜饼)回复于 2001-12-24 09:47:58 得分 0
u~pTop
34 楼siyuan79(荔枝(广州新塘))回复于 2001-12-24 10:47:05 得分 0
按照上面的办法就可以了。Top
-
相关文章
2秒记住本站域名
玩过泡泡龙吗?Readygo?Go! 再加上.Com.Cn的后缀,那就是大名小顶的readygo.com.cn
