Friday, January 9, 2009

Using Netsh to configure IP settings

To get the IP automatically using DHCP use this command:
netsh int ip set address
"local area connection" dhcp

To get the DNS server address automatically:
netsh int ip set dns
"local area connection" dhcp

local area connection can have any name. Just look in your control panel>Network Connections for the correct name.

To set a static IP address use this command:
netsh
interface ip set address "Local Area Connection" static ipaddr subnetmask gateway metric

NOTE: Replace ipaddr with the static IP address, subnetmask with the subnet mask, gateway with the default gateway and, if necessary, metric with the appropriate metric.

The following example changes the interface "Local Area Connection" to a static address of 192.168.0.10 with a subnet mask of 255.255.255.0, and the interface has a default gateway of 192.168.0.1 with a metric of 1:

netsh interface ip set address "Local Area Connection" static 192.168.0.10 255.255.255.0 192.168.0.1 1
 

To change the DNS server address use:
netsh int ip set dns
"local area connection" static 192.168.0.254 primary

To add more DNS server addresses entries use:
netsh int ip add dns
"local area connection" 192.168.1.254

 

Enable Regedit using a VB script

Here's something that might help when a message box declaring
"Registry editing has been disable by your administrator" gets thrown at your face.

This script is by Doug Knox and has helped me a lot specially when some stupid virus wouldn't allow me to access the registry.

Here's the link:
http://www.dougknox.com/security/scripts/regtools.vbs

alternate link:
http://www.mediafire.com/?lbiymmznktw

Here's the code which you can paste in notepad and then save with a '.vbs' extension.

'Enable/Disable Registry Editing tools
'© Doug Knox - rev 12/06/99

Option Explicit

'Declare variables
Dim WSHShell, n, MyBox, p, t, mustboot, errnum, vers
Dim enab, disab, jobfunc, itemtype

Set WSHShell = WScript.CreateObject("WScript.Shell")
p = "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System\"
p = p & "DisableRegistryTools"
itemtype = "REG_DWORD"
mustboot = "Log off and back on, or restart your pc to" & vbCR & "effect the changes"
enab = "ENABLED"
disab = "DISABLED"
jobfunc = "Registry Editing Tools are now "

'This section tries to read the registry key value. If not present an
'error is generated. Normal error return should be 0 if value is
'present
t = "Confirmation"
Err.Clear
On Error Resume Next
n = WSHShell.RegRead (p)
On Error Goto 0
errnum = Err.Number

if errnum <> 0 then
'Create the registry key value for DisableRegistryTools with value 0
WSHShell.RegWrite p, 0, itemtype
End If

'If the key is present, or was created, it is toggled
'Confirmations can be disabled by commenting out
'the two MyBox lines below

If n = 0 Then
n = 1
WSHShell.RegWrite p, n, itemtype
Mybox = MsgBox(jobfunc & disab & vbCR & mustboot, 4096, t)
ElseIf n = 1 then
n = 0
WSHShell.RegWrite p, n, itemtype
Mybox = MsgBox(jobfunc & enab & vbCR & mustboot, 4096, t)
End If

Check out Doug's website (http://www.dougknox.com/) for interesting scripts.

Download a big compilation of Windows Registry tweaks

Registry tweaks that I've accumulated over time: http://www.mediafire.com/?no2yvyom3dt

Lost Send to Option

If the Send To option is missing in the context menu when you right-click on a file use the following:

Paste the following in notepad and save it with a '.reg' extension. Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\AllFilesystemObjects\shellex\ContextMenuHandlers\Send To] @="{7BA4C740-9E81-11CF-99D3-00AA004AE837}"

Merge it with the registry.

Remove 'Manage' from the My Computer context menu

Paste the following in notepad and save it with a '.reg' extension. Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer] "NoManageMyComputerVerb"=dword:00000001

Merge it with the registry.

to undo the change delete the "NoManageMyComputerVerb" key from the registry.

How to hide applets in the control panel

The control panel applets are stored in the X:\WINDOWS\system32 folder.

X: represents the drive where you have installed windows.

Open regedit. Navigate to HKEY_CURRENT_USER\Control Panel\don't load

Insert a new String value and rename it with the applets name that you want to hide. Give it the value: No

For example to hide 'Add or Remove Programs' from the Control Panel insert the following in Notepad and save it with a '.reg' extension. Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Control Panel\don't load] "appwiz.cpl"="No" Merge it with the registry. To undo delete the concerned key from the registry.

Disable right-click in explorer

Paste the following in notepad and save it with a '.reg' extension.

Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer] "NoViewContextMenu"=dword:00000001 [HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer] "NoViewContextMenu"=dword:00000001

Merge it with the registry. To undo it delete the "NoViewContextMenu" from the registry.

