Question about Microsoft Windows XP Professional With Servise Pack 2 (e8503040) for PC

1 Answer

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

I need a program to shutdown the pc in visual basic

Posted by on

1 Answer

  • Level 1:

    An expert who has achieved level 1.

  • Contributor
  • 1 Answer

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

Posted on Jan 05, 2009

1 Suggested Answer

6ya6ya
  • 2 Answers

SOURCE: I have freestanding Series 8 dishwasher. Lately during the filling cycle water hammer is occurring. How can this be resolved

Hi,
a 6ya expert can help you resolve that issue over the phone in a minute or two.
best thing about this new service is that you are never placed on hold and get to talk to real repairmen in the US.
the service is completely free and covers almost anything you can think of (from cars to computers, handyman, and even drones).
click here to download the app (for users in the US for now) and get all the help you need.
goodluck!

Posted on Jan 02, 2017

Add Your Answer

Uploading: 0%

my-video-file.mp4

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

×

Loading...
Loading...

Related Questions:

1 Answer

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.

Jun 28, 2012 | Microsoft Visual C++ Professional Edition...

2 Answers

I wnt code


By deafualt it is 00000000000000000000000000000000
Thanks

May 07, 2011 | Microsoft Visual Basic 6.0 for PC

1 Answer

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!

Aug 13, 2010 | Microsoft Visual Basic 6.0 (361-00686) for...

2 Answers

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

Nov 09, 2009 | Microsoft Visual Basic 6.0 for PC

1 Answer

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!

May 12, 2009 | Microsoft Visual Basic Enterprise Edition...

1 Answer

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"

Apr 02, 2009 | Microsoft Visual Basic 6.0 for PC

1 Answer

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

Feb 28, 2009 | Microsoft Visual Basic Professional...

1 Answer

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.....

Feb 15, 2009 | Microsoft Visual Basic 6.0 for PC

Not finding what you are looking for?
Microsoft Windows XP Professional With Servise Pack 2 (e8503040) for PC Logo

280 people viewed this question

Ask a Question

Usually answered in minutes!

Top Microsoft Computers & Internet Experts

micky dee

Level 3 Expert

2644 Answers

Les Dickinson
Les Dickinson

Level 3 Expert

18381 Answers

Brian Sullivan
Brian Sullivan

Level 3 Expert

27725 Answers

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

Answer questions

Manuals & User Guides

Loading...