Since I haven't contributed squat to the forum in months, here's a useful little command file I use for switching network configurations when I travel internationally, but also can be used for keeping different configs for work, home office, and school.
Save as a .cmd file and call/schedule it anywhere you need. Enjoy
@ECHO OFF
REM
REM This batch file essentially loads a "configuration file" for a
REM network connection that has been configured previously (and
REM then exported to a backup file using netsh.exe ).
REM
REM To use this utility to create backup files that contain individual
REM network connection configurations here is what you do.
REM
REM First, you open Network Connections and make sure the single connection
REM you want to backup is configured properly
REM
REM Then ENABLE only that connection (disable all others). The netsh that
REM exports the connection configuration will only export enabled connections
REM
REM Open a command window and type the following command to create a backup file
REM with the .netsh file extension
REM
REM netsh -c interface dump > c:\your_connection_filename_here.netsh
REM
REM Repeat this process to create network configuration files for each
REM network interface configuration of interest
REM
REM After you create multiple .netsh backup configurations for each network
REM profile that you want to be able to switch between quickly, you
REM edit the batch file list (in the batch below) to show your
REM list and allow selection of the desired network config.
REM
REM And of course, you could always throw this command file into
REM your list of auto start programs if you switch all the time
REM between work, home office, and school
ECHO.
ECHO Show all currently enabled network interfaces...
ECHO.
netsh interface ip show config
ECHO.
ECHO Ping for current wireless network connection...
ECHO.
ping -n 1 yahoo.com
if %errorlevel% EQU 0 (
ECHO.
ECHO.
ECHO. ******************************************
ECHO *** Network Connection Already Active ***
ECHO. ******************************************
ECHO.
)
ECHO.
ECHO.
ECHO.
ECHO Network Connection Configuration Utility by EGM V2.5
ECHO.
REM Network interface configurations backed up and available for loading
ECHO.
ECHO (1) default - Dynamic IP (wireless network configuration)
ECHO (2) BAQ WiMax - Static IP (wireless network configuration)
ECHO (3) default - Local Area Connection DHCP (NIC)
ECHO (4) loopback - Microsoft Loopback Adapter
ECHO.
set/p CONFIG=Choose wireless network configuration (1/2/3/4)?:
IF [%CONFIG%]==[] ECHO Missing parameter for configuration
IF [%CONFIG%]==[] Goto FINALLY
ECHO Defaulting to Always On Power Management...
SET CONFIG=1
IF /I %CONFIG%==1 (
ECHO.
ECHO.
ECHO ***********************************************************
ECHO Reconfiguring wireless network configuration for dynamic ip
ECHO ***********************************************************
ECHO.
ECHO.
ECHO Load the default Dynamic ip configuration...
netsh -f "C:\Documents and Settings\username\Desktop\Scripts\WirelessConfigs\wirelessinterfacedefault.netsh"
If ErrorLevel 1 Goto ErrMsg
)
IF /I %CONFIG%==2 (
ECHO.
ECHO.
ECHO **************************************************************
ECHO Reconfiguring wireless network configuration for static BAQ ip
ECHO **************************************************************
ECHO.
ECHO.
ECHO Load the BAQ WiMax static ip configuration...
netsh -f "C:\Documents and Settings\username\Desktop\Scripts\WirelessConfigs\wirelessinterfacebaqwimax.netsh"
If ErrorLevel 1 Goto ErrMsg
)
IF /I %CONFIG%==3 (
ECHO.
ECHO.
ECHO ***********************************************************
ECHO Reconfiguring LAN network configuration
ECHO ***********************************************************
ECHO.
ECHO.
ECHO Load the default LAN ip configuration...
netsh -f "C:\Documents and Settings\username\Desktop\Scripts\WirelessConfigs\localareaconndefault.netsh"
If ErrorLevel 1 Goto ErrMsg
REM ECHO.
REM ECHO.
ECHO Release ipconfig....
ipconfig /release
REM ECHO.
REM ECHO.
ECHO Renew ipconfig....
ipconfig /renew
)
IF /I %CONFIG%==4 (
ECHO.
ECHO.
ECHO ***********************************************************
ECHO Reconfiguring Microsoft Loopback Adapter configuration
ECHO ***********************************************************
ECHO.
ECHO.
ECHO Load the default MS Loopback Adapter ip configuration...
netsh -f "C:\Documents and Settings\username\Desktop\Scripts\WirelessConfigs\msloopback.netsh"
If ErrorLevel 1 Goto ErrMsg
)
ECHO.
ECHO.
ECHO *** Network Connection Reconfigured Successfully ***
ECHO.
Goto FINALLY
:ErrMsg
ECHO ****************************
ECHO ****************************
ECHO ****************************
ECHO ****************************
ECHO **************************** ERROR DETECTED ********************************
ECHO ****************************
ECHO ****************************
ECHO ****************************
ECHO ****************************
pause
Goto FINALLY
:FINALLY
:ABORT
EXIT
-
Another moderately useful command utility, if you like to run your laptop battery down to ZERO every week/month to get the max life and power out of it, when you need it on the airplane. Enjoy
@ECHO OFF
REM
REM Makes a complete switch of Power Scheme configuration
REM
ECHO.
ECHO.
ECHO.
ECHO Power Scheme Configuration Utility by EGM V2.5
ECHO.
REM Power Schemes available for activating
ECHO.
ECHO (1) Always On (default)
ECHO (2) Presentation
ECHO (3) Deplete Battery
ECHO.
set/p CONFIG=Choose Power Scheme to activate (1/2/3)?:
IF [%CONFIG%]==[] (
ECHO Defaulting to Always On Power Management...
SET CONFIG=1
)
REM Always make sure Hibernation is enabled no matter what scheme is loaded
REM including the deplete battery scheme
powercfg /H ON
IF /I %CONFIG%==1 (
ECHO.
ECHO.
ECHO ***********************************************************
ECHO Reconfiguring for Always On Power Management Scheme
ECHO ***********************************************************
powercfg /Q "Always On"
If errorlevel 1 GOTO ErrMsg
ECHO.
ECHO.
ECHO Load the Always On configuration...
powercfg /S "Always On"
If errorlevel 1 GOTO ErrMsg
REM activate the low and critical battery alarms...
powercfg /B LOW /activate on /level 10
If errorlevel 1 GOTO ErrMsg
powercfg /B CRITICAL /activate on /level 5
If errorlevel 1 GOTO ErrMsg
)
IF /I %CONFIG%==2 (
ECHO.
ECHO.
ECHO **************************************************************
ECHO Reconfiguring for Presentation Power Management Scheme
ECHO **************************************************************
powercfg /Q "Presentation"
If errorlevel 1 GOTO ErrMsg
ECHO.
ECHO.
ECHO Load the Presentation configuration...
powercfg /S "Presentation"
If errorlevel 1 GOTO ErrMsg
REM activate the low and critical battery alarms...
powercfg /B LOW /activate on /level 10
If errorlevel 1 GOTO ErrMsg
powercfg /B CRITICAL /activate on /level 5
If errorlevel 1 GOTO ErrMsg
)
IF /I %CONFIG%==3 (
ECHO.
ECHO.
ECHO **************************************************************
ECHO Reconfiguring for Depelete Battery Power Management Scheme
ECHO **************************************************************
powercfg /Q "Deplete Battery"
If errorlevel 1 GOTO ErrMsg
ECHO.
ECHO.
ECHO Load the Deplete Battery configuration...
powercfg /S "Deplete Battery"
If errorlevel 1 GOTO ErrMsg
REM activate the low warning but DISABLE the critical battery alarm...
REM this prevents hibernation triggering and drains battery to 0...
powercfg /B LOW /activate on /level 5
If errorlevel 1 GOTO ErrMsg
powercfg /B CRITICAL /activate off
If errorlevel 1 GOTO ErrMsg
)
ECHO.
ECHO.
ECHO *** Power Scheme Reconfigured Successfully ***
ECHO.
Goto FINALLY
:ErrMsg
ECHO ****************************
ECHO ****************************
ECHO ****************************
ECHO ****************************
ECHO **************************** ERROR DETECTED ********************************
ECHO ****************************
ECHO ****************************
ECHO ****************************
ECHO ****************************
Goto FINALLY
:FINALLY
pause
:ABORT
EXIT -
If you like the idea of doing layered backup strategies, here is a command file I use to do my ZIP based backups layer.
You will need to do considerable editing for your particulars, but you get the point. Backups can be directed at multiple targets including your host FTP bulk backup directory.
Save as a.CMD file of course
Enjoy
@ECHO OFF
REM Current project goes here...
set PROJECT=BD240
ECHO.
ECHO Zip Backup Utility by EGM V2.5
ECHO.
ECHO.
ECHO.
set/p TAPE=Backup to Tape? (y/n):
IF [%TAPE%]==[] ECHO Missing parameter for Tape backup
IF [%TAPE%]==[] Goto FINALLY
ECHO.
ECHO.
set/p FTP=Backup to FTP? (y/n):
IF [%FTP%]==[] ECHO Missing parameter for FTP backup
IF [%FTP%]==[] Goto FINALLY
ECHO.
ECHO.
set/p CRUZER=Backup to CRUZER jumpdrive? (y/n):
IF [%CRUZER%]==[] ECHO Missing parameter for CRUZER backup
IF [%CRUZER%]==[] Goto FINALLY
ECHO.
ECHO.
set/p LOCALHD=Backup to LOCAL harddrive? (y/n):
IF [%LOCALHD%]==[] ECHO Missing parameter for LOCALHD backup
IF [%LOCALHD%]==[] Goto FINALLY
ECHO.
ECHO.
set/p QUICK=Do a quick backup? (y/n):
IF [%QUICK%]==[] ECHO Missing parameter for Kind of backup
IF [%QUICK%]==[] Goto FINALLY
ECHO.
ECHO.
set/p JUMPDRIVE=Include Jumpdrive data in backup? (y/n):
IF [%JUMPDRIVE%]==[] ECHO Missing parameter for Include Jumpdrive in backup
IF [%JUMPDRIVE%]==[] Goto FINALLY
ECHO.
ECHO.
set/p AUTOSHUTDOWN=Shut down after backup? (y/n):
IF [%AUTOSHUTDOWN%]==[] ECHO Missing parameter for shut down after backup
IF [%AUTOSHUTDOWN%]==[] Goto FINALLY
ECHO.
ECHO.
set/p PASSWORD=Password for the backup?:
IF [%PASSWORD%]==[] ECHO Missing parameter for password
IF [%PASSWORD%]==[] Goto FINALLY
REM clear the screen...
cls
REM use the system date as the zip file name and stamp all with same time in name...
for /F "tokens=1-4 delims=/- " %%A in ('date/T') do set FILEDATE=%%D%%B%%C
for /F "tokens=1-3 delims=: " %%A in ('time/T') do set FILETIME=%%C%%A%%B
ECHO.
ECHO.
ECHO FILEDATE %FILEDATE%%FILETIME% TAPE? %TAPE% FTP? %FTP% CRUZER? %CRUZER% LOCALHD? %LOCALHD% QUICK? %QUICK% AUTOSHUTDOWN %AUTOSHUTDOWN% Include JUMPDRIVE Data? %JUMPDRIVE%
IF /I %QUICK%==y (
ECHO PROJECT %PROJECT%
REM Set the output log file using the filedate
set LOGFILE=C:\Temp\ZipBakup\%FILEDATE%%FILETIME%_XQUICK.log
)
IF /I %QUICK%==n (
REM Set the output log file using the filedate
set LOGFILE=C:\Temp\ZipBakup\%FILEDATE%%FILETIME%_XFULL.log
)
REM Before starting new log file, clear previous builds from zip directory
If Exist C:\TEMP\ZipBakup\*.zip* DEL C:\TEMP\ZipBakup\*.zip*
If Exist C:\TEMP\ZipBakup\*.log DEL C:\TEMP\ZipBakup\*.log
If Exist C:\TEMP\*.reg DEL C:\TEMP\*.reg
ECHO.
ECHO.
ECHO Press CTRL-C to break
@ECHO OFF
pause
ECHO %DATE% %TIME% > %LOGFILE%
ECHO *** FILEDATE %FILEDATE%%FILETIME% TAPE %TAPE% FTP %FTP% CRUZER %CRUZER% LOCALHD %LOCALHD% QUICK %QUICK% AUTOSHUTDOWN %AUTOSHUTDOWN% *** >> %LOGFILE%
REM REG EXPORT and REG SAVE are different (SAVE produces a HIVE binary). EXPORT merges results back into windows registry, SAVE replaces window registry results
REM REG EXPORT and REGISTRY manual export, produce different file results! The manual export contains all values,
REM where REG EXPORT skips some values. Can not find any internet explanation
REM
REM So, do the best we can with a REG EXPORT that produces a file that will MERGE back into the registry without deleting anything when imported
ECHO.
ECHO.
ECHO Exporting the XP registry please wait...
ECHO Export the registry root keys to files for backup >> %LOGFILE%
REG EXPORT HKLM C:\TEMP\%FILEDATE%%FILETIME%_HKLM.reg
REG EXPORT HKCU C:\TEMP\%FILEDATE%%FILETIME%_HKCU.reg
REG EXPORT HKCR C:\TEMP\%FILEDATE%%FILETIME%_HKCR.reg
REG EXPORT HKU C:\TEMP\%FILEDATE%%FILETIME%_HKU.reg
REG EXPORT HKCC C:\TEMP\%FILEDATE%%FILETIME%_HKCC.reg
ECHO Copy the manual registry export of RRamdisk parameters
ECHO Copy the manual registry export of RRamdisk parameters >> %LOGFILE%
copy C:\EGMD901C_RRamdisk_Params.reg C:\TEMP
ECHO Zip the exported registry files >> %LOGFILE%
"E:\Program Files\WinZip\wzzip.exe" -ez -s%PASSWORD% -yc "C:\Temp\ZipBakup\%FILEDATE%%FILETIME%_REGISTRY.zipx" C:\TEMP\*.reg
If ErrorLevel 1 Goto ZipErrMsg
REM Jumpdrive backup?
IF /I %JUMPDRIVE%==y (
ECHO Zip the GDRIVE Jumpdrive >> %LOGFILE%
"E:\Program Files\WinZip\wzzip.exe" -x@"C:\Documents and Settings\username\Desktop\Scripts\BACKUPS\GDRIVE_EXCLUDE.LST" -ez -s%PASSWORD% -yc -P -r "C:\Temp\ZipBakup\%FILEDATE%%FILETIME%_GDRIVE.zipx" @"C:\Documents and Settings\username\Desktop\Scripts\BACKUPS\GDRIVE.LST"
If ErrorLevel 1 Goto ZipErrMsg
)
REM quick backup only?
IF /I %QUICK%==y (
ECHO Zip the CDRIVE using CDRIVE_QUICK.LST parameter file >> %LOGFILE%
"E:\Program Files\WinZip\wzzip.exe" -ez -s%PASSWORD% -yc -P -r "C:\Temp\ZipBakup\%FILEDATE%%FILETIME%_CDRIVE_QUICK.zipx" @"C:\Documents and Settings\username\Desktop\Scripts\BACKUPS\CDRIVE_QUICK.LST"
If ErrorLevel 1 Goto ZipErrMsg
ECHO Zip the FDRIVE using FDRIVE_QUICK.LST parameter file >> %LOGFILE%
"E:\Program Files\WinZip\wzzip.exe" -ez -s%PASSWORD% -yc -P -r "C:\Temp\ZipBakup\%FILEDATE%%FILETIME%_%PROJECT%.zipx" @"C:\Documents and Settings\username\Desktop\Scripts\BACKUPS\FDRIVE_QUICK.LST"
If ErrorLevel 1 Goto ZipErrMsg
)
REM full backup...
IF /I %QUICK%==n (
ECHO Zip the FDRIVE using FDRIVE.LST parameter file >> %LOGFILE%
"E:\Program Files\WinZip\wzzip.exe" -xf:\DBF*.* -ez -s%PASSWORD% -yc -P -r "C:\Temp\ZipBakup\%FILEDATE%%FILETIME%_FDRIVE.zipx" @"C:\Documents and Settings\username\Desktop\Scripts\BACKUPS\FDRIVE.LST"
If ErrorLevel 1 Goto ZipErrMsg
ECHO Zip the CDRIVE using CDRIVE.LST parameter file >> %LOGFILE%
"E:\Program Files\WinZip\wzzip.exe" -x@"C:\Documents and Settings\username\Desktop\Scripts\BACKUPS\CDRIVE_EXCLUDE.LST" -ez -s%PASSWORD% -yc -P -r "C:\Temp\ZipBakup\%FILEDATE%%FILETIME%_CDRIVE.zipx" @"C:\Documents and Settings\username\Desktop\Scripts\BACKUPS\CDRIVE.LST"
If ErrorLevel 1 Goto ZipErrMsg
)
REM tape backup?
IF /I %TAPE%==y (
ECHO Copy Zip backup files to the COOLMAX external drive >> %LOGFILE%
copy C:\Temp\ZipBakup\*.zip* H:\BAKUPS\EGMD901C\ZipBAKUPS
If ErrorLevel 1 Goto ZipErrMsg
)
REM local harddrive backup?
IF /I %LOCALHD%==y (
ECHO Copy Zip backup files to the EDRIVE local harddrive >> %LOGFILE%
copy C:\Temp\ZipBakup\*.zip* E:\BAKUPS\EGMD901C\ZipBAKUPS
If ErrorLevel 1 Goto ZipErrMsg
)
REM cruzer backup?
IF /I %CRUZER%==y (
ECHO Copy Zip backup files to the CRUZER jump drive >> %LOGFILE%
copy C:\Temp\ZipBakup\*.zip* G:\BAKUPS\EGMD901C\ZipBAKUPS
If ErrorLevel 1 Goto ZipErrMsg
)
REM ftp files to hosting account
If /I %FTP%==y (
ECHO FTP Zip backup files to the host FTP account >> %LOGFILE%
"E:\Program Files\Ipswitch\WS_FTP Professional\ftpscrpt" -u accountname -w %PASSWORD% -f "C:\Documents and Settings\username\Desktop\Scripts\BACKUPS\ws_ftp_v100.scp"
If ErrorLevel 1 Goto ZipErrMsg
)
ECHO.
ECHO.
ECHO *** Backup Batch Completed Successfully *** >> %LOGFILE%
ECHO *** Backup Batch Completed Successfully ***
Goto FINALLY
:ZipErrMsg
ECHO **************************** >> %LOGFILE%
ECHO **************************** >> %LOGFILE%
ECHO **************************** >> %LOGFILE%
ECHO **************************** >> %LOGFILE%
ECHO **************************** ERROR DETECTED ******************************** >> %LOGFILE%
ECHO **************************** >> %LOGFILE%
ECHO **************************** >> %LOGFILE%
ECHO **************************** >> %LOGFILE%
ECHO **************************** >> %LOGFILE%
ECHO ****************************
ECHO ****************************
ECHO ****************************
ECHO ****************************
ECHO **************************** ERROR DETECTED ********************************
ECHO ****************************
ECHO ****************************
ECHO ****************************
ECHO ****************************
Goto FINALLY
:FINALLY
REM Capture the end date time and write to the log file...
for /F "tokens=1-4 delims=/- " %%A in ('date/T') do set FILEDATE=%%D%%B%%C
for /F "tokens=1-3 delims=: " %%A in ('time/T') do set FILETIME=%%A%%B%%C
ECHO %DATE% %TIME% >> %LOGFILE%
ECHO %DATE% %TIME%
If /I %AUTOSHUTDOWN%==n (
REM keep the cmd window open for review...
pause
)
REM And finally move the log file and ignore any errors...
REM tape backup?
IF /I %TAPE%==y (
ECHO Copy log file to the COOLMAX external drive
copy C:\Temp\ZipBakup\*.log H:\BAKUPS\EGMD901C\ZipBAKUPS
)
REM local harddrive backup?
IF /I %LOCALHD%==y (
ECHO Copy log file to the LOCAL harddrive
copy C:\Temp\ZipBakup\*.log E:\BAKUPS\EGMD901C\ZipBAKUPS
If ErrorLevel 1 Goto ZipErrMsg
)
REM cruzer backup?
IF /I %CRUZER%==y (
ECHO Copy log file to the CRUZER jumpdrive
copy C:\Temp\ZipBakup\*.log G:\BAKUPS\EGMD901C\ZipBAKUPS
If ErrorLevel 1 Goto ZipErrMsg
)
REM ftp log file to host account
If /I %FTP%==y (
ECHO FTP Log file to the APlus FTP account
"E:\Program Files\Ipswitch\WS_FTP Professional\ftpscrpt" -u accountname -w %PASSWORD% -f "C:\Documents and Settings\username\Desktop\Scripts\BACKUPS\ws_ftp_log_v100.scp"
)
REM Clear working backup directory of temporary files
If Exist C:\TEMP\ZipBakup\*.zip* DEL C:\TEMP\ZipBakup\*.zip*
If Exist C:\TEMP\ZipBakup\*.log DEL C:\TEMP\ZipBakup\*.log
If Exist C:\TEMP\*.reg DEL C:\TEMP\*.reg
If /I %AUTOSHUTDOWN%==y (
REM shutdown but give message and wait 3 minutes before shutdown so user can abort...
SHUTDOWN -s -t 180 -c "Forced autoshutdown after zbu data backup. To abort shutdown, run <shutdown -a> from command window." -f -d p:4:1
)
To do your FTP with ws_ftp, you need a couple of .SCP files like this:
"ws_ftp_v100.scp"
CONNECT accountname.web.aplus.net
CD egmd901c.bak
LCD c:/temp/zipbakup
MPUT *.zip*
CLOSE
And a second .SCP that looks like this to move the logs after backup runs
"ws_ftp_log_v100.scp"
CONNECT accountname.web.aplus.net
CD egmd901c.bak
LCD c:/temp/zipbakup
MPUT *.log
CLOSE
Directory of output files produced looks like this for quick and full backups...
Volume in drive E is PROGS
Volume Serial Number is 9624-6720
Directory of E:\BAKUPS\EGMD901C\ZipBAKUPS
08/29/2009 08:43 AM <DIR> .
08/29/2009 08:43 AM <DIR> ..
08/28/2009 09:48 AM 8,934,375 20090828AM0948_BD240.zipx
08/28/2009 09:48 AM 337,361 20090828AM0948_CDRIVE_QUICK.zipx
08/28/2009 09:48 AM 7,024,794 20090828AM0948_REGISTRY.zipx
08/28/2009 09:53 AM 548 20090828AM0948_XQUICK.log
08/28/2009 10:58 AM 77,852,557 20090828AM1052_CDRIVE.zipx
08/28/2009 10:56 AM 124,882,328 20090828AM1052_FDRIVE.zipx
08/28/2009 10:52 AM 7,019,433 20090828AM1052_REGISTRY.zipx
08/28/2009 11:25 AM 536 20090828AM1052_XFULL.log
08/29/2009 08:43 AM 0 list.txt
101 File(s) 1,577,746,494 bytes
2 Dir(s) 143,231,369,216 bytes free
Several CMD utilities for system management
Discussion in 'Windows OS and Software' started by Pursuvant, Aug 29, 2009.