“Snap-in failed to initialize” error message when you open Microsoft Management Console

When running Microsoft Management Console if you get the error where it fails to initialize, one possible fix could be as from the following link http://support.microsoft.com/default.aspx?Product=winxp&scid=kb;en-us;826282

Fix is
To resolve this behavior, add the %SystemRoot%\System32\WBEM folder to your PATH environment variable. To do so, follow these steps:

1. Right-click My Computer, and then click Properties.
2. On the Advanced tab, click Environment Variables.
3. Under System Variables double-click the PATH environment variable.
4. Type:
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\system32\WBEM

Advertisements

How to loop through parameters in batch file?

The following example shows how to loop through parameters in batch file.

c:> TYPE script.bat
@ECHO OFF
:TOP

IF (%1) == () GOTO END
ECHO %1

SHIFT
GOTO TOP

:END
ECHO End

Sample Ouptut:
C:\>.\script.bat aaa bbb
aaa
bbb
End

How to monitor CPU of oracle processes on Windows?

Using QSlice one can monitor CPU usage for individual thread on a windows box. Qslice can be downloaded from the following url http://www.microsoft.com/downloads/en/details.aspx?familyid=6247BB76-13C5-4E0E-B800-53DC1B84A94C&displaylang=en

By clicking on the oracle.exe in Qslice it displays all threads and CPU usage for each thread, so using the following SQL you can match the corresponding SID.

SQL> select to_char(p.spid, 'xxxxxxxx') threadid, s.sid, s.username, s.program
from v$process p, v$session s
where p.addr=s.paddr;

Sample output:
THREADID SID USERNAME PROGRAM
——— ———- —————————— ————————-
d90 125 ORACLE.EXE (PMON)
1728 187 ORACLE.EXE (VKTM)
1660 1 ORACLE.EXE (GEN0)
d84 64 ORACLE.EXE (DIAG)
1794 126 ORACLE.EXE (DBRM)
144c 188 ORACLE.EXE (PSP0)

Script to change date on a computer

'
' script to change computer date
'
DIM objShell

strComputer = "." ' current host
' get current time
Set objWMIService = GetObject("winmgmts:{(Systemtime)}\\" & strComputer & "\root\cimv2")
Set colOS = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem WHERE Primary=True")

For Each objOS In colOS
Exit For
Next
Wscript.Echo "Current Date: " & strDate
strNow = objOS.LocalDateTime

' loop through to get last 5 date
FOR counter=1 TO 5
' get current system date – 1
dtPrev = DateAdd("d", -1, Date)
' get month
dtMonth = Month(dtPrev)
If dtMonth < 10 Then
dtMonth = "0" & dtMonth
End If

' get day
dtDay = Day(dtPrev)
If dtDay < 10 Then
dtDay = "0" & dtDay
End If

dtStrPrev = Year(dtPrev) & dtMonth & dtDay ' set previous date string
strDate = dtStrPrev & Right(strNow, Len(strNow) – 8) ' set date
Wscript.Echo "Setting Date to: " & dtStrPrev
objOS.SetDateTime strDate ' set new date
' perform task with new date
set objShell = wscript.createObject("wscript.shell")
iReturn = objShell.Run("cmd.exe /C set var=hello", 1, TRUE)
Next

objOS.SetDateTime strNow ' Set the date back to what it was before
Wscript.Echo "Date Reset: " & Date

Output:
C:\temp>cscript c.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

Current Date: 20100929221421.174000-360
Setting Date to: 20100928
Setting Date to: 20100927
Setting Date to: 20100926
Setting Date to: 20100925
Setting Date to: 20100924
Date Reset: 9/29/2010

Powershell

Powershell – Powershell is in an interactive shell which supports scripting. You can download this from http://support.microsoft.com/kb/926139

Displays all the command available in Powershell
PS>Get-Command

CommandType Name Definition
———– —- ———-
Cmdlet Add-Content Add-Content [-Path] [-Value] <Object[…
Cmdlet Add-History Add-History [[-InputObject] ] [-Pass…

Get-Help [Name] – Help on command with description and parameter it takes
PS>Get-Help Get-Process

NAME
Get-Process

SYNOPSIS
Gets the processes that are running on the local computer.

SYNTAX
Get-Process [[-name] ] []

Get-Process -id []
Get-Process -inputObject []
….

Process Information

Process Information – Powershell has feature allows one to list process information, list process by name. Also one can terminate process using “Stop-Process”

PS>Get-Process -Name <program name>

Example:
PS>Get-Process -Name gvim

Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
——- —— —– —– —– —— — ———–
95 7 3208 9496 65 0.16 172 gvim
108 7 3696 4900 65 0.95 1456 gvim

PS>Get-Process -Verbose

Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
——- —— —– —– —– —— — ———–
282 20 7944 13256 105 0.95 2824 AdobeARM
95 8 1468 4404 29 0.00 2652 alg
60 5 2164 5320 54 0.09 760 atchk

— store process in a variable
PS>$process = Get-Process gvim
— print the value in the variable
PS>$process

Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
——- —— —– —– —– —— — ———–
92 7 3128 9484 62 0.16 172 gvim
108 7 3696 4900 65 0.95 1456 gvim

— Show process with name gvim and using whatif option it let one view and the operation that will be applied on it
PS>Get-Process -Name gvim | Stop-Process -whatif
What if: Performing operation “Stop-Process” on Target “gvim (172)”.
What if: Performing operation “Stop-Process” on Target “gvim (1456)”.

— Show process with name gvim and using whatif option it let you confirm before the process is killed
PS>Get-Process -Name gvim | Stop-Process -confirm

Confirm
Are you sure you want to perform this action?
Performing operation “Stop-Process” on Target “gvim (172)”.
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is “Y”): N

Confirm
Are you sure you want to perform this action?
Performing operation “Stop-Process” on Target “gvim (1456)”.
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is “Y”): Y