Saturday, May 28, 2011

Install a network printer

C:\>rundll32 printui.dll,PrintUIEntry /in /n\\SERVER\hplaserj

Quick and easy. If the printer is shared correctly on the server with the right drivers for the client architecture and whatnot, nothing else is needed.

Friday, May 27, 2011

Open firewall ports

C:\>netsh firewall set portopening tcp 23 telnet

I don't think much explanation is required for this one...

Change IP address

C:\>netsh int ip set addr local dhcp
C:\>netsh int ip set addr NIC1 static 192.168.1.10 255.255.255.0 192.168.1.1 1
C:\>netsh int ip set addr "Local Area Connection 5" dhcp

The first one works if the connection you want to configure is "Local Area Connection," and they may also work if you have "Local Area Connection 2," but no others. If you're going to use this command on your own PCs with multiple NICs, it'd be better to rename your connections to "NIC1," "NIC2," etc, in which case you can use the second example. If you have multiple "Local Area Connections," you'll have to use the third one with the quotes.

Also note with the static address definition, it should be obvious that the format is IP[space]netmask[space]gateway, but you may not have noticed the [space]gateway metric at the end. To be perfectly honest, I don't even know what this means; just put a 1.

Grant local admin rights

C:\>runas /env /user:administrator "cmd /t:2f /k net localgroup Administrators /add %USERDOMAIN%\%USERNAME% && pause"

You'll need the local admin password, obviously, or use /user:DOMAIN\administrator or another admin user.

The /t:2f (optional) sets the background to green so you know it's an elevated prompt. The /env stays in the current user's environment, otherwise the %USERNAME% variable would expand to "Administrator"

Also, your current directory must be on a local drive accessible to Admin, or else you'll get a "Directory name is invalid" error.

Original OS install date

C:\>systeminfo | find "Install Date"

This one's not terribly useful, as most machines have been imaged, and this will keep the image's date. But it can still be good to know if an install is acting wonky.

System Uptime

C:\>systeminfo | find "System Up Time"

Will tell you how long since a computer's been rebooted. I use this when someone has a problem and SWEARS that they rebooted their PC four times this morning.

"Umm... well it says here you haven't rebooted since March. You know sleep and hibernate don't count, right?"

Notes:
Hibernate is an interesting beast, because it allows you to physically reboot the hardware without rebooting the software. I once hibernated a PC and replaced the hard drive. Several months later, I reinstalled the original drive to check something, and systeminfo reported the uptime as months.

Also, as always, FIND is case sensitive.

Ping a range of IPs

C:\>for /l %i in (1,1,254) do @ping 192.168.1.%i -n 1 -w 100 | find "Reply"

This will ping all addresses from 192.168.1.1 to 192.168.1.254 one time each, wait 100ms for a reply (more than enough time on a local network) and show only the addresses that replied.

Syntax for FOR /L is (start,step,end) if you want to change the range.

Also, note that the Windows FIND is case sensitive, so make sure you capitalize "Reply," or else use the /i switch or just "eply."