Showing posts with label script. Show all posts
Showing posts with label script. Show all posts

Thursday, January 23, 2014

windows ip switcher

Where I work, I support multiple offices.  Most of the offices do not have DHCP, they use static ip addresses (not my decision).  So here is a script I made for changing the ip address settings on a windows laptop, this does have to be ran with full admin privileges.  You will have to change parts of this script for your usage (where ever you see an ip address, and probably want to change the labels for the networks also).

echo ip-switch ver 20081119

set baseoffice=hq

rem now we figure out what subnet we're on
for /f "tokens=2 delims=:" %%i in ('ipconfig ^|find "IP Address"') do set ipaddr=%%i
for /f "tokens=2,3 delims=." %%o in ('echo %ipaddr%') do set subnet=%%o.%%p


rem based on the sub-net we determine what our location is
if /i "%subnet%" == "10.10" set loc=hq
if /i "%subnet%" == "10.11" set loc=sub
if /i "%subnet%" == "11.11" set loc=b1
if /i "%subnet%" == "11.12"  set loc=b2
if "%loc%" == "hq" set comploc=acompanyoffice
if "%loc%" == "substation" set comploc=acompanyoffice
if "%loc%" == "branch1" set comploc=acompanyoffice
if "%loc%" == "branch2" set comploc=acompanyoffice
if "%comploc%" == "acompanyoffice" goto comploc
set comploc=remote
:comploc


echo off

:complocmenu
cls
if "%comploc%" == "acompanyoffiice" echo this computer is currently setup for %comploc% (%loc%) use
if "%comploc%" == "remote" echo this computer is currently setup for %comploc% use
echo where is this laptop now (so it can communicate with the internet)?
echo 1) your base office (%baseoffice%)
echo 2) remote, home/other office
echo x) exit (leave everything as it is)
echo if another office enter the two-three letter abbreviation for it,
echo (hq,sub,b1,b2,etc...), and press enter, otherwise,
set /p comploc=press 1,2 or x and then enter:
rem if we entered a correct choice go to the next menu
if "%comploc%" == "1" goto methodmenu
if "%comploc%" == "2" goto methodmenu
if "%comploc%" == "x" echo no changes will be made
if /i "%comploc%" == "x" goto endprog
if /i "%comploc%" == "hq" goto otheroffice
if /i "%comploc%" == "sub" goto otheroffice
if /i "%comploc%" == "b1" goto otheroffice
if /i "%comploc%" == "b2" goto otheroffice


cls
rem if we entered a wrong chose clear screen of distraction
rem and ask for correct input
echo "you must press 1 or 2, or just press enter"
goto complocmenu

:otheroffice
set baseoffice=%comploc%
goto methodmenu

:methodmenu
echo is the laptop plugged in or using wireless?
echo 1) plugged in
echo 2) wireless
echo x) endprog
set /p netmethod=press 1 or 2 and then press enter

if "%netmethod%" == "1" set conmethod="Local Area Connection"
if "%netmethod%" == "2" set conmethod="Wireless Network Connection"
if "%netmethod%" == "1" goto methodselected
if "%netmethod%" == "2" goto methodselected
if "%netmethod%" == "x" goto endprog
echo "incorrect method selected"
goto methodmenu
:methodselected


if "%comploc%" == "1" goto staticip
if "%comploc%" == "2" goto dhcpip

:staticip
echo we will configure the computer for jcc office use
rem goto endprog
rem remove the goto endprog when we fix these settings
rem set static ip address (needs to be edited)

for /f "tokens=1 delims=-" %%I in ('echo %baseoffice%') do set loc=%%I
for /f "tokens=2 delims=-" %%C in ('hostname') do set compip=%%C
echo computer ip is %compip%

if /i "%baseoffice%" == "h1" set netaddr=10.10.10
if /i "%baseoffice%" == "sub" set netaddr=10.10.11
if /i "%baseoffice%" == "b1" set netaddr=10.11.11
if /i "%baseoffice%" == "b2" set netaddr=10.11.12




