C# – How to check whether the application running with Administrator privilege?

 

A simple snippet can help you

using System.Security.Principal;
public bool IsAdmin()
{
    try
    {
        WindowsIdentity user = WindowsIdentity.GetCurrent();
        WindowsPrincipal principal = new WindowsPrincipal(user);
        return principal.IsInRole(WindowsBuiltInRole.Administrator);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
        return false;
    }
}
 

The case of Visual Studio 2008 SP1 crash on Docking/Undocking and Switching from Debugging to Design View

 

I’m using dual monitors with my laptop and I found that Visual Studio is crashing on docking/undocking window to/from other display. Although I am not do the same operation it was crashing again on switching back to design/code view from debugging.

I’m primary using IBM Clearcase as versioninig system and I have n number of issues ever since I started using with Windows 7. The same issue happened though I copied my source to local folder and debugging from there.

Simply took the dump and attached to WinDBG. !analyze -v had given me following call stack

EXCEPTION_RECORD:  002ad92c -- (.exr 0x2ad92c)
ExceptionAddress: 3fe083d0
   ExceptionCode: c0000005 (Access violation)
  ExceptionFlags: 00000000
NumberParameters: 2
   Parameter[0]: 00000008
   Parameter[1]: 3fe083d0
Attempt to execute non-executable address 3fe083d0

FAULTING_THREAD:  00002718

DEFAULT_BUCKET_ID:  SILENT

PROCESS_NAME:  devenv.exe

ERROR_CODE: (NTSTATUS) 0x80000003 - {EXCEPTION}  Breakpoint  A breakpoint has been reached.

EXCEPTION_CODE: (HRESULT) 0x80000003 (2147483651) - One or more arguments are invalid

NTGLOBALFLAG:  400

APPLICATION_VERIFIER_FLAGS:  0

MANAGED_STACK: !dumpstack -EE
OS Thread Id: 0x2718 (0)
Current frame:
ChildEBP RetAddr  Caller,Callee
002af168 71bc5a99 (MethodDesc 0x714cc250 +0x79 System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator[[System.Int32, mscorlib],[System.__Canon, mscorlib]].MoveNext())

CONTEXT:  002ad948 -- (.cxr 0x2ad948)
eax=59730146 ebx=00000000 ecx=01a72c50 edx=0000001d esi=01a72c50 edi=01a729c8
eip=3fe083d0 esp=002adc2c ebp=002adeb0 iopl=0         nv up ei ng nz na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010286
3fe083d0 ??              ???
Resetting default scope

WRITE_ADDRESS:  3fe083d0 

FOLLOWUP_IP:
msenv!CDockManager::PruneAllDeadPanes+45
5986cbf6 e97745f8ff      jmp     msenv!CDockManager::PruneAllDeadPanes+0x45 (597f1172)

FAILED_INSTRUCTION_ADDRESS:
+5789952f04fedcac
3fe083d0 ??              ???

PRIMARY_PROBLEM_CLASS:  SILENT

BUGCHECK_STR:  APPLICATION_FAULT_SILENT

LAST_CONTROL_TRANSFER:  from 5986cbf6 to 3fe083d0

IP_ON_HEAP:  3fe083d0
The fault address in not in any loaded module, please check your build's rebase
log at \bin\build_logs\timebuild\ntrebase.log for module which may
contain the address if it were loaded.

IP_IN_FREE_BLOCK: 3fe083d0

