Windows unapproved function reveals - one

zhaozj2021-02-08  207

Windows unapproved function reveals - one

What is an unapproved function?

For Windows API function calls believe that everyone will not be unfamiliar. The API function call is to extend the functionality of the VB program by defining and calling a function in the Windows dynamic connection library in VB. The definition of the API function and the call method have a detailed description in Microsoft's development tools.

So what is the "undisclosed" function? Microsoft is for a purpose. For some functions in the system, no function descriptions and definitions are provided in any development documentation. Many of these functions are very useful. Fortunately, some have a very detailed analysis of the Windows System Dynamic Library, which will open these unobstructed functions for sharing of developers (I am grateful to them like the river, the water ... )

Ok, nonsense is less, the words come true, first introduce you to the unnendated Windows function under Windows. Although EXITWINDOWSEX is available in the Windows API function, we need to restart your computer or do not restart your computer or not restart your computer or not restart your computer. Or you want to pop up the shutdown system dialog box in the program. To implement these features, use Windows unappromested functions. Let's look at the program

First create a new project file, add a Module file in the project file. Add the following code in the Module file:

Option expedition

Public biswinnt as boolean

'The following is the undisclosed function definition, pay attention to the true name of the function after ALIAS

'But use a function number because Microsoft has no public function name.

Declare function shrestsystemmb "shell32" _

Alias ​​"# 59" _

(ByVal Howner As Long, _

Byval sextraprompt as string, _

BYVAL UFLAGS AS Long

Declare function shshutdowndialog lib "shell32" _

Alias ​​"# 60" _

(Byval Yourguess As Long) As Long

Declare function getversionEx lib "kernel32" _

Alias ​​"getversionexa" _

(LPVERSIONFORMATION As OsversionInfo) AS Long

Type OsversionInfo

DWOSVERSIONFOSIZE AS long

DWmajorversion As Long

DWMINORVERSION As Long

DWBUILDNUMBER AS Long

DWPLATFORMID AS Long

SZCSDVERSION As String * 128

End Type

Public const EWX_LOGOFF = 0

Public const EWX_SHUTDOWN = 1

Public const EWX_REBOOT = 2

Public const ewx_force = 4

Public const EWX_PowerOff = 8

Public const shrsxitNodeFprompt = 1

Public const shrsrebootsystem = 2

Const Ver_Platform_Win32S = 0

Const ver_platform_win32_windows = 1

Const Ver_Platform_Win32_NT = 2

Declare Sub CopyMemory Lib "kernel32" _ALIAS "RTLMoveMemory" _

(pdest as any, _

Psource as any, _

Byval bytelen as long

Declare function istextunicore LIB "Advapi32" _

(lpbuffer as any, _

Byval cb as long, _

LPI as long) As long

Public const I_text_unicode_ascii16 = & h1

Public const is_text_unication_reverse_ascii16 = & h10

Public const is_text_unication_statistics = & h2

Public const is_text_unicode_reverse_statistics = & H20

Public const is_text_unication_controls = & h4

Public const is_text_unicore_reverse_controls = & h40

Public const is_text_unicate_signature = & h8

Public const is_text_unicode_reverse_signature = & h80

Public const is_text_unication_illegal_chars = & h100

Public const is_text_unicth = & h200

Public const is_text_unication_dbcs_leadbyte = & h400

Public const is_text_unicade_null_bytes = & h1000

PUBLIC Const IS_TEXT_UNICODE_UNICODE_MASK = & HF

Public const is_text_unicode_reverse_mask = & hf0

Public const IS_text_unicore_not_unicode_mask = & hf00

Public const is_text_unicore_not_ascii_mask = & hf000

Public function iswinnt () as boolean

Dim Osvi as OsversionInfo

Osvi.dwosveionsInFoSize = LEN (OSVI)

GetversionEx OSVI

Iswinnt = (OSVI.DWPLATFORMID = VER_PLATFORM_WIN32_NT)

END FUNCTION

Public Function Checkstring (MSG As String) AS STRING

IF biswinnt then

Checkstring = strconv (msg, vbunicode)

Else: Checkstring = MSG

END IF

END FUNCTION

Public Function GetStrFromPtr (LPSZSTR AS Long, NBYTES AS Integer) AS STRING

Redim ab (nbytes) as Byte

CopyMemory Ab (0), ByVal Lpszstr, Nbytes

GetstrFromPtr = GetStrfromBuffer (StrConv (ab (), vbunicode) end Function

Public Function GetStrFromBuffer (Szstr As String) AS String

IF Isunicodestr (Szstr) Then Szstr = StrConv (Szstr, Vbfromunicode)

IF INSTR (SZSTR, VBNULLCHAR) THEN

GetStrfromBuffer = Left $ (Szstr, Instr (Szstr, VBnullchar) - 1)

Else: GetstrFromBuffer = Szstr

END IF

END FUNCTION

Public Function IsunicodeStr (SBuffer As String) AS Boolean

DIM DWRTNFLAGS AS Long

DWRTNFLAGS = IS_TEXT_UNICODE_UNICODE_MASK

IsunicodeStr = IsTextunicate (Byval Sbuffer, Len (Sbuffer), DWRTNFLAGS

END FUNCTION

Then add a ComboBox control in Form1, two CommandButton controls, and then add the following code in the Form1's code window:

Private submmand1_click ()

Call shshutdowndialog (0)

End Sub

Private sub fascist2_click ()

DIM SPROMPT AS STRING

DIM UFLAG As Long

Select Case Combo1.ListIndex

Case -1: uflag = val (combo1.text)

Case 0: uflag = shrsexitnodefprompt

Case 1: uflag = shrsrebootsystem

End SELECT

If ShrestartSystemmb (hwnd, sprompt, uflag) = Vbyes then

END IF

End Sub

Private sub flow_load ()

Biswinnt = iswinnt ()

IF biswinnt the 'Winnt operating system

With combo1

.Additem "0 - Close the program and log in with other users"

.Additem "1 - Close Computer"

.Additem "2 - Restart Computer"

.Text = ""

End with

Else 'Win95 / 98 operating system

With combo1

.Additem "1 - Close Computer"

.Additem "2 - Restart Computer"

.Text = ""

End with

END IF

Command1.caption = "Close System Dialog"

Command2.caption = "Off or Restart Computer"

End Sub

Run the program, click the "Close System Dialog" button to pop up the shutdown system dialog box. Select Close System in Combo1, restart or close the program and log in to the item as other user, click the "Close or Restart the Computer" button, the system will pop up the prompt dialog prompt to perform the corresponding operation, click "Yes" Execute it.

E-mail vbcode@21cn.com

转载请注明原文地址:https://www.9cbs.com/read-1169.html

New Post(0)