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.

 

Friday, April 30, 2010

How to convert cvs to svn

There are many posts available online about how to convert cvs to svn, however some steps seem to have been skipped. I did the conversion on Ubuntu, using the famous cvs2svn. 
If you have to convert the code in Windows, see this: convert cvs to svn using Cygwin

Here are some dummy steps:


1. Download and install cvs2svn, for more information (ie requirements, etc), see http://cvs2svn.tigris.org/cvs2svn.html.
Ideally you shall have a unix/linux environment with Python, cvs, svn installed.

2. install cvs, svn and svnserve

3. Create a folder (namely CVS) at your desired location

4. Set CVSROOT to this folder, you need to set with aboslute path. ie, export CVSROOT=/home/guest/CVS

5. then run "cvs init", now CVS has been set as a cvs repository, you will see a CVSROOT folder under CVS

6. run "cvs2svn --fallback-encoding=ansii -s SVN_PATH CVS", where SVN_PATH is the path for your SVN repository. "--fallback-encoding=ansii" is needed in case cvs2svn fails to convert the log messages into UTF8(default).

7. go to SVN/conf, update svnserve.conf - uncomment out
# anon-access = read
# auth-access = write
# password-db = passwd

update passwd, ie,
[users]
leon=theprogrammer
guest=1234

DO NOT leave space in the name and password, otherwise your SVN clients may deny your credentials.

8. start svnserve to the SVN repository. run "svnserve -d -r SVN", where SVN is the path of your SVN repository.

9. Point your svn client to svn://servername/SVN, you shall be prompted to log in, then you shall see the repository.



This book might be helpful: Pragmatic Guide to Subversion



ReadDirectoryChangesW returns ERROR_BAD_NET_RESP (error code 58)


A recent project is about folder monitoring. The folder can be on a local hard drive or a network. We use the standard win32 api call: ReadDirectoryChangesW.
The function works perfectly on a remote WinNT system but occasionally fails on mornitoring a folder in a remote Unix system. At the beginning we suspect if a correct (or high enough) version of samba is install on that Unix machine, but confirmation is positive. Besides the function call does not fail consistently, which really bothers us. However, the last error code from ReadDirectoryChangesW is always 58 – ERROR_BAD_NET_RESP (The specified server cannot perform the requested operation).
I suspect it is an unsupported isssue, the latest Samba patch does not full support ReadDirectoryChangesW yet. There are few articles can be found from google, links:
The solution
The loop to check ReadDirectoryChangesW does not break if last error is ERROR_BAD_NET_RESP, continue process directory changes if it fails. The interesting thing is the next ReadDirectoryChangesW call could succeed following previous failure. So eventually we capture the directory changes and process it approprietly.
The ideal solution is a samba fully support ReadDirectoryChangesW

The power of habit

A friend of mine recommended this book 'The power of habit' (习惯的力量). I love it, although the one I read is in Chinese. We act upon our habit in as much as 90% of time daily, if we can keep good habits, abandon bad ones, we will be surely moving forward to success sooner.

An interesting book to read indeed, highly recommended. The Power of Habit: Harnessing the Power to Establish Routines that Guarantee Success in Business and in Life