Convert Windows shortcuts into Ubuntu shortcuts

Posted by Michael Giarlo on October 29, 2008

[Update: Feel free to grab the code via bzr with bzr branch http://lackoftalent.org/bzr/shortcut_converter.]

Here's another entry in the "dumb little scripts that work for me and may or may not be helpful to other folks" department…

I use both Windows and Ubuntu at home, gradually transitioning from the former to the latter. I've accumulated a bunch of Windows URL shortcuts, mostly things I wanted to read once so instead of bookmarking them, I dragged their links to my desktop. This creates .URL files which are simple little plain-text two-liners. It turns out that on Ubuntu, and probably similar *nix systems, web shortcuts are also simple little plain-text files. These files have the .desktop extension (though you won't see the extension by looking at the desktop).

I wanted a way to convert my .URL files to .desktop files so that I can just toss them on my Ubuntu desktop and double-click them the same way I would if I were on Windows. This cruddy little Python script does the trick.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
# shortcut_converter.py
 
from __future__ import with_statement 
import os.path
import sys
 
TEMPLATE = """[Desktop Entry]
Version=1.0
Encoding=UTF-8
Name=%(basename)s
Type=Link
URL=%(url)s
Icon=gnome-fs-bookmark
"""
 
def convert(f):
    """ Takes a full filepath to a .URL file, converts it to a .desktop file 
        in the same directory """
    print "Converting %s" % f
    (filepath, filename) = os.path.split(f)
    (basename, extension) = os.path.splitext(filename)
    with open(f) as urlfile:
        lines = [line.strip() for line in urlfile.readlines()]
    url = lines[1].split('URL=')[1]
    dtfname = os.path.join(filepath, '%s.desktop' % basename)
    with open(dtfname, 'w') as dtfile:
        print "Writing %s" % dtfile.name
        dtfile.write(TEMPLATE % locals())
 
if __name__ == '__main__':
    for arg in sys.argv[1:]:
        if os.path.isfile(arg) and arg[-3:].lower() == 'url':
            convert(arg)
        else:
            print "*** %s is not a URL file" % arg

I used scp to pull over all my .URL files and then invoked the script thusly:

python shortcut_converter.py *.URL

worksforme!

Using Linux to fix Windows

Posted by Michael Giarlo on October 13, 2007

The hard drive on my laptop is slowly failing and a combination of being busy, lazy, and cheap is preventing me from replacing it. About once every two weeks over the past couple months, one of the Windows registry files becomes corrupted and the XP disk is unable to repair it. And the HD fails basic manufacturer-provided diagnostics. But I'm stubborn. So I've been routinely resuscitating this box and I decided to post the process I use.

If you boot and see a message like

Windows could not start because the following file is missing or corrupt
C:\windows\system32\config\system

then you may be interested in this.
Continue reading…

"Local Service" Services Dying Repeatedly?

Posted by Michael Giarlo on March 09, 2006

One of my Windows 2003 servers began exhibiting very strange behavior a few months ago.  That a Windows server behaves badly isn't strange, of course, but I'd never before encountered precisely this problem.  I searched and searched for solutions on Google, but could not find one that worked for me (though I did discover that a handful of others reported having very similar issues).  Since I've gotten so much help from the web (via Google) before, I figured I would pay back my debt by posting the solution I found this afternoon.  Your kilometerage may vary.

Problem

Services which log on as LocalService*, as opposed to LocalSystem and NetworkService, die repeatedly and at regular intervals.  In my case, it was every 90 seconds give or take 5.  I believe Windows 2003 and XP use the LocalService and NetworkService accounts for running services, so this may not apply to Windows 2000 or other versions of Windows. 

* Some of these services are Windows Time, TCP/IP NetBIOS Helper, Remote Registry, Application Layer Gateway Service, Alerter, Smart Card, SSDP Discovery Service, Universal PnP Device Host, WebClient, and Windows User Mode Driver Framework. 

Solution

Disable WINEXIT.SCR screensaver within any relevant user accounts, e.g., Default User, All Users, or any service account.  You can run a search in regedit for the string "winexit.scr" to turn up all such values and determine which are relevant.  The value I needed to delete was in HKEY_USERS/.DEFAULT/Control Panel/Desktop/SCRNSAVE.EXE.

Explanation

The server in question is to be used for public terminal services, so I intended to use the winexit.scr screensaver as a relatively lightweight, easy way to ensure that users get warned about idle time and subsequently logged off after a preset period of time.  There are other ways of accomplishing this, to be sure, but I've always had good experiences with winexit.scr.  At any rate, while watching the list of processes in Task Manager, I noticed that about every minute-and-a-half, a winexit.scr process popped up and, more interestingly, was running in the LocalService context.  Lightbulb!

Services running under LocalService are all launched via the svchost.exe binary that is included with Windows, and it turns out that the winexit screensaver kept shutting down these services (as I unwittingly instructed it to do) when they took advantage of their ability to log on as a service.  Why every 90 seconds?  I had winexit configured to allow only 60 seconds of idle time, and it gives the user 30 seconds of warning before killing a session. 

It's almost as though computers are logical.  I just love when problems make sense.

Access-based Enumeration & Windows Server 2003 R2

Posted by Michael Giarlo on December 08, 2005

As of the SP1 release, Windows Server 2003 now supports access-based enumeration of file shares. Basically, files and folders to which users lack access will not be visible within file shares. No more double-clicking shared resources only to be greeted with "Access denied." This is quite a nice feature, and one which is long overdue.

http://www.microsoft.com/windowsserver2003/techinfo/overview/abe.mspx

Also, the new release of Windows Server 2003 R2 appears to have a number of new features that were not included in SP1 (and that probably will not be featured in SP2). As far as I can figure out, R2 is related to 2003 SP1 as NT4 Option Pack was related to NT4.

http://www.microsoft.com/windowsserver2003/r2/whatsnewinr2.mspx

Windows Server 2003 still dependent upon WINS / NetBIOS?

Posted by Michael Giarlo on December 07, 2005

Perhaps I am mistaken, but I thought one of the biggest purported benefits of the newest incarnation of Active Directory was its supposed reliance upon the more commonly used DNS system for computer name lookups rather the old WINS and NetBIOS lookup system. I've recently installed a new server running Windows Server 2003 Enterprise and hooked it into our Active Directory 2003 domain and configured it to run Terminal Services. Upon this assumption, I disabled NetBIOS in the TCP/IP stack and turned off the TCP/IP NetBIOS Helper service.

When I connect to the server via Remote Desktop and login with a local administrative account, I get in just fine. When I specify my domain credentials, however, my connection is refused because Terminal Services apparently has problems reaching the RPC Server. Says it is unavailable. Turning back on the NetBT Helper service clears this up, but I did not think NetBIOS would be required for name resolution given AD integration with DNS. In the eventlog, TS shows the following error after the "RPC Server is unavailable" error: "Unable to obtain Terminal Server User Configuration".

Any ideas? I'm alright with leaving on the NetBT service, but I just don't understand why it's necessary.

I have tried re-enabling NetBIOS in the stack and that has zero effect on the connection behavior. I have also checked the DNS settings and the AD domain name is in the list of default domains to search through.

NOTE: Perhaps it is due to having external University DNS servers listed instead of the AD DNS servers. Come to think of it, I'm not sure why we would be using external DNS servers if we run AD. Giving this a try.

ADDENDUM: Apparently our AD servers do not run their own DNS; the records are offloaded to the campus DNS system. Perhaps this is the culprit?