How Can I Change the Caption for the My Computer Icon?
Hey, Scripting Guy! Instead of having the My Computer icon on the desktop read My Computer, I’d like to replace that with the name of the computer. Can I do that using a script?
Hey, TG. We get asked this question quite a bit; apparently a lot of you find it convenient to have the computer name right on the desktop, making it easier for users to know which computer they’re logged on to. If you’d like to automate the process of changing the caption for the My Computer icon, all you need to do is run a script like this one:
Const MY_COMPUTER = &H11&
Set objNetwork = CreateObject(“Wscript.Network”) strComputer = objNetwork.ComputerName Set objShell = CreateObject(“Shell.Application”) Set objFolder = objShell.Namespace(MY_COMPUTER) Set objFolderItem = objFolder.Self objFolderItem.Name = strComputer
This script begins my declaring a constant named MY_COMPUTER and setting the value to &H11&; this is the value used by the Windows Shell object to locate My Computer. We then use these two lines of code to determine the name of the local computer and store that name in the variable strComputer:
Set objNetwork = CreateObject(“Wscript.Network”) strComputer = objNetwork.ComputerName
So far, so good, right? Next, we create an instance of the Shell Application object, and use the Namespace method to bind to the special folder that corresponds to My Computer. We then bind to My Computer’s FolderItem object using this line of code:
Set objFolderItem = objFolder.Self
After we bind to the FolderItem, we have access to folder properties like, well, the folder’s name. To set the caption for My Computer to the name of the computer we simply set the name property to strComputer, the variable containing the computer name:
objFolderItem.Name = strComputer
Just like that, the caption will change, not only for the desktop icon, but also for the My Computer link in the Start menu.
If you decide later on to change the caption back to My Computer, you can always run this script:
Const MY_COMPUTER = &H11&
Set objShell = CreateObject(“Shell.Application”) Set objFolder = objShell.Namespace(MY_COMPUTER) Set objFolderItem = objFolder.Self objFolderItem.Name = “My Computer”
Remember, this does not change the name of your computer, it only changes the caption for the My Computer special folder. Renaming a computer is whole ‘nother story, one we’ll have to deal with some other time. You might note, too that even though we change the caption from My Computer to, say, atl-ws-01, our Shell Application scripts can still find the My Computer special folder without any problem. That’s because the scripts don’t locate My Computer using the string value My Computer, but instead locate the special folder using the constant &H11&.