02 March, 2012

Configuring Wireless Settings from the Command Line or a Script

You can also configure wireless settings using commands in the netsh wlan context of the Netsh command-line tool, which enables you to create scripts that connect to different wireless networks (whether encrypted or not). To list available wireless networks, run the following command.
 
Netsh wlan show networks

Interface Name : Wireless Network Connection

There are 2 networks currently visible



SSID 1 : Litware

 Network Type  : Infrastructure

 Authentication  : Open

 Encryption  : None



SSID 1 : Contoso

 Network Type  : Infrastructure

 Authentication  : Open

 Encryption  : WEP
 
Before you can connect to a wireless network using Netsh, you must have a profile saved for that network. Profiles contain the SSID and security information required to connect to a network. If you have previously connected to a network, the computer will have a profile for that network saved. If a computer has never connected to a wireless network, you need to save a profile before you can use Netsh to connect to it. You can save a profile from one computer to an Extensible Markup Language (XML) file and then distribute the XML file to other computers in your network. To save a profile, run the following command after manually connecting to a network.
 
Netsh wlan export profile name="SSID"

Interface profile "SSID" is saved in file ".\Wireless Network

Connection-SSID.xml" successfully.

Before you can connect to a new wireless network, you can load a profile from a file. The following example demonstrates how to create a wireless profile (which is saved as an XML file) from a script or the command line.
 
Netsh wlan add profile filename="C:\profiles\contoso1.xml"

Profile contoso1 is added on interface Wireless Network Connection

To connect to a wireless network quickly, use the netsh wlan connect command and specify a wireless profile name (which must be configured or added previously). The following examples demonstrate different but equivalent syntaxes for connecting to a wireless network with the Contoso1 SSID.
 
Netsh wlan connect Contoso1

Connection request is received successfully

Netsh wlan connect Contoso1 interface="Wireless Network Connection"

Connection request is received successfully

Note that you need to specify the interface name only if you have multiple wireless network adapters—an uncommon situation. You can use the following command to disconnect from all wireless networks.
 
Netsh wlan disconnect



Disconnection request is received successfully

You can use scripts and profiles to simplify the process of connecting to private wireless networks for your users. Ideally, you should use scripts and profiles to save users from ever needing to type wireless security keys.
You can also use Netsh to allow or block access to wireless networks based on their SSIDs. For example, the following command allows access to a wireless network with the Contoso1 SSID.
 
Netsh wlan add filter permission=allow ssid=Contoso networktype=infrastructure

Similarly, the following command blocks access to the Fabrikam wireless network.
 
Netsh wlan add filter permission=block ssid=Fabrikam networktype=adhoc

To block all ad hoc networks, use the Denyall permission, as the following example demonstrates.
 
Netsh wlan add filter permission=denyall networktype=adhoc

To prevent Windows from automatically connecting to wireless networks, run the following command.
 
Netsh wlan set autoconfig enabled=no interface="Wireless Network Connection"

You can also use Netsh to define the priority of user profiles (but not Group Policy profiles). Group Policy profiles always have precedence over user profiles. The following example demonstrates how to configure Windows to connect automatically to the wireless network defined by the Contoso profile before connecting to the wireless network defined by the Fabrikam profile.
 
Netsh wlan set profileorder name=Contoso interface="Wireless Network Connection"

priority=1

Netsh wlan set profileorder name=Fabrikam interface="Wireless Network Connection"

priority=2

Netsh has many other commands for configuring wireless networking. For more information, run the following at a command prompt.
 
Netsh wlan help

Note

When troubleshooting problems connecting to wireless networks, open Event Viewer and browse the Applications And Services Logs\Microsoft\Windows\WLAN-AutoConfig event log. You can also use this log to determine the wireless networks to which a client is connected, which might be useful when identifying the source of a security compromise.

Windows Batch Script - Getting Script Location (Directory/Path)

