Link to home
Start Free TrialLog in
Avatar of 3dNOVA
3dNOVAFlag for United States of America

asked on

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

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".
Avatar of Bradley Fox
Bradley Fox
Flag of United States of America image

Can an Administrator delete these connections manually?
Avatar of 3dNOVA

ASKER

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.
Avatar of 3dNOVA

ASKER

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.
Avatar of 3dNOVA

ASKER

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.
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
Avatar of 3dNOVA

ASKER

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.
SOLUTION
Avatar of Bradley Fox
Bradley Fox
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of 3dNOVA

ASKER

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.
Avatar of 3dNOVA

ASKER

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.
Post in the community support forum asking to have the question moved to the VB forum.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial