Check operating system in Vim

In Vim configuration files like vimrc or Vim scripts it might be necessary to know what is the operating system that Vim is running on. This can be done by checking for the feature that matches the operating system.

For example, Vim running on Linux will have its unix feature turned on. On Windows, it might have its win32 or win64 feature turned on. These features can be checked in Vim easily or tested in Vim scripts using the has function.

Tried with: Vim 7.3

How to share folder from Windows to Ubuntu in VirtualBox

On Windows, I sometimes run Ubuntu inside a VirtualBox virtual machine. I find that sharing a folder from Windows to Ubuntu is a convenient method of sharing files between the host and guest OS. Doing this is easy:

  • Install Guest Additions on the Ubuntu virtual machine.

  • Add your user to the group vboxsf in the Ubuntu VM:

$ sudo adduser yourusername vboxsf 
  • Power down the Ubuntu virtual machine.

  • In VirtualBox, right-click on the Ubuntu virtual machine and choose Settings → Shared Folders.

  • Choose Add Share. Choose the Folder Path to the directory you want to share. Note down the Folder Name displayed. This name will be used inside Ubuntu, so change it if you want. Check the Auto-mount option to have Ubuntu mount this directory whenever it starts up.

  • Power up the Ubuntu virtual machine. Your foo shared folder will be accessible in /media/sf_foo directory.

Tried with: Ubuntu 12.04 x64, Windows 7 Enterprise x64 and VirtualBox 4.2.0

Install Guest Additions to Ubuntu on VirtualBox

Installing Guest Additions

Guest Additions are drivers and applications of VirtualBox that can be installed to the guest operating system to enable new features and improve performance. Installing Guest Additions to Ubuntu running inside VirtualBox on Windows is easy.

  1. Start your Ubuntu image in VirtualBox. Login to your Ubuntu account.

  2. From the VirtualBox toolbar choose Devices → Install Guest Additions.

  3. VirtualBox mounts a CD of drivers and applications. Ubuntu asks for permission to autorun this CD. Allow it to run. If it does not autorun, go to /media/joe/VBOXADDITIONS directory and run sudo ./VBoxLinuxAdditions.sh.

  4. The tools from the CD are compiled and installed on Ubuntu. Ideally there should be no problems here and the install finishes.

  5. A driver icon might appear in the Ubuntu notification area. Open it. You might see a driver named Oracle VM VirtualBox Guest Additions for Linux Module. Activate it.

  6. Open the Ubuntu file manager. Unmount the Guest Additions CD.

  7. Restart Ubuntu in VirtualBox.

Tried with: Ubuntu 12.04 x64, Windows 7 Enterprise x64 and VirtualBox 4.2.0

How to unblock a downloaded file in Windows?

Unblocking a blocked file

Problem

As a security feature, Windows blocks the opening or execution of any file downloaded from the Internet. This can sometimes cause problems in other programs that use these files.

Solution

Unblocking a blocked file is pretty easy. Right-click on the file and choose Properties from the context menu. In the General tab, click on the Unblock button at the bottom and click Apply.

Tried with: Windows 8 Pro x64

How does Windows block files downloaded from the Internet?

Windows blocks execution of downloaded files.

Windows warns you if you try to open or execute a file that you downloaded from the Internet. This is a security feature of Windows that helps avoid execution or propagation of malicious files.

This is possible because applications, like the browser, use the Windows API to save files from the Internet. Windows invokes the Attachment Execution Service when such an API is called. This service adds a Zone Identifier stream to the saved file. Later when the file is opened or executed by Explorer, it sees this stream and warns the user about the file. Such a file is said to be blocked by Windows.

Reference: Page 427 of Windows Internals (6 Edition) Part 2

How to delete a symbolic link in Windows

A symbolic link can be created at the command-line using the mklink command of the command prompt.

To delete a symbolic link to a file use the del command:

del Foo.txt

To delete a symbolic link to a directory use the rmdir command:

rmdir Foo

Unlike creation of symbolic links, deletion of a symbolic link does not require Administrator privilege. It can be performed from a normal command prompt without elevated privileges.

Tried with: Windows 8 Pro

How to a create symbolic link in Windows

A shortcut in Windows is just a .lnk file that is created and used by Windows Explorer. In contrast to that, a symbolic link is an alias for a file or a directory that is created in the filesystem.

In Windows, symbolic links are only supported on NTFS, not on FAT or FAT32 filesystems. Symbolic links can be created at the command-line using the mklink command of the command prompt.

To create a symbolic link to the file Hello.txt named Foo.txt:

mklink Foo.txt Hello.txt

To create a symbolic link to the directory Hello named Foo:

mklink /d Foo Hello

Creating symbolic links requires Administrator privilege by default. So, open a command prompt with elevated privileges to try these commands.

Tried with: Windows 8 Pro

Scroll window under mouse cursor using KatMouse

KatMouse

Windows has this irritating behaviour: rolling the mouse wheel scrolls the window that is in focus, and not the window that is under the mouse cursor. This can be fixed easily by using KatMouse, which enables the latter behaviour without changing the original window focus.

By default, KatMouse assigns the scroll button press to some other functionality. This is also irritating because I use the scroll button press to close tabs in browsers and other software. So, it might be a good idea to turn off this feature. To do that, open the KatMouse properties by right-clicking its icon in the system tray. Go to Wheel Button and choose None of the buttons as push button.

Tried with: KatMouse 1.04 and Windows 7 x64

Switch between network settings easily with NetSetMan

NetSetMan is an excellent Windows tool to have on your computer if you need to change network settings frequently. Going through the Windows network connection dialogs to change the IP or DNS addresses or other settings frequently is a real pain. NetSetMan allows you to maintain six different profiles, each with all possible network settings, and switch between them in a click. I am finding it a boon to switch between DHCP and static IP addresses when I switch my notebook between two different wireless networks.

Tried with: NetSetMan 3.4.5

How to access Windows shared folder from Raspbmc

Raspberry Pi running Raspbmc is an awesome HTPC. If you have videos, music or photos on one of your home Windows computers, then it might be convenient to access or view the media right from your Raspbmc over the home network. The easiest way to do this is to share the media files in a Windows shared folder and access that from Raspbmc using SMB. I am assuming that the Windows computer and Raspbmc are connected to the same wireless router or the same home network.

First setup the Windows computer:

  1. Your Raspbmc will access your Windows computer using its IP address. So, it might be convenient to configure a static IP address for the Windows computer. In any case, note down the IP address of the Windows computer.
  2. Create a folder and make sure the folder name has no spaces in it. Drop all the media files you want to share into this folder. Make it a shared folder. Add Everyone as a user who has read access to this folder.

Next setup the Raspbmc to access the shared folder:

  1. Make sure you can ping the Windows computer from the Raspbmc. You can do this by SSH to Raspbmc (here is how) and pinging the IP address of the Windows computer.
  2. Assuming you want to access the video files in the shared folders. In XBMC, go to Videos > Files > Add videos > Browse > Add network location.
  3. In the Add network location dialog, choose Protocol as Windows network (SMB). For Server name enter the IP address of the Windows computer. For Shared folder enter the name of the shared folder on the Windows computer. Fill the Username and Password fields with the credentials of a user on your Windows computer. Press OK.
  4. The Windows computer shared folder now appears in the listing, choose OK. Press OK in the next dialog. Now the shared folder is visible in the Files listing and you should be able to browse through the media files inside it and play them whenever needed.

Have fun playing the content from your Windows computer on your Raspbmc 🙂

Tried with: Windows 7 (64-bit) and Raspbmc RC4