I wrote this this morning on my XP box. I had a chance to test this out on a Win2K box this afternoon and found it necessary to first open a command prompt to get this to work. I have updated the code to do that and to display the configurations saved in UPPERCASE for readbility.
'==========================================================================
'
' NAME: IPSwitcher.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL:
' DATE : 3/23/2004
'
' COMMENT: <comment>
'
'==========================================================================
Dim fso,WSHShell
Set fso = CreateObject("Scripting.FileSystemObject")
Set WSHSHell = CreateObject("Wscript.Shell")
Path = "C:\IPCONFIGS"
'Create Storage location if not already there
If Not fso.FolderExists(Path) Then
fso.CreateFolder(Path)
End If
'Prompt to activate, create or delete a config
Action = InputBox("Do you want to ACTIVATE, SAVE or DELETE an IP Configuration","What should I do?")
Action = UCase(Action)
Call ConfigList
Select Case Action
Case "ACTIVATE"
If Len(ConfigList) >0 Then
What = InputBox("Existing configurations are:" & vbCrLf & vbCrLf & ConfigList & vbCrLf & "Enter config name to activate.","Activate Which Configuration")
FileName = Path & "\" & What & ".txt"
WSHShell.Run ("cmd /c netsh -f " & FileName)
Else
MsgBox "Sorry there are no configurations to activate"
End If
Case "SAVE"
If Len(ConfigList) >0 Then
What = InputBox("Existing configurations are:" & vbCrLf & vbCrLf & ConfigList & vbCrLf & "Enter new config name to save, enter existing name to overwrite.","Save Configuration")
Else
What = InputBox("Enter new config name to save.","Save Configuration")
End If
FileName = Path & "\" & What & ".txt"
'MsgBox Filename
WSHShell.Run ("cmd /c netsh -c interface dump >" & FileName)
Case "DELETE"
If Len(ConfigList) >0 Then
What = InputBox("Existing configurations are:" & vbCrLf & vbCrLf & ConfigList & vbCrLf & "Enter config name to delete.","Delete Configuration")
FileName = Path & "\" & What & ".txt"
fso.DeleteFile(FileName)
Else
MsgBox "No configurations saved to delete."
End If
End Select
MsgBox "Done"
Function ConfigList
'Read the existing configs
Set oFolder = fso.GetFolder(Path)
ThisList = ""
For Each oFile In oFolder.files
ThisConfigLength = (Len(oFile.Name)-4)
ThisConfig = Left(oFile.Name,ThisConfigLength)
ThisList = ThisList & ThisConfig & vbCrLf
Next
ConfigList = UCase(ThisList)
End Function
I hope you find this post helpful. Please let me know if it was.
Regards,
Mark