Inside a Windows batch file (.bat or .cmd) you can reference the drive and folder where the batch file is located by: %~D0
CHDIR %~DP0
The first line causes the script to change to the drive where the script is located.
The second line causes the script to change to the directory where the script is located.
See Call command for further information.

Windows 7 Bug

Windows 7 has a bug in the handling of %~dp0 and %~f0 which can cause this to fail. When running a .cmd or .bat script and using %~f0 or %~dp0 to resolve the batch script name if the batch script name has spaces (ex: "my script.cmd") and you chdir within the script then further references to %~dp0 will incorrectly resolve to the new cwd instead of the correct batch script location.
This does not happen if the script name has no spaces in it.
Example script below:
@REM When this script is named "test.cmd" (no spaces) it works as expected for the value of %~f0

@REM When this script is named "test with spaces.cmd" it does not work

echo "Stage 1:  dp0 == %~dp0"

SET STAGE1=%~dp0


%~d0
cd "%~dp0"
mkdir TestSubFolder
cd TestSubFolder

echo "Stage 2:  dp0 == %~dp0"
echo Should have gotten value %STAGE1%

Work Around

I've filed a bug with Microsoft at https://connect.microsoft.com/PowerShell/feedback/details/617705/windows-shell-bug-with-how-dp0-is-resolved. In the mean time if you make the FIRST statements in your batch as follows you can still use this trick:
@REM Must set these first thing due to bug in Windows 7 when batch script filename has spaces in it
SET BATCH_SCRIPT_DRIVE=%~d0
SET BATCH_SCRIPT_FOLDER_PATHNAME=%~dp0
You could then do
%BATCH_SCRIPT_DRIVE%
CD "%BATCH_SCRIPT_FOLDER_PATHNAME%"
to make the current working drive and directory the same as your scripts.

28 February, 2012

Recovering Windows and Software Keys

** copied verbatim from my good friend Mark Dan's excellent blog http://blog.callageek.com.au **

Product keys are one of the most valuable resources in your computer. Most people I do work for don’t have them backed up or even have their original CD/DVD’s.
Here is how I recover product keys in case a client’s computer crashes.
The methods described below will also work to back-up your product keys before your computer crashes.
If you are the vigilant type, and you should be, use a tool described below to back-up your software product keys before it’s too late.

Files needed to be copied

You will need to recover some files from your crashed computer’s hard drive. To do that you can either pull out the hard drive and plug it into a second computer using a spare hard drive connector or use a SATA USB docking station.

If you don’t have any SATA openings and don’t have a SATA docking station you can recover the files with a live Linux USB drive too. Use whatever distribution you feel comfortable with because you just need to copy a folder to the drive.

If you are using Linux, boot the broken machine from the drive, and copy this folder to the USB drive.

C:\Windows\System32\config

ProduKey is made by our friends at Nirsoft and will allow you to recover your product keys from a running version of Windows just the same as a copied
C:\Windows\System32\config folder.

image

Start by downloading ProduKey from the link below and extract the exe file to a place of your choosing. Launch the program and it will immediately recover the available product keys from your current Windows installation.

Now may be a good time to save your current product keys somewhere safe.

To recover the keys from the broken copy of Windows, drop down the file menu and choose select source.
From the new window select “load the product keys from external Windows directory” and then browse to your saved Windows folder.

If you used a live Linux disk to recover the config folder you will need to manually make Windows and System32 folders and then place your config folder inside of them for the keys to be read.

If you are using a USB docking station, you can also just select “load the product keys of external Windows installations from all disks currently plugged to your computer” and the drive will be scanned automatically.
ProduKey will now show you all the keys it was able to find from your broken computer which makes it very handy when needing to re-install.

To make sure your keys stay safe click the save icon and save a text file of your product keys. I recommend storing it in a safe place keeping all your keys together.

How to install Operating Systems from a Bootable USB Drive

