Wednesday, January 16, 2019

Fun scripts in cmd

In this post, I’ll represent temporary parameter by using %name of parameter%, you need to change the whole thing with your parameter. Please take a look at the example below. The reason I use %name of parameter% because it represent a variable in batch file.

simpleBatch.bat (run as administrator)

@echo off
setlocal
set username=olaf
REM create new user
net user %username% /add
net user
pause
Result:
Administrator DefaultAccount Guest
xxx olaf xxx

Start or Stop or enable type of service in cmd

sc config %service name% start=auto
net start %service name%
Ex (remember to change %service name% to service name you want to enable):
sc config RemoteRegistry start=auto
net start RemoteRegistry

Find particular service in cmd

sc query type=service state=all | findstr /i “remote”
/i: case insensitive

Add key or value to registry

reg add “%directory%” /v %value% /t %type_of_value% /d %data%
You can read more here
/t:
REG_BINARY // Free form binary
REG_DWORD // 32-bit number
REG_DWORD_LITTLE_ENDIAN // 32-bit number (same as REG_DWORD)
REG_DWORD_BIG_ENDIAN // 32-bit number
REG_LINK // Symbolic Link (unicode)
REG_MULTI_SZ // Multiple Unicode strings
REG_RESOURCE_LIST // Resource list in the resource map
REG_FULL_RESOURCE_DESCRIPTOR // Resource list in the hardware description
REG_QWORD // 64-bit number

Shutdown a computer

shutdown /m %name_of_the_network_machine% /s /f
/s: shutdown
/f: forced shutdown

Hide user in log in screen

We need to add “SpecialAccounts\UserList” sub-key under Winlogon
In cmd:
reg add “\%computer_name%”\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\SpecialAccounts\UserList" /v %user_name_to_be_hidden% /t REG_DWORD /d 00000000

Disable UAC (User Account Control) restrictions in order to remote control computer

reg add “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System” /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 00000001

Create a new user with admin privilege

net user %your user name% /add
net localgroup administrators %username% /add

Delete a user

net user username /delete

Change user password

net use %username% %password%

Login to the network

net use \name_of_computer_in_nw

Extend the maximum login

net accounts /maxpwage:%duration%