June 2, 2011

Separate domain and Runas

Filed under: networking,windows plateform Himanshu @ 1:45 pm

Have you ever wonder how can you run a specific application having awareness of different domain’s credentials? We have VPN setup between our different offices, and all offices are having complete separate windows domain tree. I’m in Pune office, that is having domain, which has not direct relation to our US office (e.g. it’s not welcomed in networking terms) – and believe me there is a good reason to be it that way.

While being in Pune, I needed to run an application on my machine (that is in Pune domain), with is aware that I also have valid credentials in our US office. And Runas worked well in that case as well. Runas.exe can be found in %WINDIR%\System32, checkout its short help by: %windir%\system32\runas.exe /? on command prompt.

I had used it as %WINDIR%\System32\runas.exe /netonly /user:<my US domain name>\<my username in US domain name> “<path to the application that should run within that credentials>”

January 21, 2011

Upgrading XP by SP3 on Laptop

Filed under: windows plateform Himanshu @ 7:34 pm

I was trying to apply Windows XP SP3 through windows auto updates.  Auto update repeatedly reported that it couldn’t apply SP3 update. After digging further, I found that update was failing because laptop was not on AC supply.

Two points to note:

  1. On laptop, shouldn’t apply windows update while battery powered
  2. Interesting to understand that either xp auto update do not have way to report correct problem and instead just say “Could not apply following updates”, or maybe SP3 installer is not rightly coded for auto update.

February 2, 2010

Ignorance is not bliss. EventWaitHandle.OpenExisting throws WaitHandleCannotBeOpenedException

Filed under: .net,windows plateform Himanshu @ 12:06 pm

My development computer got upgraded to Windows 7, Windows 7 is good experience.

For one of our client, I needed to setup mechanics such that admin users should be able to initiate a process in Windows Service using GDI based .NET application. We had also developed the windows service in .NET. As both of them are .NET applications, there are more than one ways to IPC between them. As in this case there was only need to give signal to the service, I choose to do it through Windows Event. .NET BCL provides wrapper around Win32 functions to do this through type named EventWaitHandle.

I completed the code like I used to do in my old days, and tried the first use of it. On call to OpenExisting, client application failed with exception “No handle of the given name exists”. My first thought was that this could be because of UAC, but in that case it should say something like access violation. I tried running application in Windows 2003 Server and it worked perfectly. I decided to check documentation.

After some time I landed to msdn page for namespaces of kernel objects, which indicates that:

For processes started under a client session, the system uses the session namespace by default. However, these processes can use the global namespace by prepending the “Global\” prefix to the object name

changed my client code to have name prefixed with “Global\”, and everything started behaving the way I wanted it to in Windows 7 as well.

January 10, 2009

Knowing memory usage from Compact Framework application

For any handheld device application, memory usage is an important element to observer. .NET Compact framework have very less code that gives information about physical or virtual memory. But using native libraries – by doing pInvoke, one can retrieve memory usage statistics.

There can be more than one level of report that can be captured. Today, lets start with summary. GlobalMemoryStatus function in coredll can help identifying how much total physical memory available in the device and how much of it is free. Same way, how much of virtual memory available to process and how much of it is free.

Lets see how can we use GlobalMemoryStatus. We will have to define a class which will be passed to function and will be filled by GlobalMemoryStatus function. Layout of it is defined as structure by MS team, but its alright to use class here. By having it as class, we will be able to write default constructor unlike structure in C#.

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
    internal class MemoryStatus
        public uint dwLength;
        public uint dwMemoryLoad;
        public uint ullTotalPhys;
        public uint ullAvailPhys;
        public uint ullTotalPageFile;
        public uint ullAvailPageFile;
        public uint ullTotalVirtual;
        public uint ullAvailVirtual;
        public uint ullAvailExtendedVirtual;
        public MemoryStatus()
            this.dwLength = (uint)Marshal.SizeOf(typeof(MemoryStatus));

Now, lets define extern method for GlobalMemoryStatus

        [return: MarshalAs(UnmanagedType.Bool)]
        [DllImport("coredll.dll", CharSet = CharSet.Auto, SetLastError = true, EntryPoint = "GlobalMemoryStatus")]
        static extern bool GlobalMemoryStatusWinCE([In, Out] MemoryStatus lpBuffer);

And here is how we can call the method

    MemoryStatus internalReport = new MemoryStatus();
    if (GlobalMemoryStatusWinCE(internalReport))

Powered by WordPress