echo network address is %netaddr%

rem netsh interface ip set address "Local Area Connection" static %netaddr%.%compip% 255.255.255.0 %netaddr%.1 1
rem netsh interface ip set dns "Local Area Connection" static 10.91.1.21
rem netsh interface ip set wins "Local Area Connection" static 204.130.253.130
netsh interface ip set address %conmethod% static %netaddr%.%compip% 255.255.255.0 %netaddr%.1 1
netsh interface ip set dns %conmethod% static 10.91.1.21
netsh interface ip set wins %conmethod% static 10.254.2.130
rem start /wait sysdm.cpl

goto endprog


:dhcpip
rem some netsh commands to set dhcp on the interface
netsh interface ip set address name=%conmethod% source=dhcp
netsh interface ip set dns name=%conmethod% source=dhcp
netsh interface ip set wins name=%conmethod% source=dhcp
goto endprog

:endprog
hostname
for /f "tokens=2 delims=:" %%i in ('ipconfig ^|find "Default Gateway"') do set gateway=%%i
ipconfig |find "Address"
ping %gateway%
echo if you got back replys your good, if any of the requests timed out that's not good.
pause

Monday, September 23, 2013

enable basic games in windows

To enable/disable features in windows 7 you use dism (deployment image servicing and management).

The following batch file will enable the basic games (chess, minesweeper, solitaire, etc...), but not any of the internet games.
This will have to be ran with full admin privileges.

rem --------------games-enable-w7.bat--------------
rem to get a list of whats available and enabled/disabled
rem dism /online /Get-Features
echo make sure you're running this with admin privleges
dism /online /enable-feature /featurename:"InboxGames"
dism /online /disable-feature /featurename:"Internet Games"
dism /online /disable-feature /featurename:"More Games"
rem ---------end of batch script----------------


Thursday, February 28, 2013

net send for windows vista/7/8

Remember back in the day of NT/2000/XP, where you could type
net send computername some message here?

If you tried to do a net send with any version of windows since xp (vista/7/8), you've probably noticed that Microsoft removed net send entirely (with xp sp2, they disabled the service, but you could easily re-enable it).

Microsoft probably did this for security/anti-spam.  Back in the days when I was in college, I would often be getting net send spam.

You can use msg.exe which will send a message to a terminal server (has to be a server vision of windows), or to display a popup on your local computer.  If we combine that with psexec we have a way to replicate the functionality,

psexec \\remotecomputer msg.exe * /server:remotecomputer some message here

However this doesn't work very well if you have many computers (say a whole office?) that you need to send a message to.
So here's a script to make it easier if you have multiple computers:

rem --------beginning of netsend7.bat-------------------------


@echo off

rem this is for sending messages to computers using psexec and msg.exe

rem instead of net send. as net send doesn't exist in windows after xp

rem NEEDS PSEXEC.EXE in the the path or same folder.




if "%~1" == "" goto error




rem need to convert the list of computers

rem from comma to space delimited

for /f "tokens=*" %%c in ('echo %~1') do set comps=%%c

echo the computers are %comps%




rem extract the message from the command line

for /f "tokens=1,* delims= " %%p in ('echo %*') do set msg=%%q

echo the message is: %msg%




rem call the subroutine for each message.

for %%c in (%comps%) do call :submsg %%c







goto end




:submsg

set subcomp=%1

rem echo messaging %subcomp%, with message %msg%

psexec \\%subcomp% msg.exe * /server:%subcomp% %msg%

exit /b




:error

echo make sure to include quotes at the beginning and

echo end of the list of computers, but not the message,

echo usage "comp1,comp2,comp3,etc..." some message to the computers




rem check for psexec

where /q "$path:psexec.exe"

if %errorlevel% == 0 goto end

echo .

if not exist psexec.exe echo you need to have psexec.exe somewhere in the path.




:end


rem --------end of netsend7.bat-------------------------



If you want to accomplish the same thing without psexec, there is a guy who figured out a method using vbscript and setting a remoteRPC key in the registry on every computer you're messaging to: