We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Script to edit "Network and Dial-up Connections" remotely

3dNOVA
3dNOVA asked
on
Medium Priority
272 Views
Last Modified: 2007-12-19
We have a Windows 2000/2003 AD domain, with roaming profiles, and a lot of group policies.  We also use a single image for every PC we setup.  So, the desktop is very standard.  Problem is, when first created, the image had about 9 entries in "Network and Dial-up Connections", as we used several different RAS servers around the world to get to the WAN.  Howerver, we now use mostly VPN to get back in, and are down to only 1 RAS server.  We only want the 1 active entry listed in there, and remove the other 8.  We have several thousand PCs out there, with the full list.  Trying to write a script to fix this, but I can't find where these settings are kept.  I've searched the Registry for the entries used, but can't find them.  I've searched the local HD, and the user folder on the server for any files containing the text.  All I found was this file: "C:\Documents and Settings\All Users\Application Data\Microsoft\Network\Connections\Pbk\rasphone.pbk"  This file has all the entries in it, in the clear, editable with Notepad.  I thought I was good-to-go.  I edited this file, and removed all the extranious entries (after backing up, of course).  File is now exactly the same name, with only one entry.  However, when I go into "Network and Dial-up Connections", it still shows the original 9 entries.  Even after reboot, it still shows all.

Any idea how to get this to use the new list?   Oh BTW, if a user tries to delete any entries manually, they get an error: "The connection you selected cannot be deleted".
Comment
Watch Question

Bradley FoxLAN/WAN Systems Administrator
CERTIFIED EXPERT

Commented:
Can an Administrator delete these connections manually?

Author

Commented:
Yes, a domain admin, that is in the local Admin group as well can delete.  But, a regular domain user, that is in the local Admin group cannot.

Author

Commented:
OK, I'm upping this to 500 points.  But, I really need a complete answer that gets the script built.  Or the GP changed, if it ends up being there.

Author

Commented:
I have discovered that the file I was looking at before, "C:\Documents and Settings\All Users\Application Data\Microsoft\Network\Connections\Pbk\rasphone.pbk", is the file that needs changed to make this work.  However, just changing or replacing it does not update the entries you see.  Rebooting doesn't even do it.  So far, the only way I can make it work is to open up
"Network and Dial-up Connections" and hit F5.  This immedietely makes it reread that file, and everything looks great.  Now I have 2 problems writing a script for this (VBS).  I don't know how to make "Network and Dial-up Connections" refresh from a script, after replacing the file.  And, I can't get the VBS commands to recognize the long filename path.  Any suggestions?

If I don't get a response, I will end this question, and rewrite it over in the VB area.
Bradley FoxLAN/WAN Systems Administrator
CERTIFIED EXPERT

Commented:
For the long path issue you can either put it in triple quotes

"""C:\Documents and Settings\All Users\Application Data\Microsoft\Network\Connections\Pbk\rasphone.pbk"""

or you can use the short path

C:\Docume~1\AllUse~1\Applic~1\Micros~1\networ~1\connec~1\raspho~1.pbk

I will look into the VB refresh on the network properties page for you

Author

Commented:
I have tried the triple quotes thing, it doesn't work.  Here's the pertinent part of my script:

On Error Resume Next
Set wshshell = WScript.CreateObject("wscript.shell")
Set fs = CreateObject ("Scripting.FileSystemObject")

Set FileInfo = fs.GetFile("""C:\Documents And Settings\All Users\Application Data\Microsoft\Network\Connections\rasphone.pbk""")
WScript.Echo "Size = " & FileInfo.Size

This works perfectly well with ...("c:\temp\rasphone.pbk") as a test.  As soon as I put in the long path, with single quotes, double, triple, quad, chr(34), anything I've tried, not only does it not print the filesize, it won't even echo the "Size = " part anymore.
Bradley FoxLAN/WAN Systems Administrator
CERTIFIED EXPERT
Commented:
C:\Documents And Settings\All Users\Application Data\Microsoft\Network\Connections\rasphone.pbk

This is the wrong path...correct path is

C:\Documents and Settings\All Users\Application Data\Microsoft\Network\Connections\Pbk\rasphone.pbk

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Bradley FoxLAN/WAN Systems Administrator
CERTIFIED EXPERT

Commented:
This code works...I just tested it

Set fs = CreateObject ("Scripting.FileSystemObject")

Set FileInfo = fs.GetFile _
("C:\Documents And Settings\All Users\Application Data\Microsoft\Network\Connections\pbk\rasphone.pbk")
WScript.Echo "Size = " & FileInfo.Size

Author

Commented:
Doh!  You're right!    Path was just wrong.   You know, you look at someting a hundred times....

Yes, works fine now.  Not only that, but it also works the way I really wanted it to work:

LocPath = "C:\Documents And Settings\All Users\Application Data\Microsoft\Network\Connections\pbk\rasphone.pbk"
Set FileInfo = fs.GetFile(LocPath)
If FileInfo.Size > 0 Then
    WScript.Echo "Size is " & FileInfo.Size      
End If

So, all I need now is a way to get the setting to refresh.

Author

Commented:
If nobody can find out a way to refresh the network properties in the script, then I will have to close out this call.  I suppose I will have to recreate it over in the VB scripting area.  I hate to close it, when we're so close to an answer.
Bradley FoxLAN/WAN Systems Administrator
CERTIFIED EXPERT

Commented:
Post in the community support forum asking to have the question moved to the VB forum.
I guess RasPhone.....
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.