Showing posts with label vbscript. Show all posts
Showing posts with label vbscript. Show all posts

12 September, 2010

Rename the desktop "My Computer" to pc name

Hi,

Using bginfo to add to the user desktop his workstation name ?
Why not just rename the "My Computer" text to the workstation name and that's it ?

2 ways to do it:
- Using VBS Script
- Using GPP

VBS Script:
===================================
Const MY_COMPUTER = &H11&


Set objNetwork = CreateObject("Wscript.Network")
objComputerName = objNetwork.ComputerName
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(MY_COMPUTER)
Set objFolderItem = objFolder.Self
objFolderItem.Name = objComputerName
===================================

GPP:
Just add a registry chnage on the user level:
===================================
Key:        Software\Microsoft\Windows\CurrentVersion\Explorer\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}
Value Name:     (Default)
Value Data:    %computername%
Type:        REG_SZ
==================================

The registry key by the way is (replace 123 with what you want):
==================================
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}]
@="123"
==================================

Have fun...

10 May, 2009

How to get the DN from an NT name...

Hi,

If you are scripting you may came across the annoying problem of the DN name.
In everyday activity you use the NT name of an object from Active Directory but when you want to start scripting - no... you need the DN.

The following Script will help you convert on the fly the NT name to DN object.

===================================
private function TranslateNTName(ntname)
dim nto
dim result
const ADS_NAME_INITTYPE_SERVER = 2
const ADS_NAME_INITTYPE_GC = 3
const ADS_NAME_TYPE_1779 = 1
const ADS_NAME_TYPE_NT4 = 3
TranslateNTName=""
set nto = CreateObject("NameTranslate")
'on error resume next
nto.Init ADS_NAME_INITTYPE_GC , ""
nto.set ADS_NAME_TYPE_NT4, ntname
TranslateNTName = nto.Get(ADS_NAME_TYPE_1779)
on error goto 0
end function

wscript.echo TranslateNT4Name ("domain\user")
===================================

Enjoy