Remove System Properties from My Computer and Control Panel

Paste the following in notepad and save it with a '.reg' extension.

Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer] "NoPropertiesMyComputer"=dword:00000001

Merge it with the registry.

To undo the effect delete the "NoPropertiesMyComputer"from the registry.

Disable right-click on the Taskbar

Paste the following in notepad and save it with a '.reg' extension.

Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer] "NoTrayContextMenu"=dword:00000001

Merge it with the registry.

To allow right-clicking on the taskbar delete the "NoTrayContextMenu" key from the registry.

Remove the Run command from the Start menu

Paste the following in notepad and save it with a '.reg' extension. Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer] "NoRun"=dword:00000001

to renable it delete the "NoRun" key from the registry.

Disable Task Manager

Paste the following in notepad and save it with a '.reg' extension. Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system] "DisableTaskMgr"=dword:00000001 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System] "DisableTaskMgr"=dword:00000001

To re-enable the task manager delete the "DisableTaskMgr" key from the registry.

Disable Control Panel

Paste the following in Notepad and save it with a '.reg' extension. Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer] "NoControlPanel"=dword:00000001 [HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer] "NoControlPanel"=dword:00000001

Now merge it with the windows registry. To enable opening the control panel delete the "NoControlPanel" key in the registry.

Remove the 'Shortcut to...' Prefix on Shortcuts

Paste the following in Notepad and save it with a '.reg' extension. Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer] "link"=hex:00,00,00,00 [HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer] "link"=hex:00,00,00,00

Now merge it with the registry.

To undo the effect replace the value of "link" with "link"=hex:01,00,00,00

Prevent access to registry editing tools

Method 1: One way to do this in Windows XP professional is through gpedit.msc

Start>Run... type: gpedit.msc

In the 'Group Policy' window expand 'User Configuration' expand 'Admininstravive Templates' and select 'System'

Double-click 'Prevent access to registry editing tools' in the pane towards the right.

Choose 'Enabled' and apply.

 

Method 2: The second way is to use the registry itself. To disable it for the current user: [HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System] "DisableRegistryTools"=dword:00000001

To disable it for all users: [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System] "DisableRegistryTools"=dword:00000001

If one tries to run regedit after applying this tweak a message box will appear stating "Registry editing has been disabled by your administrator"

Hiding Drives in the Windows Explorer

This will hide a particular drive in My Computer, Explorer, Send To, ... In the Windows Registry Editor (regedit) navigate to: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer

Create a new DWORD Value named: NoDrives

The value for NoDrives needs to be calculated as follows:
A drive that needs to be hidden is represented by a binary 1.

ZYXWVUTSRQPONMLKJIHGFEDCBA
00000000000000000000100000

For example to hide drive F the value for NoDrives = 20 in hexadicimal To hide all drives except C, D and E the binary value is 11111111111111111111100011 So the value for NoDrives will be: 3FFFFE3

Disable detection of USB Storage devices

To disable the detection of USB Storage devices paste the following in notepad and save it with a '.reg' extension.

Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR] "Start"=dword:00000004

merge it with the Windows registry.

To re-enable the detection of USB storage devices use:

Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR] "Start"=dword:3

Write-Protect USB Drives

You can use this to prevent data theft through the USB port. Paste the following in notepad and save it with a '.reg' extension.

Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\StorageDevicePolicies] "WriteProtect"=dword:00000001

Then merge it with the windows registry.

Disable Autorun on all drives

Many viruses spread through removable storage drives using the drives autorun feature. For example as soon as one inserts the USB drive an autorun.inf file that links to the virus gets executed.

To disable automatically running this autorun.inf file use the following steps:

1) If you use Windows XP Professional:

click Start>Run... type:

gpedit.msc and hit Enter. This will open a 'Group Policy' window. Expand: 'Computer Configuration' then expand 'Administrative Templates' Select 'System' and in the pane towards the right look for 'Turn off Autoplay'. Double-click 'Turn off Autoplay' and choose 'Enabled'. Where it says 'Turn off autoplay on:' choose 'All Drives' . Click 'Apply' and 'OK' Follow the same steps by expanding 'User Configuration'

2) In case your version of windows does not run gpedit.msc try the following method that uses the Windows Registry:

open Notepad and paste the following in it:

Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer] "NoDriveTypeAutoRun"=dword:000000ff

Save the file with a '.reg' extension and double-click the file. You might be prompted to merge it with the registry. Agree to do so.

Note : if you double-click the drive it might still execute the autorun.inf file.

A safer option to open drives is to use the Windows Explorer View (WinKey + E). Or maybe you'll need to import this in the registry too: Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Cdrom] "AutoRun"=dword:00000000

I'm not too sure but I guess the above tweak removes the Autoplay entry from the CDROM context menu.