objADGroup2 = GetObject ("WinNT://"&strDomain&"/Domain Admins,group") failed at Windws 10 startup

超 邓 1 Reputation point
2020-12-10T07:46:36.22+00:00

Hi Guys

I tried to add some local and domain group to local admins group via windows group policy -startup scripts, as below.

Set objGroup = GetObject("WinNT://"&strComputerName&"/Administrators,group")
Set objUser = GetObject("WinNT://"&strComputerName&"/BL_OSD,user")
Set objADGroup1 = GetObject ("WinNT://"&strDomain&"/PCAdmins,group")
Set objADGroup2 = GetObject ("WinNT://"&strDomain&"/Domain Admins,group")

If Not ObjGroup.IsMember(objUser.ADsPath) Then
objGroup.Add(objUser.ADsPath)
End If
If Not objADGroup1.IsMember(objADGroup1.ADsPath) Then
objGroup.Add(objADGroup1.ADsPath)
End If
If Not objADGroup2.IsMember(objADGroup2.ADsPath) Then
objGroup.Add(objADGroup2.ADsPath)
End If

Then i found that the local account "BL_OSD" added to the local admins group. However failed to add the domain group.
I added some err handling script ,like err.number after the
"Set objADGroup2 = GetObject ("WinNT://"&strDomain&"/Domain Admins,group")"
and found the error number was "-2147024843", i googled the error number ,seems it means the network path was not found.

But if i manually run the script after user login, everything works as expect.
So i wondering the problem maybe due to network was ready when the scripts running at startup or anything else?
Kindly need your help

Thanks
jacky

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,564 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bill Stewart 181 Reputation points
    2020-12-10T21:05:46.277+00:00

    It is likely a timing issue, as you expect.

    I would recommend not using scripts but rather group policy preferences to manage local group memberships anyway.

    0 comments No comments