خاموش، لوگ آف یا استند بای کردن ویندوز
یک کلاس Power Off ویندوز با چندین قابلیت جالب. علاوه بر کارکردهای معمولی، میشه از اون به عنوان سر به سر گذاشتن کاربران هم استفاده کرد :46: ( البته توصیه نمیکنم )
کد:
Public Class Win_ShutDown
Public Enum shutdownTypes
Logoff = 0
Shutdown = 1
Reboot = 2
Force = 4
PowerOff = 8
End Enum
Private Structure LUID
Dim UsedPart As Integer
Dim IgnoredForNowHigh32BitPart As Integer
End Structure
Private Structure TOKEN_PRIVILEGES
Dim PrivilegeCount As Integer
Dim TheLuid As luID
Dim Attributes As Integer
End Structure
Private Declare Function ExitWindowsEx Lib "user32" (ByVal shutdownType As Integer, ByVal dwReserved As _
Integer) As Integer
Private Declare Auto Function InitiateSystemShutdownEx Lib "Advapi32.dll" (ByVal lpMachineName As _
String, ByVal lpMessage As String, ByVal dwTimeout As Integer, ByVal bForceAppsClosed As Boolean, _
ByVal bRebootAfterShutdown As Boolean, ByVal dwReason As shutdownReason) As Boolean
Public Enum shutdownReason
SHTDN_REASON_MAJOR_APPLICATION = &H40000 'Application issue.
SHTDN_REASON_MAJOR_HARDWARE = &H10000 'Hardware issue.
SHTDN_REASON_MAJOR_LEGACY_API = &H70000 'The InitiateSystemShutdown function was used instead of InitiateSystemShutdownEx.
SHTDN_REASON_MAJOR_OPERATINGSYSTEM = &H20000 'Operating system issue.
SHTDN_REASON_MAJOR_OTHER = &H0 ' Other issue.
SHTDN_REASON_MAJOR_POWER = &H60000 'Power failure.
SHTDN_REASON_MAJOR_SOFTWARE = &H30000 'Software issue.
SHTDN_REASON_MAJOR_SYSTEM = &H50000 'System failure
End Enum
Public Enum shutdownMethodToExecute
ExitWindowsExAPI = 1
ProcessShellMethod = 2
End Enum
Private Declare Auto Function AbortSystemShutdown Lib "Advapi32.dll" (ByVal lpMachineName As String) _
As Boolean
Private Declare Function OpenProcessToken Lib "advapi32" (ByVal ProcessHandle As IntPtr, ByVal _
DesiredAccess As Integer, ByRef TokenHandle As Integer) As Integer
Private Declare Function LookupPrivilegeValue Lib "advapi32" Alias "LookupPrivilegeValueA" (ByVal _
lpSystemName As String, ByVal lpName As String, ByRef lpLuid As LUID) As Integer
Private Declare Function AdjustTokenPrivileges Lib "advapi32" (ByVal TokenHandle As Integer, ByVal _
DisableAllPrivileges As Boolean, ByRef NewState As TOKEN_PRIVILEGES, ByVal BufferLength As _
Integer, ByRef PreviousState As TOKEN_PRIVILEGES, ByRef ReturnLength As Integer) As Integer
Private Declare Function SHShutDownDialog Lib "shell32" Alias "#60" (ByVal notSureYet As Integer) As Integer
Private Sub AdjustToken()
Const TOKEN_ADJUST_PRIVILEGES As Int32 = &H20
Const TOKEN_QUERY As Int32 = &H8
Const SE_PRIVILEGE_ENABLED As Int32 = &H2
Dim hdlProcessHandle As IntPtr
Dim hdlTokenHandle As Int32
Dim tmpLuid As LUID
Dim tkp As TOKEN_PRIVILEGES
Dim tkpNewButIgnored As TOKEN_PRIVILEGES
Dim lBufferNeeded As Int32
hdlProcessHandle = Process.GetCurrentProcess.Handle
OpenProcessToken(hdlProcessHandle, (TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY), hdlTokenHandle)
LookupPrivilegeValue("", "SeShutdownPrivilege", tmpLuid)
tkp.PrivilegeCount = 1 'One privilege to set
tkp.TheLuid = tmpLuid
tkp.Attributes = SE_PRIVILEGE_ENABLED
AdjustTokenPrivileges(hdlTokenHandle, False, tkp, Len(tkpNewButIgnored), tkpNewButIgnored, _
lBufferNeeded)
End Sub
Public Function shutdownWindowsOS(ByVal shutdownType As shutdownTypes, Optional ByVal executeShutdownMethod As _
shutdownMethodToExecute = shutdownMethodToExecute.ExitWindowsExAPI) As Integer
Select Case executeShutdownMethod
Case shutdownMethodToExecute.ExitWindowsExAPI
AdjustToken()
Return ExitWindowsEx(shutdownType, Nothing)
Case Else
If shutdownType = shutdownTypes.Shutdown Then
Process.Start("shutdown -s -f -t 0")
'Shell("shutdown -s -f -t 0", , False, 0)
End If
If shutdownType = shutdownTypes.Reboot Then
'Shell("shutdown -r -f -t 0", , False, 0)
Process.Start("shutdown -r -f -t 0")
End If
If shutdownType = shutdownTypes.Logoff Then
'Shell("shutdown -l -f -t 0", , False, 0)
Process.Start("shutdown -l -f -t 0")
End If
End Select
End Function
Public Function initiateSystemShutdownDialog(Optional ByVal computerName As String = "", Optional ByVal _
shutdownMessage As String = "Computer needs to Shutdown", Optional ByVal shutdownTimeoutBySeconds _
As Integer = 10, Optional ByVal forceShutdown As Boolean = False, Optional ByVal _
rebootAfterShutdown As Boolean = True, Optional ByVal shutdownReason As shutdownReason = _
shutdownReason.SHTDN_REASON_MAJOR_APPLICATION) As Boolean
AdjustToken()
Return InitiateSystemShutdownEx(computerName, shutdownMessage, shutdownTimeoutBySeconds, _
forceShutdown, rebootAfterShutdown, shutdownReason)
End Function
Public Function cancelInitiatedShutdownDialog(Optional ByVal computerName As String = "") As Boolean
Return AbortSystemShutdown(computerName)
End Function
Public Function openTurnOffComputerDialog() As Integer
Return SHShutDownDialog(0)
End Function
End Class
پخش فرمتهای مختلف موزیک توسط وی بی
بوسیله این Dll به راحتی تمامی فرمتهای موزیک در وی بی، قابل پخش خواهد بود.
[html]http://rapidshare.com/files/48354393/Music_Library.dll.html[/html]
عیر فعال کردن دکمه Close فرم
برای این کار کافیست کد زیر رو در هر جایی از کد ادیتور که میخواهید بنویسید ( البته خارج از روال ها ) :
کد:
Private _closeClick AsBoolean
PublicConst SC_CLOSE AsInteger = 61536
PublicConst WM_SYSCOMMAND AsInteger = 274
ProtectedOverloadsOverridesSub WndProc(ByRef m As Message)
If m.Msg = WM_SYSCOMMAND AndAlso m.WParam.ToInt32 = SC_CLOSE Then
ExitSub
Else
Me._closeClick = True
EndIf
MyBase.WndProc(m)
EndSub
پیدا کردن آخرین کانکشنی که با آن به اینترنت وصل شده بودید
کد:
Dim
output AsString = ""
Dim msg AsString
Dim I AsInteger
Dim myEventLog AsNew EventLog
myEventLog.Log = "system"
I = myEventLog.Entries.Count - 1
While I >= 0
If myEventLog.Entries.Item(I).Source = "RemoteAccess"Then
msg = myEventLog.Entries.Item(I).Message
If InStr(msg, "successfully established") Then
output =
"You last connected to the network on: "
output &= myEventLog.Entries.Item(I).TimeWritten
msg = Mid(msg, InStr(msg,
"connection to") + 14)
msg = Microsoft.VisualBasic.Left(msg, InStr(msg, "using") - 2)
output &= vbNewLine & "The name of the connection used was: " & msg
ExitWhile
EndIf
EndIf
I -= 1
EndWhile
MsgBox(output)
EndSub