Hviidnet.com
21Jan/090

Exclude VMware Virtual Adapters from Network Awareness

Because the VMware virtual network adapters appear to be in a “Public network”, Windows thinks that the whole machine is exposed to a public network, and it triggers the public profile for Windows Firewall. While in most cases this helps protect the entire computer from external access, sometimes you actually need to have external access, and therefore you need to manually change the setting.

Make this file: network.ps1 edit it and paste in the following:

# see <a href="http://msdn2.microsoft.com/en-us/library/bb201634.aspx">http://msdn2.microsoft.com/en-us/library/bb201634.aspx</a>
#
# *NdisDeviceType
#
# The type of the device. The default value is zero, which indicates a standard
# networking device that connects to a network.
#
# Set *NdisDeviceType to NDIS_DEVICE_TYPE_ENDPOINT (1) if this device is an
# endpoint device and is not a true network interface that connects to a network.
# For example, you must specify NDIS_DEVICE_TYPE_ENDPOINT for devices such as
# smart phones that use a networking infrastructure to communicate to the local
# computer system but do not provide connectivity to an external network.
#
# Usage: run in an elevated shell (vista/longhorn) or as adminstrator (xp/2003).
#
# PS> .\fix-vmnet-adapters.ps1

# boilerplate elevation check

$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = new-object Security.Principal.WindowsPrincipal $identity
$elevated = $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)

if (-not $elevated) {
$error = "Sorry, you need to run this script"
if ([System.Environment]::OSVersion.Version.Major -gt 5) {
$error += " in an elevated shell."
} else {
$error += " as Administrator."
}
throw $error
}

function confirm {
$host.ui.PromptForChoice("Continue", "Process adapter?",
[Management.Automation.Host.ChoiceDescription[]]@("&No", "&Yes"), 0) -eq $true
}

# adapters key
pushd 'hklm:\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}'

# ignore and continue on error
dir -ea 0  | % {
$node = $_.pspath
$desc = gp $node -name driverdesc
if ($desc -like "*vmware*") {
write-host ("Found adapter: {0} " -f $desc.driverdesc)
if (confirm) {
new-itemproperty $node -name '*NdisDeviceType' -propertytype dword -value 1
}
}
}
popd

# disable/enable network adapters
gwmi win32_networkadapter | ? {$_.name -like "*vmware*" } | % {

# disable
write-host -nonew "Disabling $($_.name) ... "
$result = $_.Disable()
if ($result.ReturnValue -eq -0) { write-host " success." } else { write-host " failed." }
# enable
write-host -nonew "Enabling $($_.name) ... "
$result = $_.Enable()
if ($result.ReturnValue -eq -0) { write-host " success." } else { write-host " failed." }
}

Next, open a PowerShell prompt. Note that you need to run it with elevated credentials (i.e. "Run as Administrator").

Navigate to the folder where you've placed the script, and execute it. You can type the first letter of the script's name and press TAB to auto complete the script's name.

If you get an error like this:

File D:\Tools\Admin\Scripts\VMware - VMNET Adapters Triggering Public Profile for Windows Firewall\script.ps1 cannot be loaded because the execution of
scripts is disabled on this system. Please see "get-help about_signing" for more details.

you will have to write the following first:

Set-ExecutionPolicy Unrestricted

And wola! stuff works!

For the original article take a look at www.petri.co.il. He does some GREAT work for all windows server stuff.

19Dec/080

Rebuilding the WMI Repository

If you experience behavior when using WMI, such as application errors or scripts that used to work are no longer working, you may have a corrupted WMI repository. To fix a corrupted WMI repository, use these steps:

Windows XP and Windows Vista

Click Start, Run and type CMD.EXE

Note: In Windows Vista, you need to open an elevated Command Prompt window. To do so, click Start, click All Programs, click Accessories, right-click Command Prompt, and then click Run as administrator.

Type this command and press Enter:

net stop winmgmt

Using Windows Explorer, rename the folder %windir%\System32\Wbem\Repository. (For example, %windir%\System32\Wbem\Repository_bad). %windir% represents the path to the Windows directory, which is typically C:\Windows.

Switch to Command Prompt window, and type the following and press ENTER after each line:

net start winmgmt

EXIT

Courtesy: The above is excerpted from Microsoft Technet article WMI Isn't Working!
© 2007 Microsoft Corporation. All rights reserved.

For Windows XP Service Pack 2

Click Start, Run and type the following command:

rundll32 wbemupgd, UpgradeRepository

This command is used to detect and repair a corrupted WMI Repository. The results are stored in the setup.log (%windir%\system32\wbem\logs\setup.log) file.

For Windows Vista

Open an elevated Command Prompt window. To do so, click Start, click All Programs, click Accessories, right-click Command Prompt, and then click Run as administrator.

Type the following command:

winmgmt  /salvagerepository

The above command Performs a consistency check on the WMI repository, and if an inconsistency is detected, rebuilds the repository. The content of the inconsistent repository is merged into the rebuilt repository, if it can be read.

