Sign in with
Sign up | Sign in
Solved

Adding domain user to admin group

Last response: in Windows 7
Share

even on my home laptop, I was trying to add a local user to admin group using below script but getting an error : Access denied on line 12

Set oWshNet = CreateObject("WScript.Network" )
sUser = "Ginnu"
sNetBIOSDomain = oWshNet.UserDomain
sComputer = oWshNet.ComputerName
Set oGroup = GetObject("WinNT://" & sComputer & "/Administrators,group" )
Set oUser = GetObject("WinNT://" & sNetBIOSDomain & "/" & sUser & ",user" )
oGroup.Add(oUser.ADsPath)
Related ressources

ursonly11 said:
even on my home laptop, I was trying to add a local user to admin group using below script but getting an error : Access denied on line 12

Set oWshNet = CreateObject("WScript.Network" )
sUser = "Ginnu"
sNetBIOSDomain = oWshNet.UserDomain
sComputer = oWshNet.ComputerName
Set oGroup = GetObject("WinNT://" & sComputer & "/Administrators,group" )
Set oUser = GetObject("WinNT://" & sNetBIOSDomain & "/" & sUser & ",user" )
oGroup.Add(oUser.ADsPath)

Which is correct behavior if the script is not running with administrator rights.

Ok so this is funny !
My ID is a member of Admin group but I wasn't able to run script as mentioned above. But when I selected run as admin, function behaved properly without error.
How is this possible that my ID being a part of admin group does not have complete rights

ursonly11 said:
Ok so this is funny !
My ID is a member of Admin group but I wasn't able to run script as mentioned above. But when I selected run as admin, function behaved properly without error.
How is this possible that my ID being a part of admin group does not have complete rights

Welcome to Windows 7. That's how administrator level accounts have behaved since the release of Vista.
!