STACK_TEXT:
3fe083d0 unknown+0x0
5986cbf6 msenv!CDockManager::PruneAllDeadPanes+0x45
597eef9b msenv!CDockManager::SaveUI+0xb7
598122a5 msenv!CPane::TransitionToDesign+0x46
597f67a9 msenv!CVsShellDebugMgr::m_OnModeChange+0xe6
5976aca3 msenv!CVsUIShell::OnModeChange+0x21
5f4dbfa3 vsdebug!CDebugger::SetShellMode+0x9b
5f4dc04f vsdebug!CDebugger::OnModeChange+0x44
5f4dbeef vsdebug!CDebugger::SetDebugMode+0x69
5f4f2c93 vsdebug!CDebugger::OnExitBreakState+0xaa
5f53cab1 vsdebug!CDebugger::OnDebuggingStopped+0x6e
5f51bcb6 vsdebug!CDebugger::HandleEvent+0x8ae
5f4dbc19 vsdebug!CDebugger::Event+0xef
5f4dbaef vsdebug!sdm::CDebugManager::HandleEvent+0xb5
75eefc8f rpcrt4!Invoke+0x2a
75f54c53 rpcrt4!NdrStubCall2+0x2d6
75e9d936 ole32!CStdStubBuffer_Invoke+0xb6
75e9d9c6 ole32!SyncStubInvoke+0x3c
75e9df1f ole32!StubInvoke+0xb9
75db223c ole32!CCtxComChnl::ContextInvoke+0xfa
75db2131 ole32!MTAInvoke+0x1a
75db30fa ole32!STAInvoke+0x46
75e9de47 ole32!AppInvoke+0xab
75e9dcbb ole32!ComInvokeWithLockAndIPID+0x372
75e9e34c ole32!ComInvoke+0xc5
75db2ed2 ole32!ThreadDispatch+0x23
75db2e91 ole32!ThreadWndProc+0x161
762986ef user32!InternalCallWinProc+0x23
76298876 user32!UserCallWinProcCheckWow+0x14b
762989b5 user32!DispatchMessageWorker+0x35e
76298e9c user32!DispatchMessageW+0xf
75d7d6be ole32!CCliModalLoop::PeekRPCAndDDEMessage+0x4c
75d7d66d ole32!CCliModalLoop::FindMessage+0x30
75d7d57e ole32!CCliModalLoop::HandleWakeForMsg+0x41
75d7d633 ole32!CCliModalLoop::BlockFn+0xc3
75d71117 ole32!CoWaitForMultipleHandles+0xcd
5f513ed6 vsdebug!sdm::CDebugManager::WaitForEvent+0x8a
5f526aa0 vsdebug!CDebugger::WaitForDebuggingToStop+0x51
5f526fed vsdebug!CDebugger::TerminateSession+0x106
5f52711a vsdebug!CDebugger::StopDebugging+0x10a
5f4e8014 vsdebug!CVSDebugPackage::Exec+0x5f9
5974249f msenv!CVSCommandTarget::ExecCmd+0x937
59884617 msenv!FTranslateAcceleratorEx+0x4a3
597581c3 msenv!FTranslateAccelerator+0x49
59758045 msenv!MainFTranslateMessage+0x1a7
59757f2b msenv!CMsoComponent::FPreTranslateMessage+0x72
59757ec0 msenv!SCM_MsoStdCompMgr::FPreTranslateMessage+0xdd
5974152c msenv!EnvironmentMsgLoop+0x159
597fb9bd msenv!CMsoCMHandler::FPushMessageLoop+0x86
597fb94d msenv!SCM::FPushMessageLoop+0xb7
597fb8e9 msenv!SCM_MsoCompMgr::FPushMessageLoop+0x28
597fb8b8 msenv!CMsoComponent::PushMsgLoop+0x28
597fbe4e msenv!VStudioMainLogged+0x482
597f7561 msenv!VStudioMain+0xc1
2f6aaabc devenv!util_CallVsMain+0xff
2f6a78f2 devenv!CDevEnvAppId::Run+0x11fd
2f6a7bf4 devenv!WinMain+0x74
2f6a7c68 devenv!License::GetPID+0x258
765a1114 kernel32!BaseThreadInitThunk+0xe
7791b429 ntdll!__RtlUserThreadStart+0x70
7791b3fc ntdll!_RtlUserThreadStart+0x1b

SYMBOL_STACK_INDEX:  1

SYMBOL_NAME:  msenv!CDockManager::PruneAllDeadPanes+45

FOLLOWUP_NAME:  MachineOwner

MODULE_NAME: msenv

IMAGE_NAME:  msenv.dll

DEBUG_FLR_IMAGE_TIMESTAMP:  488f2b9f

STACK_COMMAND:  .cxr 002AD948 ; kb ; dds 2adc2c ; kb

FAILURE_BUCKET_ID:  SILENT_80000003_msenv.dll!CDockManager::PruneAllDeadPanes

BUCKET_ID:  APPLICATION_FAULT_SILENT_BAD_IP_msenv!CDockManager::PruneAllDeadPanes+45

WATSON_STAGEONE_URL:  http://watson.microsoft.com/StageOne/devenv_exe/9_0_30729_1/488f2b50/unknown/0_0_0_0/bbbbbbb4/80000003/00000000.htm?Retriage=1

Followup: MachineOwner
---------

Luckily a Google search with the call stack has returneda single relevant result about this issue in Microsoft Connect.

Visual Studio 2008 IDE Crashes Returning to Design Mode When Stopping Debugging Native C++ Code

Microsoft has released a patch to resolve this issue. Download

 

Tools: How to monitor log files in real-time?

 

It’s always painful for users that to see the log file in real-time. Probably we will do some logging mechanism and then the file will be updated by application and we’ve no way to track what’s happening.

Windows programmers rely on traces (OutputDebugString, Debug, Trace classes in .net) etc. which can be monitored in debugger output window or using handy tool called DbgView. But the pain here is we’ve to add the code again and take the build to see things in action.

What if we can do the same stuff with a tool? BareTail is real-time log file monitoring tool with lot of filtering options for highlighting and storage. It also supports multiple tabs, UNICODE/Non-Unicode files etc. Also it’s a standalone application where no installation required. So it’s suitable for using in the target machines where the installations of the softwares are restricted.