** copied verbatim from my good friend Mark Dan's excellent blog http://blog.callageek.com.au **


One of the challenges with new Operating Systems especially SBS Server 2011, which is over 6GB.
Now I mostly install and test Operating System in a virtual environment and don’t needed to burn an ISO to a DVD.

The following steps will allow you to not only create a bootable SBS 2011 USB stick, but you can use the steps with any other bootable ISO to do pretty much the same thing.

1. Firstly you will need the Windows 7 USB/DVD Download Tool.
Download

2. You will a copy of your SBS 2011 ISO image or any other ISO image you would like to make bootable on a USB stick.
Note: Disable your AV software on your desktop machine as this has caused problems with accessing the USB stick during the copy process.

3. Install the Windows 7 USB/DVD download tool on your machine and you should be left with the icon as below
clip_image001

4. Run…..the tool and it will open as per the screen below.
clip_image002

5. Select….. the ISO file that you wish to copy to the USB

6. Select…. Next.
clip_image003

7. Choose…. the type of media you to burn the ISO file to

8. Select…. USB device below.
clip_image004

9. Verify that your USB drive is showing below. Use the refresh icon to refresh the selection if you had not plugged the USB drive in before you started.
Once you have selected the USB device

10. Select…..Begin Copying to commence the process.
clip_image005

NOTE: If the USB device has data on it, you will receive this message warning you that it will erase the device.

11. Select…. Erase USB Device to continue
clip_image006

NOTE: Confirm this message to erase the USB.

12. Select…. Yes
clip_image007

NOTE: The software utility will now format the USB device. But if you didn’t disable your AV software you will get the following error message.
Go Ahead and Disable your AV software and start the procedure again.
clip_image009

13. If you did disable your AV software the software utility will format the disk and start copying the required files to the USB drive from the ISO image.

NOTE: This can take some time depending on the speed of the USB stick and the amount of data to be copied relating to your image.
clip_image010

14. After the copy process is complete, you have a completed bootable USB stick that you can use to build your Operating System.
clip_image011

15. remember the USB stick is NOT a read only copy, you need to remember that other things can be copied to the USB stick.
This can be good thing as you can copy other software on the USB stick that you might use in your fresh installation/build,

NOTE: At this point go and re-enable your AV software.

How To Disable or Enable the Homegroup Feature in Windows 7

** copied from howtogeek **

Have you ever used the Homegroup feature in Windows 7? It’s a great way to share files and printers with all your Windows 7 computers, but if you don’t want it anymore, you can disable or enable the feature easily.
image
Before you bother disabling it, you should make sure to check out our articles explaining how it works, and why it’s great:
Still not convinced? Keep reading.

Disable the Homegroup Feature in Windows 7

The first thing you’ll want to do is open up Windows Explorer, right-click on the Homegroup option in the left-hand pane, and then choose Change HomeGroup settings.

At the bottom of the window, you’ll find an option called “Leave the homegroup”, which you should click.
Now you’ll be presented with a wizard asking you to confirm that you really want to leave the homegroup.

This disables the homegroup, but doesn’t remove it from the navigation pane.

Remove Homegroup from the Navigation Pane

Next, you’ll want to open up services.msc in the start menu search box, or just find it through Control Panel. Find HomeGroup Listener in the list, and double-click on it.
Change the Startup type to Disabled, and click the Stop button to stop the service. Once you’re done with that, you’ll need to disable the Homegroup Provider service in the same way.

At this point you’ll notice that it’s gone from the navigation pane.

Again, we recommend you learn how the feature works, but if you don’t want to, it’s pretty easy to disable, right?

How to Enable Homegroups Again

First, you’ll want to enable the service again—head back into services.msc, find the HomeGroup Listener and set it to automatic. Next, head into Control Panel –> Network and Internet, and then click on HomeGroup.
Then, simply click on the Create a Homegroup button, and follow the prompts. If your button says Join a homegroup, follow that wizard instead.

