 |
VFP 愛用者社區 本討論區為 Visual Foxpro 愛用者經驗交流的地方, 請多多利用"搜尋"的功能, 先查看看有無前例可循, 如果還有不懂的再發問. 部份主題有附加檔案, 須先註冊成為社區居民才可以下載.
|
上一篇主題 :: 下一篇主題 |
發表人 |
內容 |
spfrk
註冊時間: 2004-11-08 文章: 163
第 1 樓
|
發表於: 星期五 二月 16, 2007 9:43 am 文章主題: VFP 如何在 XP 系統下自動關機 |
|
|
[size=18][/size]
此功能在 VB 或 VC 下是很簡單, 但在 VFP 下就有些困難, 因為 VFP 並沒有
結構變數, 因此必須用字串變數去解, 這是我自己在使用的, 在此分享各位狐友
*///
*/ 自動關機
*/
*/ 0 登出 原參數
*/ 1 關機
*/ 2 重開機
*/ 4 強制關機
*/
*///
func EposShutDown
para vtype
local vt
Declare integer GetCurrentProcess in kernel32.dll
Declare integer LookupPrivilegeValue in advapi32.dll String, String, String @
Declare integer AdjustTokenPrivileges in advapi32.dll Long, Long, String @, Long, String @, Long @
Declare integer OpenProcessToken in advapi32.dll Long, Long, Long @
vt = 1
do case
case vtype = 1 && 登出
vt = 0
case vtype = 2 && 關機
vt = 1
case vtype = 3 && 重開機
vt = 2
case vtype = 4 && 強制關機
vt = 4
endcase
TOKEN_ADJUST_PRIVILEGES = 32 && H20
TOKEN_QUERY = 8 && H8
SE_PRIVILEGE_ENABLED = 2 && H2
ANYSIZE_ARRAY = 1
hdlProcessHandle = 0
hdlTokenHandle = 0
tmpLuid = repl(chr(0), && LUID
tkp = chr(1)+repl(chr(0),15) && TOKEN_PRIVILEGES tkp.PrivilegeCount = 1
tkpNewButIgnored = repl(chr(0),16) && TOKEN_PRIVILEGES
lBufferNeeded = 0
hdlProcessHandle = GetCurrentProcess()
if vtype <> 0
vtmp = OpenProcessToken(hdlProcessHandle, 40, @hdlTokenHandle) && long long long @
endif
LookupPrivilegeValue ("","SeShutdownPrivilege", @tmpLuid) && String, String, String @
tkp = substr(tkp,1,4) + tmpLuid + chr(2)+repl(chr(0),3) && SE_PRIVILEGE_ENABLED 4 8 4
vtmp = AdjustTokenPrivileges(hdlTokenHandle, 0, @tkp, 16, @tkpNewButIgnored, @lBufferNeeded)
ExitWindowsEx(vt, 0)
quit
retu .Y. |
|
回頂端 |
|
 |
spfrk
註冊時間: 2004-11-08 文章: 163
第 2 樓
|
發表於: 星期五 二月 16, 2007 9:49 am 文章主題: |
|
|
tmpLuid = repl(chr(0), 不知為何變成笑臉, 更正 |
|
回頂端 |
|
 |
spfrk
註冊時間: 2004-11-08 文章: 163
第 3 樓
|
發表於: 星期五 二月 16, 2007 9:50 am 文章主題: |
|
|
tmpLuid = repl(chr(0) , 8 ) 笑臉是 8 ) |
|
回頂端 |
|
 |
garfield Site Admin

註冊時間: 2003-01-30 文章: 2160
第 4 樓
|
發表於: 星期五 二月 16, 2007 12:15 pm 文章主題: |
|
|
---------------------
function ExitWindows
*--------------------
PARAMETERS lnExitType
* lnExitType = EWX_LOGOFF = 0
* lnExitType = EWX_SHUTDOWN = 1
* lnExitType = EWX_REBOOT = 2
* lnExitType = EWX_FORCE = 4
* lnExitType = EWX_POWEROFF = 8
* lnExitType = EWX_RESET = EWX_LOGOFF + EWX_FORCE + EWX_REBOOT
DECLARE INTEGER ExitWindowsEx IN user32 INTEGER, INTEGER
lnExitWindows=ExitWindowsEx(lnExitType,0)
return(lnExitWindows)
endfunc
ReNo(2) 蔡世恩 回覆請按 >>Re 回覆Jack許:回覆蔡世恩:如何利用vfp讓windows關機????
2001/3/6 PM 07:20:50 JACK許,
謝謝您的幫忙
不過操作時, 發現一新的問題
在WIN ME下執行, 只能登出,不能關機
WIN2000則無反應
不知是否還有其他注意事項????????
謝謝
ReNo(3) Jack許 回覆請按 >>Re 回覆蔡世恩:回覆Jack許:回覆蔡世恩:如何利用vfp讓windows關機????
2001/3/7 AM 09:35:32 * EWX_LOGOFF = 0
* EWX_SHUTDOWN = 1
* EWX_REBOOT = 2
* EWX_FORCE = 4
* EWX_POWEROFF = 8
* EWX_RESET = EWX_LOGOFF + EWX_FORCE + EWX_REBOOT
lnExitType = 1
或
lnExitType = 1 + 4
************* 另外的方法
RunCommand="C:\WINDOWS\RUNDLL.EXE user.exe,exitwindows"
Run &RunCommand. _________________ 利用>>搜尋<<的功能會比問的還要快得到答案. |
|
回頂端 |
|
 |
spfrk
註冊時間: 2004-11-08 文章: 163
第 5 樓
|
發表於: 星期五 二月 16, 2007 10:13 pm 文章主題: |
|
|
在 NT2000, XP 作業系統下只使用 exitwindows 此 API 是無法關機的, 必須先讓程式取得關機的許可權,
才能執行 exitwindows 關機. |
|
回頂端 |
|
 |
garfield Site Admin

註冊時間: 2003-01-30 文章: 2160
第 6 樓
|
|
回頂端 |
|
 |
|
|
您 無法 在這個版面發表文章 您 無法 在這個版面回覆文章 您 無法 在這個版面編輯文章 您 無法 在這個版面刪除文章 您 無法 在這個版面進行投票 您 無法 在這個版面附加檔案 您 無法 在這個版面下載檔案
|
|