Saturday, January 29, 2011

Issue to get process id of the IExplore on Windows vista or later

If we want to get id  of the process and get detail about that process or kill that process 

Then it’s not as strait as getprocessbyName inbuilt method. 


This issue happens to get detail about process iexplore. With windows version later than vista and IE version higher than 6 this issue occurs. 

This issue is due to the way the new IE manage the session so they are managing the process created in some different way. So if we get directly id by “getProcessByName” or “getProcessByID” will not work. 

For that I have found on net one good solution to get Id of IE process on vista or later by below link..


http://www.jeff.wilcox.name/2008/09/using-ielaunchurl-in-c-to-launch-a-protected-mode-internet-explorer-7-window/

Thanks to Jeff Wilcox here it’s given nice explanation and implementation of the whole procedure to get the Id of the process for vista or later. 

So after you get the id of the process with the above method  is not only enough then after have to get parent process of the process get by above method. 


So this parent process is the actual process started by IE. So we can use id of that to do whatsoever  kill process or retrieve some information. 

Hope this will be helpful to resolve really weird issue with the IE process on vista or later.

Thanks
Tushar 

Automate windows authentication process in browser

Once i was faced issue to show the windows authenticated site  browser control in window application.

Becuase it shows pop-up to ask credentials but i want to automate that task so that it not ask for

credential when passed in code.

For that form class has to be implemented from

IOleClientSite, IServiceProvider, IAuthenticate
 
definitions for that you can find on net.
 
after insert defination of above inside our project inside on class you can implement that 
inside form code.
 
So then on form load you have to first move to "about.blank" page before actually navigate
the page you want to access. Because it useful to eliminate issue IE sometimes not
call authenicate process of IAuthentiate at first run.
So form load event has to be something like
private void form1_Load(object sender, EventArgs e)
    {
 
//Navigate to about:blank to avoid authentication
// issue on Ie
    string oURL = "about:blank";
    webBrowser1.Navigate(oURL);

   // NOe set the ole object 
    object obj = webBrowser1.ActiveXInstance;
    IOleObject oc = obj as IOleObject;
    oc.SetClientSite(this as IOleClientSite);
    } 

 two methods which needs to be implemented here is as below
 
public static Guid IID_IAuthenticate = new Guid("79eac9d0-baf9-11ce-8c82-00aa004ba90b");
    public const int INET_E_DEFAULT_ACTION = unchecked((int)0x800C0011);
    public const int S_OK = unchecked((int)0x00000000);
 
 
public int QueryService(ref Guid guidService, ref Guid riid, out IntPtr ppvObject)
    {
    int nRet = guidService.CompareTo(IID_IAuthenticate); // Zero returned if the compared objects are equal
    if (nRet == 0)
    {
    nRet = riid.CompareTo(IID_IAuthenticate); // Zero returned if the compared objects are equal
    if (nRet == 0)
    {
    //This method returns an interface pointer that represents the requested interface on the specified object. It is particularly useful if you have an unmanaged method that expects to be passed an interface pointer; Add to the COM interface reference count.
    ppvObject = Marshal.GetComInterfaceForObject(this, typeof(IAuthenticate));
    return S_OK;
    }
    }
    ppvObject = new IntPtr();
    return INET_E_DEFAULT_ACTION;
    }
 
 public int Authenticate(ref IntPtr phwnd, ref IntPtr pszUsername,
    ref IntPtr pszPassword)
    {
    //Copies the contents of a managed String to a block of memory allocated from the unmanaged COM task allocator.
    IntPtr strUser = Marshal.StringToCoTaskMemAuto(txtUserID.Text);
    IntPtr strPassword = Marshal.StringToCoTaskMemAuto(txtPassword.Text);


    pszUsername = strUser;
    pszPassword = strPassword;
    return S_OK;
    }
 
 
 
I hope this above information is useful to resolve the issue  like i have faced.
 
If you want the complete souce code implementation than mail me. i will be back to you with that.
 
 
 
Thanks
Tushar 
 
 
 

Sunday, December 5, 2010

Issue to run command PSExec (PSTools command) over 64Bit OS

    When you execute the PSTools command PsExec over 64-Bit os
it always gives invalid path error  and not able to execute
PsExec command over 64bit os. This may happen because PsExec is copying command over it's systemdirectory and run that exe from there but in 64Bit os it directly copies content to 64-bit compatible system directory so 32bit appliaction not able to copy there so it gives path not found error.

    So for that you have to create the .cmd file and write the code as below and you have to execute command file over there and it will do rest of the things for you.

so this can work for both 64-Bit and 32-Bit also.




@echo off

if exist %WinDir%\SysWow64 cd /d %WinDir%\SysWow64

copy file://SourceHostName/SharedFolderFromSourceHost/ExenameWantToExecute

ExenameWantToExecute  ExeArguements




    Copy above code to text file and save it as .cmd file and now you can use it with the
pstools command.

Hope this will be helpful to resolve issue with 64-Bit OS.

Saturday, December 4, 2010

Cross Thread Exception







    In multi threaded application when you start you application and create one thread to preform some action in background and when you set some controls property over that thread you may be getting "Cross-Thread exception". In this case you can not set property of the control from the thread other then where it initialized.so you can set the property with the use of reflection as below.






private sub SetControlPrpertyValue(byval oControl as control, byval propcName as string,byval propValue as string) 

 If oControl.InvokeRequired Then 

oControl.Invoke(d,
Dim d As New SetControlValueCallback(AddressOf SetControlPrpertyValue)New Object() {oControl, propName, propValue}) 

Else
Dim t As Type = oControl.[GetType]() 
Dim props As PropertyInfo() = t.GetProperties()

 For Each p As PropertyInfo In props 
    If p.Name.ToUpper() = propName.ToUpper()  Then 
         p.SetValue(oControl, propValue, Nothing)
       
    End If
 Next
end
End if
End Sub

Telerik RadAjaxManager object return null on subsequent request

PageAjaxManager in second request .

It work well with first ajax request but in second request  $find("<%= PageAjaxManager.ClientID %>") return null.

This problem occurs browsers other than IE. In IE all ajax request are fired successfuly

Then set the EnablePageHeadUpdate property of PageAjaxManager as below and it will solve that issue. 


<telerik:RadAjaxManager ID="PageAjaxManager" runat="server" OnAjaxRequest="AjaxManager1_AjaxRequest" EnablePageHeadUpdate="false" EnableAJAX="True" UpdatePanelsRenderMode="Inline" >

Hope it may be helpful to resolve your issue. 

Thursday, November 18, 2010

Windows7 msg command usage

In Windows7 there is no direct command like netsend. 
Here you can use "Msg" command for same purpose. 
you can create a .bat file with following and can  use it diectly. 
@echo off
cls
echo.
set choice=
set /p choice=Enter in the target hostname or IP:
set choice1=
set /p choice1=Enter in the Message:
msg /SERVER:%choice% console %choice1%
pause

But before that you have to make sure on remote pc where you are goin to send this message has enabled the following key: 

HKLM\System\CurrentControlSet\Control\Terminal Server
Dword=AllowRemoteRPC
Value=1

Check comma separated values exist within the column having comma separated data

If you want to select records from table which having match some text in comma sperated list given by user with the values within the column of table having also data in comma seperated manner you can do query over table like below.


Select * from Table1
WHERE          exists(select val from Split([Column1],',') where val in (select val from Split(@CommaSeperatedList,',') ))