Windows 7 Boot Optimization Error

** copied verbatim from my good friend Mark Dan's excellent blog http://blog.callageek.com.au **

I am not sure if you know you can manually invoke Windows 7 defragmentation Tool to do boot optimization by using the /b flag.
When you run defrag.exe, you get the following error "the parameter is incorrect. (0×80070057)"

Description:
Locates and consolidates fragmented files on local volumes to improve system performance.
Syntax:

defrag | /C | /E [/H] [/M | [/U] [/V]]
defrag | /C | /E /A [/H] [/M | [/U] [/V]]
defrag | /C | /E /X [/H] [/M | [/U] [/V]]
defrag /T [/H] [/U] [/V]

Parameters:
Value Description
/A Perform analysis on the specified volumes.
/C Perform the operation on all volumes.
/E Perform the operation on all volumes except those specified.
/H Run the operation at normal priority (default is low).
/M Run the operation on each volume in parallel in the background.
/T Track an operation already in progress on the specified volume.
/U Print the progress of the operation on the screen.
/V Print verbose output containing the fragmentation statistics.
/X Perform free space consolidation on the specified volumes.
Examples:
defrag C: /U /V
defrag C: D: /M
defrag C:\mountpoint /A /U
defrag /C /H /V

Notice there is no /B flag but it is there.
However on a fresh Windows 7 installation when you try to do this with Administrative Permission in a Command Prompt Window.
C:\Windows\system32>defrag C: /B
You get some message saying it cannot be done like the following:

Microsoft Disk Defragmenter
Copyright (c) 2007 Microsoft Corp.
Invoking boot optimization on (C:)…
Analysis: 100% complete.
Some registry entries were missing from the boot optimization section of the registry. (0×89000017)


How to resolve this?

The issue is the idle tasks Windows is scheduled to run hasn’t run once yet hence it cannot initialize boot optimization.
So to resolve simply open a Command Prompt Windows with Administrative Permission again and run the following commands to invoke the idle task.
C:\Windows\system32>Rundll32.exe advapi32.dll, ProcessIdleTasksAfter that the error message will be gone and you can run boot optimization manually.


Why doesn’t this happen sometimes?

Because RunIdle task is scheduled to run eventually after sometime of idle usage if you do boot defrag immmediately after installation,
RunIdle task hasn’t got a chance to run at all so you have to invoke it manually if you want to start the operation immediately.

Reset Your Forgotten Windows Password

** copied verbatim from my good friend Mark Dan's excellent blog http://blog.callageek.com.au **


Forgetting your password is never any fun, but luckily there’s a really easy way to reset the password.
All you need is a copy of the Windows installation disk and one simple command line trick.
Resetting Your Forgotten Windows Password
Boot off the Windows disk and select the “Repair your computer” option from the lower left-hand corner.
image
Follow through until you get to the option to open the Command Prompt, which you’ll want to select.
image
First you’ll want to type in the following command to backup the original sticky keys file:
copy c:\windows\system32\sethc.exe c:\
Then you’ll copy the command prompt executable (cmd.exe) over top of the sticky keys executable:
copy c:\windows\system32\cmd.exe c:\windows\system32\sethc.exe
image
Now you can reboot the PC.

Resetting the Password
Once you get to the login screen, hit the Shift key 5 times, and you’ll see an administrator mode command prompt.
image
Now to reset the password just type the following command, replacing the username and password with the combination you want:
net user Mark NewPassword
image
Now you can login with your new password.

Checking MAK Product Key Remaining Activation Count

** copied verbatim from my good friend Mark Dan's excellent blog  http://blog.callageek.com.au **


