Discussion:
Script to add a domain user to the local admin group throws the error "The network path was not found."
(too old to reply)
Andrew Aronoff
2012-05-07 15:13:55 UTC
Permalink
I have a Windows Server 2008 R2 domain and a Windows XP Pro workstation that has been joined to the domain and then logged off. I am trying to create a VBS script to add a domain user to the local Administrators group.

I log onto the workstation as a local admin and run the following script:

Dim oNetwork : Set oNetwork = WScript.CreateObject("WScript.Network")
Dim strPC : strPC = oNetwork.ComputerName
Dim oGroup : Set oGroup = GetObject("WinNT://" & strPC & "/Administrators")
Dim oUser : Set oUser = GetObject("WinNT://domainname/username")
oGroup.Add(oUser.ADsPath)

This script returns the error "The network path was not found."

However, I am able to go into Control Panel > User Accounts > enter the username and the domainname > click Next... > choose the Administrators group from "Other" and the (domain-level) username will be added to the local Admin group.

The same script runs without error if it's launched after logging the workstation onto the domain with a domain Admin account.

How do I get my script to run without error when logged onto the workstation as a local admin?

regards, AndyA
Andrew Aronoff
2012-05-08 00:01:11 UTC
Permalink
Post by Andrew Aronoff
Dim oNetwork : Set oNetwork = WScript.CreateObject("WScript.Network")
Dim strPC : strPC = oNetwork.ComputerName
Dim oGroup : Set oGroup = GetObject("WinNT://" & strPC & "/Administrators")
Dim oUser : Set oUser = GetObject("WinNT://domainname/username")
oGroup.Add(oUser.ADsPath)
This script came from a "Hey, Scripting Guy" article: http://goo.gl/PuaTv

The problem is the oGroup.Add method syntax. A modified Add method syntax was obtained here: http://goo.gl/3vECz

The corrected script is thus:

Dim oNetwork : Set oNetwork = WScript.CreateObject("WScript.Network")
Dim strPC : strPC = oNetwork.ComputerName
Dim oGroup : Set oGroup = GetObject("WinNT://" & strPC & "/Administrators")
Dim strUser : strUser = "WinNT://domainname/username"
oGroup.Add strUser

This works on a Windows 2008 R2 domain when run as a local Administrator from a workstation that has been joined to the domain and succeeds in adding a domain user to the local Administrators group.

regards, AndyA

Continue reading on narkive:
Search results for 'Script to add a domain user to the local admin group throws the error "The network path was not found."' (Questions and Answers)
5
replies
can i get question answer of asp.net ?
started 2006-10-11 00:02:47 UTC
software
Loading...