Tuesday, May 18, 2010

Disable autorun on USB drives in Windows

Nowaday most USB drives contain viruses, believe it or not. And usually these malware exploit the Autorun feature to spread from thumb drive to PC. Disable the autorun feature to prevent malware from spreading.

There are three ways to disable autorun in Windows.
  1. Group Policy Editor
    • Click "Start"->"Run", type in "gpedit.msc"
    • Group Policy Editor is prompted, goes to
      Computer Configuration->Administrative Templates->System

      , see screen shot Group Policy Editor
    • On the right, scroll down to “Turn off Autoplay” and double click on it
    • Set the radio button to Enabled, and change the “Turn off Autoplay on” to All Drives. See screen shot Turn off Autoplay
  2. Registry method 1
    • Go to "Start"->"Run", type regedit
    • In registry manager, browse to "HKEY_CURRENT_USER\Software\Microsoft\Windows\ CurrentVersion\Policies\Explorer". If you have admin privilege, you can modify the same key in HKEY_LOCAL_MACHINE
    • Modify the value of NoDriveTypeAutoRun to ff (hexadecimal)
  3. Registry method 2
    • This method requires users can access to modify registry in HKEY_LOCAL_MACHINE
    • Bring up regedit and browse to "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\IniFileMapping\"
    • If key "Autorun.inf" doesn't exist, create it
    • Create a string value "@" as "@SYS:DoesNotExist"
Download this reg file DisableAutorun.reg and double click to set the above registry trick.

Windows logon takes a long time

I have encountered this problem when configuring new machines to join a domain. The problem occurs when you try to log on to a computer which just restarted after joining to a domain, then you click the drop down menu to change the logon domain, a dialog is prompted: “Please wait while the domain list is created” and it hangs on forever.

To come out of the waiting loop, just press Ctrl-Alt-Del, select the desired domain, then the dialog is prompted again and press Ctrl-Alt-Del again to type in password to log in to that domain.

Basically the problem is a DNS issue. If the DNS of the system is not pointing to the DNS Server which includes a record of the domain, then it hangs on and does nothing. This is usually the case if we specify the DNS server as public internet servers rather than our own internal domain DNS server. So to solve this problem, just logon with the local administrator account and change the DNS address to the one which specifiesthe domain in its records.

Monday, May 10, 2010

how to minimize a c# .net windows application to system tray

First you need to add a NotifyIcon (ie, object notifyicon1) to your form, set the default Visible property to be false.


Add a Form_Resize event handler to the form.

private void Form_Resize1(object sender, System.EventArgs e)
{
   if(this.WindowState == FormWindowState.Minimized)
   {
     this.Visible = false;
     notifyIcon1.Visible = true;
   }
}

 

Then add an event handler to the NotifyIcon (usually double click) with this code:

 

this.Visible = true;

notifyIcon1.Visible = false;

 

This article from Microsoft is also helpful: http://code.msdn.microsoft.com/TheNotifyIconExample

 

Will talk about minimizing native win32 app into tray next time.