Sunday, May 11, 2014

Win7 access point

OK, this time, its slightly different. It is not about Linux, but about windows 7. I was looking into building an application for pebble watch and while reading about their cloud IDE, I came to know that I need to have both development PC and the Android phone need to be on same wifi network. However, my wifi router was dead long back and I was managing using ad-hoc networks between my laptops. (Well, I had taken over my wife's old laptop after I bought a new one for her and it was running win-7. Since display was dead for that laptop, I have hooked a LCD monitor to it and it was working as my wifi router in adhoc mode)

Now, it was definite that I need an AP at home and thought about buying one. Each one costed more than 1.5K INR or more. And, I had the bad experience of wifi on my D-Link DSL-2730U dying within 3 months of buying it. Actually, it did not die... but, the its dc adapter did and after a few months from replacing the original adapter with a local made one, I noticed that whole device kept rebooting if wifi was on. When the frequency of rebooting became really unbearable, I decided to move to my ad-hoc network. So, the bottom line is, even if I spent 1.5K, there is nothing that I can do for adapter which is not covered under warranty and so, I decided against buying it.

I then read about having the access point setup on the win7 machine. It was much easier than I thought. After a bit of searching on google, I came up with the following solution.

  • Start the command prompt as admin user (type cmd in search box and when cmd appears on top, right click and select run as)
  • The bellow commands will create an AP
    • netsh wlan set hostednetwork mode=allow "ssid=YourNwkName" "key=0Your1Secret3Key" keyUsage=persistent
    • netsh wlan start hostednetwork
  • Change SSID and KEY as per your choice
  • You can see the new virtual WIFI port and set it properties at the same location where you see the normal network adaptors. (Start -> run -> type "ncpa.cpl" sans quotes -> enter)
  • Right click on the adapter that is connected to internet and select properties
  • Select the sharing tab, enable it and select the home network as the newly created network
  • Windows will move home network to some vague IP address block that is not so common. You may change it by editing the IPv4 properties of that network
  • Install a dhcp server and configure it
    • I used the server from
    • The setup is explained at
    • However, I have briefly explained some points to take care below
    • It comes with a firewall, setup the firewall to allow access

Test your network and be satisfied that things work as expected. Now comes the interesting part. How do I turn on this stuff at start-up? Again came google to the rescue :)

  • Create a batch file to create and start hosted network (I saved it as startap.bat)
  • Add dhcp server startup also to it. Final script will look something like below
netsh wlan set hostednetwork mode=allow "ssid=YourNwkName" "key=0Your1Secret3Key" keyUsage=persistent
netsh wlan start hostednetwork
D:\dhcpserv\dhcpsrv.exe -ini D:\dhcpserv\dhcpsrv.ini -start
  • Download and install nssm and the batch script as a startup service to windows
    • I created a run.bat which contained the following line and executed it as administrator by right clicking it
      • D:\dhcpserv\nssm-2.21.1\nssm-2.21.1\win32\nssm.exe install apsrv
    • The above action will bring up a GUI and you can select bash script created in previous step (startap.bat) as the command to run
  • In your scripts, change the paths as per where you have installed dhcpsrv, 
Now a bit about dhcp configuration
  1. Set dns server and gateway
  2. Do remember to turn on firewall
  3. Save the configuration
(I wanted add a few screenshots... but now I am too sleepy...)