For Windows Server 2003

Use the following command to detect and repair a corrupted WMI Repository:

rundll32 wbemupgd, RepairWMISetup

Re-registering the WMI components (Ref WMI FAQ)

The .DLL and .EXE files used by WMI are located in %windir%\system32\wbem. You might need to re-register all the .DLL and .EXE files in this directory. If you are running a 64-bit system you might also need to check for .DLLs and .EXE files in %windir%\sysWOW64\wbem.

To re-register the WMI components, run the following commands at the command prompt:

  • cd /d %windir%\system32\wbem
  • for %i in (*.dll) do RegSvr32 -s %i
  • for %i in (*.exe) do %i /RegServer

Note that none of the above two methods restore the missing files related to Windows Management Instrumentation (WMI). So, below is a comprehensive repair procedure that restores all the missing WMI modules. In case of missing WMI modules, you may use the following method.

Comprehensive rebuild method

Important note: If you've installed a Service Pack, you need to insert your Windows XP CD with Service Pack integration (called as the Slipstreamed Windows XP CD). If you don't have one, you may point to the %Windir%\ServicePackFiles\i386 folder for a recent version of the system files required during WMI repair. Or you may create a slipstreamed Windows XP CD and insert it when prompted.

Click Start, Run and type the following command, and press ENTER:

rundll32.exe setupapi,InstallHinfSection WBEM 132 %windir%\inf\wbemoc.inf

Insert your Windows XP CD into the drive when prompted. Repair process should take few minutes to complete. Then restart Windows for the changes to take effect.

18Dec/080

How do I save my Outlook Password?

When using RPC/HTTPS connection in Outlook, you will need to follow the instructions below to store your password so Outlook will not prompt you for credentials. You must be running on Windows XP or Vista (any edition except Windows Home).

  1. In Outlook,  Go to: Tools > Email Accounts > Click Next to View or change existing email accounts > Highlight Microsoft Exchange Server and click Change > Click More Settings > Connections tab > Exchange Proxy Settings.
  2. Select NLTM Authentication as the Proxy Authentication Setting
  3. Check Connect using SSL only and Mutually authenticate the session when connecting with SSL
  4. The Principle name for the proxy server is in the following format:
    • msstd:proxy.server.com (proxy.server.com is the same as the Proxy Server URL)
  5. Click OK and close all the Outlook Settings Windows
  6. Launch Outlook, and when prompted for your username and password, make sure to check the box ‘Save Password’ and login.
  7. In Windows, click the Start Menu > Run > Type in "control keymgr.dll’"
  8. You’ll see an entry now with the Exchange Server name. Select it can click Properties
  9. Change the first portion up to the first period ‘.’ with an asterisk ‘*’. Below is an example:
    • "Exvmbx017-10.exch017.msoutlookonline.net"  should be changed to "*.exch017.msoutlookonline.net" (without quotes)
    • For Windows Vista you will need to Add a new entry. For the Log on to field, you will need to replace everything up to the last period with an asterisk "*". Example: "*.msoutlookonline.net".
  10. Enter in your password and click OK

**Note: Only one account/password can be saved per Windows Profile**

Also note that the new outlook profile helper will allow you to save your password without doing any of the above changes.

12Nov/080

Shutdown / iisreset or regedit from commandline on remote host

simply autorize first with this command:

runas /noprofile /netonly /user:user@ip cmd

afterwards run

iisreset <computername>

shutdown /m \\computername /r /f /t 0

or run regedit and connect to remote host. Now that youre authenticated you CAN get access.

22Oct/080

Reading and writeing to files in C#

// file IO using class StreamWriter
//
// SnippetCompiler.exe was used to write, compile (uses .NET V2 csc.exe)

using System;
using System.IO; // TextWriter, StreamWriter

public class MyClass
{
public static void Main()
{
string text;

text = "Why Did the Chicken Cross the Road?\n";
text += "ARISTOTLE: It is the nature of chickens to cross roads.\n";
text += "RONALD REAGAN: I forget.\n";
text += "CAPTAIN JAMES T. KIRK: To boldly go where no chicken has gone before.\n";
text += "ERNEST HEMINGWAY: To die. In the rain.\n";
text += "COLONEL SANDERS: I missed one?";

// create a writer and open the file
TextWriter tw = new StreamWriter("date.txt");

// write a line of text (present date/time) to the file
tw.WriteLine(DateTime.Now);

// write the rest of the text lines
tw.Write(text);

// close the stream
tw.Close();

// read the text file back ...
// create reader & open file
TextReader tr = new StreamReader("date.txt");

// read first line of text (here date/time)
Console.WriteLine(tr.ReadLine());

// read the text, next 2 lines
Console.WriteLine(tr.ReadLine());
Console.WriteLine(tr.ReadLine());

// read the rest of the text lines
Console.WriteLine(tr.ReadToEnd());

// close the stream
tr.Close();

// wait to look at console display
Console.Write("\nPress Enter to exit ...");
Console.Read();

}
}

Tagged as: , No Comments