How can I automatically rename the My Computer desktop icon so that it includes the host name?

A. The following code renames the My Computer icon on the desktop to "My Computer <hostname>". You can run the code as a domain-level logon script or call it from another script.

option explicit

dim objNetwork, objShell, strComputer, objFolder, objFolderItem
Const MY_COMPUTER = &H11&

Set objNetwork = CreateObject("Wscript.Network")
Set objShell = CreateObject("Shell.Application")

strComputer = objNetwork.ComputerName

Set objFolder = objShell.Namespace(MY_COMPUTER)
Set objFolderItem = objFolder.Self
objFolderItem.Name = "My Computer " & strComputer

You can change the last line to be any text that you want to use for the My Computer icon. It doesn't need to begin with My Computer.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish