.: Windows Command Line Scripts (Batch Files)
|
|
| |
Please select from the following WSH examples:
|
|
----------------------------------------------------------------------------------------------------------------------------------------------------------
Check for Local user Account
@ECHO off
Net User EnterUserAccountName > %Temp%\003423.tmp
for /F "tokens=1-4" %%A in (%Temp%\003423.tmp) do (set DeployName=%%A %%B %%C %%D)
If Defined DeployName goto AccountExists
If NOT Defined DeployName goto AccountNotExist
:AccountExists
Echo Account Exists
Erase /Q %Temp%\003423.tmp
pause
Exit
:AccountNotExist
Echo Account Does Not Exist
Erase /Q %Temp%\003423.tmp
pause
Exit
Disable or Enable the Windows Firewall
@ECHO off
netsh firewall set opmode disable
exit
or
@ECHO off
netsh firewall set opmode enable
exit
Get IP Address and Save as a Variable
@ECHO off
%Windir%\system32\ipconfig.exe > %temp%\ipconfig.txt
type %temp%\ipconfig.txt|findstr /c:"IP Address" > %temp%\ip.txt
type %temp%\ip.txt|findstr /v "0.0.0.0" > %temp%\ip1.txt
FOR /F "delims=: tokens=2" %%I in (%temp%\ip1.txt) DO ECHO %%I > %temp%\justip.txt
FOR /F "delims=. tokens=1" %%A in (%temp%\justip.txt) DO SET octet1=%%A
FOR /F "delims=. tokens=2" %%B in (%temp%\justip.txt) DO SET octet2=%%B
FOR /F "delims=. tokens=3" %%C in (%temp%\justip.txt) DO SET octet3=%%C
FOR /F "delims=. tokens=4" %%D in (%temp%\justip.txt) DO SET octet4=%%D
del /q %temp%\ip1.txt
del /q %temp%\ip.txt
del /q %temp%\ipconfig.txt
del /q %temp%\justip.txt
Set IPAddress=%octet1%.%octet2%.%octet3%.%octet4%
ECHO %IPAddress%
pause
exit
because the variable IPAddress was created from 4 different Octets you can change the number of Octets used for a subnet comparison.
Add Domain Group or User Account to Local Administrators - Requires Local Admin Rights
@ECHO off
net localgroup administrators /add "DomainName\DomainUserorGroup"
Exit
Web site contents © Copyright Alan Phipps 2006, All rights reserved.
Website templates |