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

Networks - Servers
plus
plus
plus
plus
plus
plus
plus

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

Client IP Configuration script

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

; Set initial diretory
; Put all files and ini file in same directory.
DirChange(DirScript())
inifile=StrCat(DirScript(),"netsh.ini")

If param0 !=0   ; then a parameter was passed.  Assume it is ips filename to set
   If FileExist(param1)==@FALSE
       Message("Error",StrCat("Netsh Configureation file not found",@CRLF,param1))
       Exit
   EndIf

   ;format file name to put "doublequotes" around it
   fullipsnamewithquotes=StrCat('"',param1,'"')

   ;build command parameter line
   pline=StrCat('/c netsh exec ',fullipsnamewithquotes)

   ;Debugging stuff
   ;pline2=strcat("cmd.exe ",pline)
   ;Message("Debug",pline2)

   ;Do it
   RunWait("cmd.exe",pline)
   Exit
EndIf


; No parameters passed.  Use the User Interface section

;Set up while loop so when adding new config, script will repeat
While @TRUE
   
   ipsfilesIPS=FileItemize("*.ips")             ;get a list of current config files
   ipscount=ItemCount(ipsfilesIPS,@TAB)         ;See how many we have
   If ipscount==0                               ;well, if there aren't any...
      ipsfiles="*No saved configurations*"
   Else
      ipsfiles=FileRoot(ItemExtract(1,ipsfilesIPS,@TAB))   ;otherwise name a new list of files w/o the .ips on the end   
      For xx=2 To ipscount
         x=FileRoot(ItemExtract(xx,ipsfilesIPS,@TAB))
         ipsfiles=StrCat(ipsfiles,@TAB,x)
      Next
   EndIf
   
   ;Get last setting info and previous config info out of the ini file
   ;(plus some code to handle both first time and deleted config files.
   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
   

   ;Bring up GUI
   
   
   
   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)        ; Save ini info
      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)                                          ; add ips on the end if the user did not
      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:   W17051
File Created: 2007:07:03:14:27:56
Last Updated: 2007:07:03:14:27:56