Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
查看: 4480|回复: 29
打印 上一主题 下一主题

vb.net auto shutdown PC

[复制链接]

13

主题

0

好友

2113

积分

白金长老

Rank: 10

跳转到指定楼层
1#
发表于 2008-8-9 11:00 PM |只看该作者 |倒序浏览
vb6


  1. Private Const EWX_LOGOFF = 0
  2. Private Const EWX_SHUTDOWN = 1
  3. Private Const EWX_REBOOT = 2
  4. Private Const EWX_FORCE = 4
  5. Private Const TOKEN_ADJUST_PRIVILEGES = &H20
  6. Private Const TOKEN_QUERY = &H8
  7. Private Const SE_PRIVILEGE_ENABLED = &H2
  8. Private Const ANYSIZE_ARRAY = 1
  9. Private Const VER_PLATFORM_WIN32_NT = 2

  10. Type OSVERSIONINFO
  11. dwOSVersionInfoSize As Long
  12. dwMajorVersion As Long
  13. dwMinorVersion As Long
  14. dwBuildNumber As Long
  15. dwPlatformId As Long
  16. szCSDVersion As String * 128
  17. End Type

  18. Public Type LUID
  19. LowPart As Long
  20. HighPart As Long
  21. End Type

  22. Public Type LUID_AND_ATTRIBUTES
  23. pLuid As LUID
  24. Attributes As Long
  25. End Type

  26. Public Type TOKEN_PRIVILEGES
  27. PrivilegeCount As Long
  28. Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES
  29. End Type

  30. Private Declare Function GetCurrentProcess Lib "kernel32.dll" () As Long
  31. Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal
  32. ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
  33. Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
  34. 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
  35. TOKEN_PRIVILEGES, ReturnLength As Long) As Long Private Declare Function ExitWindowsEx Lib "user32.dll" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
  36. Private Declare Function GetVersionEx Lib "kernel32.dll" Alias "GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFO) As Long

  37. Private Sub EnableShutDown()
  38. Dim hProc As Long
  39. Dim hToken As Long
  40. Dim mLUID As LUID
  41. Dim mPriv As TOKEN_PRIVILEGES
  42. Dim mNewPriv As TOKEN_PRIVILEGES

  43. hProc = GetCurrentProcess()
  44. OpenProcessToken hProc, TOKEN_ADJUST_PRIVILEGES + TOKEN_QUERY, hToken
  45. LookupPrivilegeValue "", "SeShutdownPrivilege", mLUID
  46. mPriv.PrivilegeCount = 1
  47. mPriv.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED
  48. mPriv.Privileges(0).pLuid = mLUID
  49. AdjustTokenPrivileges hToken, False, mPriv, 4 + (12 *
  50. mPriv.PrivilegeCount), mNewPriv, 4 + (12 * mNewPriv.PrivilegeCount)
  51. End Sub

  52. Public Sub ShutDownNT(Force As Boolean)
  53. Dim Ret As Long
  54. Dim flags As Long

  55. flags = EWX_SHUTDOWN
  56. If Force Then flags = flags + EWX_FORCE
  57. EnableShutDown
  58. ExitWindowsEx flags, 0
  59. End Sub

  60. Public Sub RebootNT(Force As Boolean)
  61. Dim Ret As Long
  62. Dim flags As Long

  63. flags = EWX_REBOOT
  64. If Force Then flags = flags + EWX_FORCE
  65. EnableShutDown
  66. ExitWindowsEx flags, 0
  67. End Sub

  68. Public Sub LogOffNT(Force As Boolean)
  69. Dim Ret As Long
  70. Dim flags As Long

  71. flags = EWX_LOGOFF
  72. If Force Then flags = flags + EWX_FORCE
  73. ExitWindowsEx flags, 0
  74. End Sub

复制代码


vb.net
要引进
在referance 里

imports System.Diagnostics

  1. System.Diagnostics.Process.Start("Shutdown", "/s")
复制代码




收藏收藏0

13

主题

0

好友

2113

积分

白金长老

Rank: 10

2#
发表于 2008-8-9 11:01 PM |只看该作者
.net 可以很懒

vb6 要用 win32 api 的函数


回复

使用道具 举报

2

主题

2

好友

621

积分

青铜长老

Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7

3#
发表于 2008-8-9 11:28 PM |只看该作者
要怎么运行...不好意思我还是新手


回复

使用道具 举报

62

主题

5

好友

3715

积分

本站名嘴

Rank: 11Rank: 11

4#
发表于 2008-8-9 11:52 PM |只看该作者
我才做了你就放了
不过我的是Shell


回复

使用道具 举报

13

主题

0

好友

2113

积分

白金长老

Rank: 10

5#
发表于 2008-8-10 12:05 PM |只看该作者
原帖由 goodhermit95 于 2008-8-9 11:52 PM 发表
我才做了你就放了
不过我的是Shell


paste 你的 code 啦~~~


回复

使用道具 举报

62

主题

5

好友

3715

积分

本站名嘴

Rank: 11Rank: 11

6#
发表于 2008-8-10 01:43 PM |只看该作者

回复 #5 goodday 的帖子

Label1.Text = FormatDateTime(Now.Hour & ":" & Now.Minute & ":" & Now.Second) ' vb.net time format
timer2_Tick (Byval e as....)...
If label1.text = textbox1.text & textbox2.text & textbox3.text & combobox1.text then
If Radiobutton1.checked  = true then 'Radiobutton1.text = shutdown
  Shell ("shutdown -s") ' the shell command means shutdown,shutdown
ElseIf Radiobutton2.checked = true then 'if not then radiobutton2,text = restart
  Shell ("Shutdown -r") ' the shell command means shutdown,restart
Else ' else then logoff
  shell ("Shutdown -l")
End If
End If
End Sub

[ 本帖最后由 goodhermit95 于 2008-8-10 01:45 PM 编辑 ]


回复

使用道具 举报

3

主题

0

好友

7984

积分

百变名嘴

Rank: 13Rank: 13Rank: 13Rank: 13

7#
发表于 2008-8-11 12:43 AM |只看该作者
我是不是可以拿來害人呢        
·


回复

使用道具 举报

102

主题

1

好友

6230

积分

百变名嘴

Rank: 13Rank: 13Rank: 13Rank: 13

8#
发表于 2008-8-11 05:28 PM |只看该作者
哇..真的写出来了哦?
可是完全看不懂叻
我连最基本得都还没学会写


回复

使用道具 举报

3

主题

0

好友

7984

积分

百变名嘴

Rank: 13Rank: 13Rank: 13Rank: 13

9#
发表于 2008-8-13 06:35 PM |只看该作者
說真的

我也不知道怎么compile

怕弄錯了我中招


回复

使用道具 举报

62

主题

5

好友

3715

积分

本站名嘴

Rank: 11Rank: 11

10#
发表于 2008-8-13 10:46 PM |只看该作者

回复 #9 dious 的帖子

debug的时候


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2024-12-26 01:40 PM , Processed in 0.126624 second(s), 27 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部