Tuesday 22 January 2013

A tip for fixing gns3 duplex mismatch issue

To fix GNS3 duplex mismatch issue on router 3700, just do these steps in order:

speed 100
full-duplex
ip address x.x.x.x y.y.y.y
no shut

That order makes it work and not revert. Not sure why but issuing the commands in a different order won't work.

Two ways to check if a Registry Key exists using VBScript

http://yorch.org/2011/10/two-ways-to-check-if-a-registry-key-exists-using-vbscript/

The first one is using the method RegRead from WScript.Shell.
If the given key is not found, it will rise an error, so we need to use an On Error Resume Next (which I don’t really like).
We would need to pass to the function a string like HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\ (note the trailing \) if we are looking for a Registry Key (those that look like a folder). If we want to check if a value inside a key exists, we would remove the trailing \, like HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\CurrentLevel.
Function RegKeyExists(Key)
  Dim oShell, entry
  On Error Resume Next
 
  Set oShell = CreateObject("WScript.Shell")
  entry = oShell.RegRead(Key)
  If Err.Number <> 0 Then
    Err.Clear
    RegKeyExists = False
  Else
    Err.Clear
    RegKeyExists = True
  End If
End Function


The second method uses WMI.
In this case, we would need to pass the Key Hive (Current User, Local Machine, etc) in the form of hex numbers (I declared them as constants). The KeyPath would be something like SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings.
Const HKCR = &H80000000 'HKEY_CLASSES_ROOT
Const HKCU = &H80000001 'HKEY_CURRENT_USER
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
Const HKUS = &H80000003 'HKEY_USERS
Const HKCC = &H80000005 'HKEY_CURRENT_CONFIG

Function KeyExists(Key, KeyPath)
  Dim oReg: Set oReg = GetObject("winmgmts:!root/default:StdRegProv")
  If oReg.EnumKey(Key, KeyPath, arrSubKeys) = 0 Then
    KeyExists = True
  Else
    KeyExists = False
  EndIf
EndFunction

Thursday 29 November 2012

3 methods to add domain user or group to local admin group

local host name: lsong-test
domain:  lsong.ca
user: lsong\testuser
group: lsong\group name with more than 20 characters

1. net local group administrators /add lsong\testuser

it's easy way, but user or group name have to be limited to 20 characters.

2. VBscript
Set objAdmins = GetObject("WinNT://lsong-test/Administrators")
Set objGroup = GetObject("WinNT://lsong.ca/group name with more than 20 characters")
objAdmins.add(objGroup.ADsPath)

This method has no 20 characters limitation for the user or group's name, but need to log on with domain account. If using local account to log in, it won't find domain object.

3. Cusrmgr.exe
cusrmgr -u "lsong\group name with more than 20 characters" -alg Administrators

cusrmgr command can work with user or group which name exceed 20 characters. But this command can only be found in Windows2000 Resource Kit. You have to copy it to local computer.