Windows unopened function revealed (1)

zhaozj2021-02-11  203

WINDOWS unopened function revealed

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, the collateral is correct, here is the first to introduce you unneleased 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 Explicit Public Biswinnt as boolean 'is the unapproved function definition, pay attention to the true name "of the function after Alias ​​is used, because Microsoft does not have public function name Declare Function SHRestartSystemMB Lib "shell32" - Alias ​​"# 59" - (ByVal hOwner As Long, - ByVal sExtraPrompt As String, - ByVal uFlags As Long) As Long Declare Function SHShutDownDialog Lib "shell32" - Alias ​​"# 60" - (ByVal yourGuess As Long) As Long Declare Function GetVersionEx Lib "kernel32" - Alias ​​"GetVersionExA" - (lpVersionInformation As OSVERSIONINFO) As Long Type OSVERSIONINFO dwOSVersionInfoSize 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 shrsExitNoDefPrompt = 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 IsTextUnicode Lib "advapi32" - (lpBuffer As Any, - ByVal cb As Long, - LPI As Long) As longode-ascii16 = & h1 public const IS-text-unicode-reverse-ascii16 = &

H10 Public Const IS-TEXT-UNICODE-STATISTICS = & H2 Public Const IS-TEXT-UNICODE-REVERSE-STATISTICS = & H20 Public Const IS-TEXT-UNICODE-CONTROLS = & H4 Public Const IS-TEXT-UNICODE-REVERSE-CONTROLS = & H40 Public const IS-TEXT-UNICODE-SIGNATURE = & H8 Public const IS-TEXT-UNICODE-REVERSE-SIGNATURE = & H80 Public const IS-TEXT-UNICODE-ILLEGAL-CHARS = & H100 Public const IS-TEXT-UNICODE-ODD-LENGTH = & H200 Public const IS-TEXT-UNICODE-DBCS_LEADBYTE = & H400 Public const IS-TEXT-UNICODE-NULL-BYTES = & H1000 Public const IS-TEXT-UNICODE-UNICODE-MASK = & HF Public const IS-TEXT-UNICODE-REVERSE-MASK = & HF0 Public const IS-TEXT-UNICODE-NOT-UNICODE-MASK = & HF00 Public const IS-TEXT-UNICODE-NOT-ASCII_MASK = & HF000 Public Function IsWinNT () As Boolean Dim osvi As OSVERSIONINFO osvi.dwOSVersionInfoSize = 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 = STRC ONV (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 = IsTextUnicode (ByVal sBuffer, Len (sBuffer), dwRtnFlags) End Function then was added a ComboBox control to Form1, two CommandButton control, and then add the following code in the code window Form1: Private Sub Command1_Click () Call SHShutDownDialog (0) End Sub Private Sub Command2_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 Form_Load () bIsWinNT = IsWinNT () If bIsWinNT Then 'WinNT OS With Combo1 .Additem "0 - Close the program and log in." 1 - Turn off the computer ".additem" 2 - Restart the computer ".text =" "End with end if command1.caption =" shutdown system dialog "Command2.caption =" Off or restart computer "End Sub running program,

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

New Post(0)