Microsoft Windows XP Professional With Servise Pack 2 (e8503040) for PC Logo
Posted on Jan 01, 2009

What is the program code to shutdown the pc in visual basic

I need a program to shutdown the pc in visual basic

1 Answer

Anonymous

Level 1:

An expert who has achieved level 1.

  • Contributor 1 Answer
  • Posted on Jan 05, 2009
Anonymous
Contributor
Level 1:

An expert who has achieved level 1.

Joined: Jan 05, 2009
Answers
1
Questions
1
Helped
325
Points
1

I was wondering if someone could help me to convert this vb6 code to be used
in VB.net. It basically allows you to call the subs at the bottom to logoff
shutdown and restart the pc (By force if necessary). Any help is greatly
appreciated.

Private Const EWX_LOGOFF = 0
Private Const EWX_SHUTDOWN = 1
Private Const EWX_REBOOT = 2
Private Const EWX_FORCE = 4
Private Const TOKEN_ADJUST_PRIVILEGES = &H20
Private Const TOKEN_QUERY = &H8
Private Const SE_PRIVILEGE_ENABLED = &H2
Private Const ANYSIZE_ARRAY = 1
Private Const VER_PLATFORM_WIN32_NT = 2

Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type

Public Type LUID
LowPart As Long
HighPart As Long
End Type

Public Type LUID_AND_ATTRIBUTES
pLuid As LUID
Attributes As Long
End Type

Public Type TOKEN_PRIVILEGES
PrivilegeCount As Long
Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES
End Type

Private Declare Function GetCurrentProcess Lib "kernel32.dll" () 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 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 ExitWindowsEx Lib "user32.dll" (ByVal uFlags As
Long, ByVal dwReserved As Long) As Long
Private Declare Function GetVersionEx Lib "kernel32.dll" Alias
"GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFO) As Long

Private Sub EnableShutDown()
Dim hProc As Long
Dim hToken As Long
Dim mLUID As LUID
Dim mPriv As TOKEN_PRIVILEGES
Dim mNewPriv As TOKEN_PRIVILEGES

hProc = GetCurrentProcess()
OpenProcessToken hProc, TOKEN_ADJUST_PRIVILEGES + TOKEN_QUERY, hToken
LookupPrivilegeValue "", "SeShutdownPrivilege", mLUID
mPriv.PrivilegeCount = 1
mPriv.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED
mPriv.Privileges(0).pLuid = mLUID
AdjustTokenPrivileges hToken, False, mPriv, 4 + (12 *
mPriv.PrivilegeCount), mNewPriv, 4 + (12 * mNewPriv.PrivilegeCount)
End Sub

Public Sub ShutDownNT(Force As Boolean)
Dim Ret As Long
Dim flags As Long

flags = EWX_SHUTDOWN
If Force Then flags = flags + EWX_FORCE
EnableShutDown
ExitWindowsEx flags, 0
End Sub

Public Sub RebootNT(Force As Boolean)
Dim Ret As Long
Dim flags As Long

flags = EWX_REBOOT
If Force Then flags = flags + EWX_FORCE
EnableShutDown
ExitWindowsEx flags, 0
End Sub

Public Sub LogOffNT(Force As Boolean)
Dim Ret As Long
Dim flags As Long

flags = EWX_LOGOFF
If Force Then flags = flags + EWX_FORCE
ExitWindowsEx flags, 0
End Sub

Add Your Answer

×

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

Related Questions:

0helpful
1answer

What's your problem?I need code for a project in a programming basics class

Give me a definition on which you are looking for.Such as constructor ,destructor etc...
Specify it.
0helpful
2answers

I wnt code

By deafualt it is 00000000000000000000000000000000
Thanks
1helpful
1answer

How to create a program using visual basic 6.0 kindly give me a sample program using VB 6.0, with the codes.

The "Hello World" program is always the first program you should write in any language, as it will show you very basic use of the language.
Here is a tutorial of a "hello world" program for VB6.
Hope this helps, good luck!
5helpful
2answers

VIDEO LIBRARY MANAGEMENT SYSTEM source code IN visual basic

You can get your project from

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=70428&lngWId=1
0helpful
1answer

Drawing in Visual Basic 6.0

Hi - You cannot scan directly into VB6 unless you use a third-party control (OCX). You would need to get the data into a database table and use ADO, or, hard-code the data directly into your source code. You can actually grab it from Excel too but that involves automation programming - not hard to do - just more to learn. Have fun!
0helpful
1answer

What is visual basic practical 6.0

Read the HOW TO section in the Help File of the program, or search the net for "what is visual basic practical"
1helpful
1answer

How i can download vb on my pc for windos98

Here the download for visual basic environment on windows 98

Download details: Visual Basic 6.0

If you instead want to do programming, then you need to download Visual studio 2005, that runs on Windows 98.

You can download Cisula Studio 2005 from the link below:

Download details: Visual Studio® 2005 Express Editions SP1
0helpful
1answer

About the vb6 printing codes

hi, welcome to fixya
i could not check more about it just check it out might help u out...good luck..

pls rate my solutions,i need it.....
Not finding what you are looking for?

335 views

Ask a Question

Usually answered in minutes!

Top Microsoft Computers & Internet Experts

Grand Canyon Tech
Grand Canyon Tech

Level 3 Expert

3867 Answers

k24674

Level 3 Expert

8093 Answers

Brad Brown

Level 3 Expert

19187 Answers

Are you a Microsoft Computer and Internet Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...