MAK (Multiple Activation Key) product key, is the product key that is provided by Microsoft to its customers on volume licensing agreements to activate many computers running Windows Operating System/Office suite.
Corporate clients of Microsoft has a choice of activating the systems running in their organizations through KMS host or MAK product key. The MAK product key allows companies to activate against Microsoft’s server instead of having installed and maintained a server running KMS service.
One MAK product keys can potentially activate hundreds or even thousands of computers running Windows Vista or Windows 7, or Office 2010 (separate type of product keys for two different products required).
The number of activations can be done by each product key is determined by the software licensing agreements (and the money paid to Microsoft).
Once a MAK product key is been used to activate many machines, most administrators lose count of actual times of remaining activations that can be done with the serial codes.
In addition, some MAK product keys may have been “leaked” to Internet, or “shared” with outsiders, causing the numbers of remaining activation count available dwindling faster than expected.
Microsoft provides a Volume Activation Management Tool (VAMT) which can be used to check how many activations remain unused for a MAK product key.
If you have a MAK product key, you can check how many activations remain using Volume Activation Management (VAMT) Tool:

1.Download and install Volume Activation Management Tool (VAMT).
2.Select….Product Keys in the left pane.
3.Enter….Product Key and a Remark.
4.Click….Verify button.
5.Click….Add Product Key button.

image

6.Highlight…. the product key in the list below
7.Click….Refresh Product Key Data Online on the right.

image

8.Check… the product keys listing frame for remaining activation count, which means the number of times that product key can still be used to activate a Microsoft Windows or Office system.

Access your web browsers address bar via the keyboard

You’re browsing the web, going to all the sites you love, and you’re coming down with hand cramps from constantly going back to the mouse just to go back to the address bar so you can type in your next destination. These keyboard shortcuts can save you the trouble.
Making the trip up to your browser’s address bar directly from the keyboard is very easy, but it does vary from browser to browser. Here’s a breakdown:

Firefox: Control/Command + L
Chrome/Safari/WebKit: Control/Command + L
Internet Explorer: Alt + D
Opera: Control/Command + L

Here’s an added bonus. If your browser has a separate search box

Firefox: Control/Command + K
Safari: Command + Option + F
Internet Explorer: Control + E
Opera: Control/Command + E

If you’re not familiar, use Command for a Mac and Control for a Windows machine.
There are many useful browser shortcuts, but this one ranks pretty high. 
All joking aside, it is really annoying to constantly have to use the mouse to go to the address bar.

msosync.exe Process… What is it ?

** Copied verbatim from my good friend Mark Dans excellet site http://blog.callageek.com.au **



If you are using Office 2010, you may have come across MSOSYNC.EXE process in the Task Manager.

MSOSYNC.EXE Process?

Microsoft Office 2010 now caches your document for faster viewing. Whether it is a Word document, Excel spread sheet, or a PowerPoint presentation, Office 2010 will cache the documents. Msosync.exe process stands for Microsoft Office Document Cache and is used to cache the documents. In layman’s term, Msosync.exe process makes caching of Office 2010 documents possible.

What happen if you Kill the process?

It’s safe to end the process. It takes 2-3MB of system memory and does not effect the overall speed of the OS. It will start again when Office 2010 begins to cache a document.
Microsoft Office Document Cache

What else is this process used for?


Remember Office 2010 Upload Center?
The documents when uploaded to SkyDrive are cached in the local drive for faster viewing. You can view all cached files by opening Upload Center and then selecting All Cached Files from the drop-down menu.
Short Tip for Beginners: Open Upload Center by typing Upload Center in Start Searchand then hit Enter.
Office 2010 Upload Center Cached Files

How to Delete cached documents?

Office 2010 by default reserves 10% quota for cached documents. In my case it equals to 14.5Gb of space, which is a lot. To delete cache, head over to Upload Center settings and hit the Delete Cached Filesbutton.
Upload Center Settings
When prompted for confirmation, hit Delete Cached Informationbutton.
office 2010 delete cache
This will delete all cached files and free up some disk space along the way. Since there is a direct relationship between the MSOSYNC.EXE process and the Document Cache, we have covered both tips in this post.