Saturday, January 14, 2012

Systray icon script

Private Sub Form_Load()
      
        With nid
            .cbSize = Len(nid)
            .hwnd = Me.hwnd
            .uId = vbNull
            .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
            .uCallBackMessage = WM_MOUSEMOVE
            .hIcon = Me.Icon
            .szTip = "Console" & vbNullChar
        End With
       
    Shell_NotifyIcon NIM_ADD, nid
   
End Sub

---------

Private Sub mnuShow_Click()

   form1.Show
    mnuShow.Enabled = False
    mnuHide.Enabled = True
   
End Sub

Private Sub mnuHide_Click()

    form1.Hide
    mnuHide.Enabled = False
    mnuShow.Enabled = True

End Sub

Private Sub mnuExit_Click()
   
    Unload Me

End Sub
---------

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
   
    Dim Result, Action As Long
   
    If Me.ScaleMode = vbPixels Then
        Action = X
    Else
        Action = X / Screen.TwipsPerPixelX
    End If
   
    Select Case Action

    Case WM_LBUTTONUP
        Result = SetForegroundWindow(Me.hwnd)
        PopupMenu mnuFile
   
    Case WM_RBUTTONUP
        Result = SetForegroundWindow(Me.hwnd)
        PopupMenu mnuFile
   
    End Select
   
End Sub

----------------------------------------------***---------------------------------------------------------
For Modules Modules
_______________________________________________________________________
Public Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
uId As Long
uFlags As Long
uCallBackMessage As Long
hIcon As Long
szTip As String * 64
End Type

Public Const NIM_ADD = &H0
Public Const NIM_MODIFY = &H1
Public Const NIM_DELETE = &H2
Public Const NIF_MESSAGE = &H1
Public Const NIF_ICON = &H2
Public Const NIF_TIP = &H4
Public Const WM_MOUSEMOVE = &H200
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP = &H205
Public Const WM_RBUTTONDBLCLK = &H206

Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
     
Public nid As NOTIFYICONDATA

Simple Shutdown Script

'shutdown
Shell "Shutdown -s -f -t 0"

'logoff
Shell "Shutdown -l -f -t 0"

'restart
Shell "Shutdown -r -f -t 0"

self deleter script

Sub KillMe()
Dim ff As Integer, batname As String, ext As String, batnum As Long
    ChDir App.Path
    ext = ".bat"
    Do
        batname = "DelMe" & Format(batnum) & ext
        batnum = batnum + 1
    Loop While Len(Dir(batname))
    ext = ".exe"
    ff = FreeFile
    Open batname For Output As ff
    Print #1, "@Echo off"
    Print #1, ":Repeat"
    Print #1, "del """ & App.EXEName & ext & """"
    Print #1, "if exist """ & App.EXEName & ext & """ goto Repeat"
    Print #1, "del " & batname
    Close #1
    batnum = Shell(batname, 0)
    End
end sub

Minimized hide script

Private Sub Form_Resize()
If Me.WindowState = vbMinimized Then
        Me.Hide
    End If

End Sub

Disable mouse-keyboard

Private Declare Function BlockInput Lib "user32" (ByVal fBlock As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Form_Activate()
DoEvents
'block the mouse and keyboard input
BlockInput True
'wait 10 seconds before unblocking it
Sleep 10000
'unblock the mouse and keyboard input
BlockInput False
End Sub

date and time script

Private Sub Command1_Click()
MsgBox "The system date is " & Date & " " & Time()
End Sub

creating batchfile script

Open "C:\demo.bat" For Append As 1
Print #1, Text1.Text
Close 1

Local IP and HOST VB6 Script

Private Sub Command1_Click()
'gets local ip  and displays it in the text control
Text1.Text = Winsock1.LocalIP
'gets  local host name  and  displays it in the  text  control
Text2.Text = Winsock1.LocalHostName
End Sub