WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Network

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Save Restore Network Configuration


; Net config save / restore script
; using netsh.exe

DirChange(DirScript())
inifile=StrCat(DirScript(),"netsh.ini")


While @TRUE


ipsfilesIPS=FileItemize("*.ips")
ipscount=ItemCount(ipsfilesIPS,@TAB)
If ipscount==0
   ipsfiles="*No saved configurations*"
Else
   ipsfiles=FileRoot(ItemExtract(1,ipsfilesIPS,@TAB))
   For xx=2 To ipscount
      x=FileRoot(ItemExtract(xx,ipsfilesIPS,@TAB))
      ipsfiles=StrCat(ipsfiles,@TAB,x)
   Next
EndIf

LastSetting=IniReadPvt("Main","LastSetting","???",inifile)
PrevSetting=IniReadPvt("Main","PrevSetting","???",inifile)

If LastSetting=="???" Then LastSettingShow="<None>"
Else LastSettingShow=LastSetting

If PrevSetting=="???"
   If ipscount==0
      PrevSetting=ipsfiles
   Else
      PrevSetting=ItemExtract(1,ipsfiles,@TAB)
   EndIf
Else
   PrevSettingIPS=StrCat(PrevSetting,".ips")
   If FileExist(PrevSettingIPS)==@FALSE
     PrevSetting=ItemExtract(1,ipsfiles,@TAB)
   EndIf
EndIf





IPSFILE=ipsfiles

NetCfgFormat=`WWWDLGED,6.1`

NetCfgCaption=`Network Configuration Changer`
NetCfgX=002
NetCfgY=034
NetCfgWidth=218
NetCfgHeight=096
NetCfgNumControls=008
NetCfgProcedure=`DEFAULT`
NetCfgFont=`DEFAULT`
NetCfgTextColor=`DEFAULT`
NetCfgBackground=`DEFAULT,DEFAULT`
NetCfgConfig=0

NetCfg001=`151,051,036,012,PUSHBUTTON,DEFAULT,"&Change",1,1,32,"Microsoft Sans Serif|5632|70|34","0|0|0",DEFAULT`
NetCfg002=`151,075,036,012,PUSHBUTTON,DEFAULT,"E&xit",0,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
NetCfg003=`095,031,092,058,DROPLISTBOX,IPSFILE,"%PrevSetting%",DEFAULT,3,4,DEFAULT,DEFAULT,DEFAULT`
NetCfg004=`095,011,092,012,VARYTEXT,LastSettingShow,"Vary 1",DEFAULT,4,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
NetCfg005=`019,011,064,012,STATICTEXT,DEFAULT,"Last Configuration:",DEFAULT,5,1024,"Microsoft Sans Serif|5632|70|34","0|0|0",DEFAULT`
NetCfg006=`011,033,072,012,STATICTEXT,DEFAULT,"Change Configuration to:",DEFAULT,6,1024,"Microsoft Sans Serif|5632|70|34","0|0|0",DEFAULT`
NetCfg007=`005,005,200,066,GROUPBOX,DEFAULT,DEFAULT,DEFAULT,7,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
NetCfg008=`011,075,074,012,PUSHBUTTON,DEFAULT,"Save Current Config",2,8,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("NetCfg")


If ButtonPushed==1   ; change
   IniWritePvt("Main","PrevSetting",LastSetting,inifile)
   IniWritePvt("Main","LastSetting",ipsfile,inifile)
   ;Message("Changing to",strcat(ipsfile,@crlf,LastSetting))
   fullipsnamewithquotes=StrCat('"',DirScript(),ipsfile,'.ips"')
   pline=StrCat('/c netsh exec ',fullipsnamewithquotes)
   pline2=StrCat("cmd.exe ",pline)
   ;Message("Debug",pline2)
   RunWait("cmd.exe",pline)
   Exit

EndIf

If ButtonPushed==2   ; save
   newfile=StrTrim(AskFilename("Enter new configuration name","","IPS Files|*.ips|All Files|*.*","*.ips",0))
   x=StrLower(newfile)
   If StrLen(x) < 5
      newipsfile=StrCat(newfile,".ips")
   Else
      If StrSub(x,StrLen(x)-3,4) !=".ips"
         newipsfile=StrCat(newfile,".ips")
      Else
         newipsfile=newfile
      EndIf
  EndIf
  fullipsnamewithquotes=StrCat('"',newipsfile,'"')

   ;Message("Saving to",newipsfile)
  pline=StrCat('/c netsh interface ip dump >',fullipsnamewithquotes)
  pline2=StrCat("cmd.exe ",pline)
 ; Message("Debug",pline2)
  RunWait("cmd.exe",pline)


EndIf

EndWhile

Exit

Article ID:   W17255
File Created: 2007:07:03:14:29:02
Last Updated: 2007:07:03:14:29:02