Posts

Some tricks and codes in VBScript

'Sample VBScript to kill a program Option Explicit Dim objWMIService, objProcess, colProcess Dim strComputer, strProcessKill strComputer = "." strProcessKill = "'application.exe'" Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2") Set colProcess = objWMIService.ExecQuery _ ("Select * from Win32_Process Where Name = " & strProcessKill ) For Each objProcess in colProcess objProcess.Terminate() Next WScript.Quit ' End of WMI Example of a Kill Process 'Sample VBScript to create a file Dim oAPI, oBag Set oAPI = CreateObject(“MOM.ScriptAPI”) Set oBag = oAPI.CreatePropertyBag() Set objFSO = CreateObject(“Scripting.FileSystemObject”) strFile = “C:\myfile.log” If objFSO.FileExists(strFile) Then Call oBag.AddValue(“Status”,”Ok”) Call oAPI.Return(oBag) Else Call oBag.AddValue(“Status”,”Error”) Call oAPI.Return(oBag) E

how to execute query from VBScript in script two state monitor SCOM

here is code : 'define and create objects for passing values in 2 state to SCOM Dim oAPI, oBag Set oAPI = CreateObject("MOM.ScriptAPI") Set oBag = oAPI.CreatePropertyBag() StrConnect = "PROVIDER=SQLOLEDB.1;Integrated Security=SSPI;INITIAL CATALOG=DBName;DATA SOURCE=ServerName" Set cnt = CreateObject("ADODB.Connection") cnt.Open StrConnect set recordSet = CreateObject("ADODB.Recordset") SQLStr = " select * from .... " recordSet.Open SQLStr, cnt,1,1 TotalRecords = recordSet.RecordCount recordSet.Close : set recordSet = nothing cnt.Close : set cnt = nothing 'We have to handle Status value from SCOM and create rule for each state If TotalRecords >= 0 Then Call oBag.AddValue("Status","ERROR") Else Call oBag.AddValue("Status","OK") End If Call oAPI.Return(oBag)

Credential while creating site in Share Point Portal

Call SPSecurity.CodeToRunElevated for executing CreateSite() method.This statement makes credential scope over Share Point server. exeample: SPSecurity.CodeToRunElevated elevatedGetSitesAndGroups = new SPSecurity.CodeToRunElevated(method which owns CreateSite method); SPSecurity.RunWithElevatedPrivileges(elevatedGetSitesAndGroups);

get error "The path is not of a legal form" during installation of Microsoft Dynamics CRM Data Migration Manager

Check registry key below ; [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\ \InstallProperties] Value: InstallLocation   if InstallLocation is empty,Wizard will be thrown an error about illegal path. Set it with correct path.Installation will continue.   GUI value = make a searchment under the products with "Data Migration" keyword to modify.

"Navigation to the webpage was canceled‏" seems in chm file pages.

First of all, make sure that hhctrl.ocx is registered in the windows system.if not run regsvr32 hhctrl.ocx command from prompt. Secondly, unlock the file from property menu by right click . good luck...

Cannot locate resource 'xxxxx.xaml' (Default: 'window1.xaml'). Windows Presentation Foundation

If you get an error message as in subject line; add [assembly: NeutralResourcesLanguageAttribute(/*"xx-XX" (for example :*/"en-US"/*)*/, UltimateResourceFallbackLocation.Satellite)] statement into AssemblyInfo.cs file on your project. Good Luck...

Stored Procedure Pattern in SQL Server 2005

Here is a basic stored procedure concept i personally offer to advanced SQL Server users; SET NOCOUNT ON DECLARE cur_sor CURSOR DECLARE @CURSOR_FETCH_STATUS INT DECLARE @varible1 as [anytype] ,@variable2 as [anytype],.... SET cur_sor = CURSOR LOCAL FORWARD_ONLY STATIC READ_ONLY FOR SELECT .... FROM ..... /* for Arguments Detail check http://msdn.microsoft.com/en-us/library/ms180169.aspx */ OPEN cur_sor BEGIN TRY BEGIN TRANSACTION FETCH NEXT FROM cur_sor INTO @varible1,@variable2 ,... /* not more than selected columns above*/ SELECT @CURSOR_FETCH_STATUS = @@FETCH_STATUS WHILE @CURSOR_FETCH_STATUS = 0 BEGIN ....... /* INSERT,DELETE,UPDATE ( DML) or any other process */ ....... FETCH NEXT FROM cur_sor INTO @varible1,@variable2 ,... SELECT @CURSOR_FETCH_STATUS = @@FETCH_STATUS END COMMIT END TRY BEGIN CATCH PRINT(ERROR_NUMBER()) PRINT(ERROR_SEVERITY()) PRINT(ERROR_STATE()) PRINT(ERROR_PROCEDURE()) PRINT(ERROR_LINE()) PRINT(ERROR_MESSAGE()) ROLLBACK END CATCH CLOSE cur_sor DEALLOCATE cur_so