Friday, June 10, 2011

VB.Net code to control mouse movement and click

VB.Net code to perform mouse movements and clicks.

Include references at the top of the class code file to Windows interface libraries:

Public Declare Auto Function SetCursorPos Lib "User32.dll" (ByVal X As Integer, ByVal Y As Integer) As Integer
Public Declare Auto Function GetCursorPos Lib "User32.dll" (ByRef lpPoint As Point) As Integer
Public Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)

Some fixed constant values will be needed, so include these as basic names:


This provides three types of capabilities to move the mouse pointer, determine the mouse pointer location and to perform click events.

Set the mouse position on the screen:
Dim X As Integer, Y As Integer
X = 428
Y = 256
SetCursorPos(X, Y)

Get the mouse position on the screen:
Dim lpPoint As Point
X = lpPoint.X
Y = lpPoint.Y
System.Diagnostics.Debug.WriteLine(String.Format("X: {0}, Y: {1}", X, Y)) 'output the current position to the debug window

Lastly, perform click operations, notice that a complete click is a "down" followed by "up" action, otherwise you're holding down the click button:
Call mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
Call mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)

Monday, April 18, 2011

I Don't Need No Stinking Antivius -- But Will You Please Get It?

People often ask me what antivirus I use. The answer is that I don't use any AV. I typically know the metrics on what my programs are doing, so viruses aren't something I tend to get.

Don't get me wrong; there are a few times I've been exposed to malware, but I had put myself in a risky position and knew what to expect from it. Downloading music or alternative software are both prime examples of such situations. When viruses run amok throughout a computer system, it’s imperative to know how to seek and destroy the many tentacles with which it can take hold. It's actually kind of fun not only to kill, but to observe the hacking creativity (I have a small collection of well designed viruses).

There are some nasty programs out there. It’s important to act very quickly upon getting infected with a virus or malware because it could start transferring private files to the net almost immediately. To make matters worse, once a single piece of malware makes it through, it very often creates a backdoor that provides easy access for other hostile programs, and the scenario inevitably repeats itself. I've cleaned a few systems with literally 100+ virus processes running.

If you install Windows XP out of the box, you can get a virus by visiting a basic website and not even clicking on anything (trust me; I've even experienced it from my own website). To prevent most of the bad stuff, you should run Windows Update (or automatically enable to download) since the folks at Microsoft are pretty much on the forefront of security patches.

Should you come down with an unfortunate case of sporadic applications, browser pop-ups or some other malware, you need to be quick to disable the network adapter and kill the processes. On one occasion, I had to pull the plug on my system as a rouge process was maliciously wiping data files.

I take the care and tending of my system resources very personally and don't want my programs running amuck. I consider AV programs, like Norton, one of the worst offenders. That having been said, please take note that I am a power user and I oversee a farm of web and database servers for my local SEO company- I use hotkeys everywhere, I've created macros to do repetitive tasks and I program automation processes to accelerate and interoperate.

The problem with AV programs is that they operate by constantly scanning inputs & outputs of all your files and internet activity. This adds processing time and latency in just about everything you do. In most situations, this is may be a minor resource utilization and probably goes unnoticed by most users; nevertheless, it’s a burden I'm not inclined to accept. However, unless are prepared to a) avoid malware in the first place, and b) are capable of completely cleaning up something that may have slipped in, then I'd strongly recommend you use AV software.

About a month ago, I was (un)lucky enough to be part of the 0.02% of Google users affected with an outage. Accidents do happen, and antivirus software is like an insurance policy. In fact, if you get a virus on your system, it can often spread to your local and office networks. Nothing is worse than having your co-worker’s computer contaminate the network! So for the other 99.98% of internet users, I recommend you get a solution in place.

If I ever have an AV program installed on my system, I will disable all active monitoring of said program and enable it to perform detection only when I ask it to do so. I personally like to use Microsoft Defender and legacy versions of AdAware (before they went commercial), both of which I've linked on the side of my blog. A nice feature about periodically running AV programs is that they can scan and cleanse unnecessary objects, such as clear wasted registry pointers & marketing/tracking cookies.

Malware Prevention Tips:

  • Don't Click. Just Close It-- when you're prompted with something that you don't want, clicking on anything, even something that looks like "Cancel" or "No" might be a trick. Instead, hit the Escape button, Ctrl-W (a switch to shutdown a browser tab), or Alt-F4 (close application).
  • Keep Windows Patched -- visit if you’re not sure.
  • Use Google Chrome or Firefox – both are resilient, yet functional, browsers. Stay far away from Internet Exposer.

Dealing With Malware:

· Disconnect -- pull the network plug or shutdown your wi-fi. That tends to stop most popup based ads.

· Ctrl-Alt-Del -- Open Task Manager and look at the list of processes, sorted by CPU desc. Take note of oddly named processes that you don't see on other computers (call a nerdy friend and ask them to compare). Kill any suspicious ones. If they come back alive, you may need more professional help.

· Run AV -- hopefully you've contained the malware, now eradicate it with Microsoft Defender, AVS, AdAware or your $60 Fry's special software.

· (advanced) -- Seek and Destroy yourself by performing tricks such as: deleting or renaming the malware file, opening Regedit and searching for the process.

Share Links