1。Shell下也可用如下命令实现:Rundll32.exe user.exe,exitwindows
2。VB代码实现:
Option Explicit |
/' *******************************************************
/' Routine Name : (PUBLIC in MODULE) Function ReturnApiErrString
/' Written By : L.J. Johnson
/' Programmer : L.J. Johnson [Slightly Tilted Software]
/' Date Writen : 01/16/1999 -- 12:56:46
/' Inputs : ErrorCode:Long - Number returned from API error
/' Outputs : N/A
/' Description : Function returns the error string
/' : The original code appeared in Keith Pleas
/' : article in VBPJ, April 1996 (OLE Expert
/' : column). Thanks, Keith.
Public Function ReturnApiErrString(ErrorCode As Long) As String
On Error Resume Next /' Don/'t accept an error here
Dim p_strBuffer As String
Dim p_lngHwndModule As Long
Dim p_lngFlags As Long
/' ------------------------------------------
/' Separate handling for network errors
/' netmsg.dll
/' ------------------------------------------
If ErrorCode >= NERR_BASE And _
ErrorCode <= MAX_NERR Then
p_lngHwndModule = LoadLibraryEx(lpLibFileName:="netmsg.dll", _
hFile:=0&, _
dwFlags:=LOAD_LIBRARY_AS_DATAFILE)
If p_lngHwndModule <> 0 Then
p_lngFlags = FORMAT_MESSAGE_FROM_SYSTEM Or _
FORMAT_MESSAGE_IGNORE_INSERTS Or _
FORMAT_MESSAGE_FROM_HMODULE
/' ------------------------------------
/' Allocate the string, then get the
/' system to tell us the error
/' message associated with this error number
/' ------------------------------------
p_strBuffer = String(256, 0)
FormatMessage dwFlags:=p_lngFlags, _
lpSource:=ByVal p_lngHwndModule, _
dwMessageId:=ErrorCode, _
dwLanguageId:=0&, _
lpBuffer:=p_strBuffer, _
nSize:=Len(p_strBuffer), _
Arguments:=ByVal 0&
/' ------------------------------------
/' Strip the last null, then the last
/' CrLf pair if it exists
/' ------------------------------------
p_strBuffer = Left(p_strBuffer, InStr(p_strBuffer, vbNullChar) - 1)
If Right$(p_strBuffer, 2) = Chr$(13) & Chr$(10) Then
p_strBuffer = Mid$(p_strBuffer, 1, Len(p_strBuffer) - 2)
End If
FreeLibrary hLibModule:=p_lngHwndModule
End If
/' ------------------------------------------
/' Separate handling for Wininet error
/' Wininet.dll
/' ------------------------------------------
ElseIf ErrorCode >= INTERNET_ERROR_BASE And _
ErrorCode <= INTERNET_ERROR_LAST Then
/' ---------------------------------------
/' Load the library
/' ---------------------------------------
p_lngHwndModule = LoadLibraryEx(lpLibFileName:="Wininet.dll", _
hFile:=0&, _
dwFlags:=LOAD_LIBRARY_AS_DATAFILE)
If p_lngHwndModule <> 0 Then
p_lngFlags = FORMAT_MESSAGE_FROM_SYSTEM Or _
FORMAT_MESSAGE_IGNORE_INSERTS Or _
FORMAT_MESSAGE_FROM_HMODULE
/' ------------------------------------
/' Allocate the string, then get the
/' system to tell us the error
/' message associated with this error number
/' ------------------------------------
p_strBuffer = String(256, 0)
FormatMessage dwFlags:=p_lngFlags, _
lpSource:=ByVal p_lngHwndModule, _
dwMessageId:=ErrorCode, _
dwLanguageId:=0&, _
lpBuffer:=p_strBuffer, _
nSize:=Len(p_strBuffer), _
Arguments:=ByVal 0&
/' ------------------------------------
/' Strip the last null, then the last
/' CrLf pair if it exists
/' ------------------------------------
p_strBuffer = Left(p_strBuffer, InStr(p_strBuffer, vbNullChar) - 1)
If Right$(p_strBuffer, 2) = Chr$(13) & Chr$(10) Then
p_strBuffer = Mid$(p_strBuffer, 1, Len(p_strBuffer) - 2)
End If
FreeLibrary hLibModule:=p_lngHwndModule
End If
/' ------------------------------------------
/' Wasn/'t Wininet or NetMsg, so do the standard
/' API error look-up
/' ------------------------------------------
Else
/' ---------------------------------------
/' Allocate the string, then get the system
/' to tell us the error message associated
/' with this error number
/' ---------------------------------------
p_strBuffer = String(256, 0)
p_lngFlags = FORMAT_MESSAGE_FROM_SYSTEM Or _
FORMAT_MESSAGE_IGNORE_INSERTS
FormatMessage dwFlags:=p_lngFlags, _
lpSource:=ByVal 0&, _
dwMessageId:=ErrorCode, _
dwLanguageId:=0&, _
lpBuffer:=p_strBuffer, _
nSize:=Len(p_strBuffer), _
Arguments:=ByVal 0&
/' ---------------------------------------
/' Strip the last null, then the last CrLf
/' pair if it exists
/' ------------------------------------------
p_strBuffer = Left(p_strBuffer, InStr(p_strBuffer, vbNullChar) - 1)
If Right$(p_strBuffer, 2) = Chr$(13) & Chr$(10) Then
p_strBuffer = Mid$(p_strBuffer, 1, Len(p_strBuffer) - 2)
End If
End If
/' ------------------------------------------
/' Set the return value
/' ------------------------------------------
ReturnApiErrString = p_strBuffer
End Function