[Powershell] Script to install software

Today I want to check whether the Windbg is installed on the target machine with expected version, and if not, install the correct version with Powershell. It turns out that Powershell is really powerful to do such things.

$dbgApp = get-wmiobject -class "Win32_Product" -namespace "root\CIMV2" | where {$_.Caption -like '*Debugging Tools for Windows*'};
if ($dbgApp -eq $null -or !$dbgApp.Version.StartsWith("6.13"))
{
    msiexec /passive /i D:\Debug\dbg_amd64.msi;
}

Windbg + SOS complains Failed to load data access DLL, 0x80004005

When I debug one .Net 4.0 program with SOS. After .loadby sos clr then run any SOS command results in following errors:

Failed to load data access DLL, 0x80004005 Verify that
1) you have a recent build of the debugger (6.2.14 or newer)
2) the file mscordacwks.dll that matches your version of mscorwks.dll is in the version directory
3) or, if you are debugging a dump file, verify that the file mscordacwks_.dll is on your symbol path.
4) you are debugging on the same architecture as the dump file. For example, an IA64 dump file must be debugged on an IA64 machine.
You can also run the debugger command .cordll to control the debugger's load of mscordacwks.dll. .cordll -ve -u -l will do a verbose reload. If that succeeds, the SOS command should work on retry.
If you are debugging a minidump, you need to make sure that your executable path is pointing to mscorwks.dll as well.

By google, some posts were found with same error info. But most of them are focus on the debugging dump on another machine with differnt mscordacwks version. This is not the case as I’m doing living debug. From the 1) hint of the error message I check the Windbg version is 6.6 and then install the newest version 6.13.0006. It works!
~~~~~~~
The same error happened during debug a Waston dump. The solution is

0:000> .cordll -ve -u -l
CLRDLL: Unable to find mscordacwks_AMD64_AMD64_2.0.50727.5005.dll by mscorwks search
CLRDLL: Unable to find 'mscordacwks_AMD64_AMD64_2.0.50727.5005.dll' on the path
CLRDLL: Unable to find mscorwks.dll by search
CLRDLL: ERROR: Unable to load DLL mscordacwks_AMD64_AMD64_2.0.50727.5005.dll, Win32 error 0n2
CLR DLL status: ERROR: Unable to load DLL mscordacwks_AMD64_AMD64_2.0.50727.5005.dll, Win32 error 0n2

The version we are trying to find is 2.0.50727.5005, while check the attribute of file mscordacwks.dll under D:\Windows\Microsoft.NET\Framework64\v2.0.50727 it turns out its version is 2.0.50727.4454. Copying the mscordacwks.dll from the machine where the dump was generated to the root path where Windbg is installed and rename it to mscordacwks_AMD64_AMD64_2.0.50727.5005.dll. It works!

掩耳盗铃

2011年的开始便颇有些热闹,YD作秀接见上*访的P民的确很不!和%谐^,而房产税在上海重庆的试点更是吸引眼球。
房产税实在不是什么新的东西,记得经济学原理里面提到了19世纪Henry George就提出了类似的土地税的概念,原因是他认为地主从整个经济增长中得到的利益大于他们应该得到的,是基于对经济福利分配的关注。当然网络上更有人考证出咱们的祖宗更伟大,在汉武帝时候便有更彻底的财产税,根据是史记中的“各以其物自占,率缗钱二千一算千而一算。诸作有租及铸,率缗钱四千一算”。
这个东西据说出发点是好的,据说可以调节贫富差距,这也是税收的一个重要目的,很不幸的是,This is China.
首先政府当然是永远的赢家。解决价格问题无非是两个途径,增加供给或者降低需求。而当供给或者需求缺乏弹性的时候,税收的无谓损失小。很不幸的是供给是非常缺乏弹性的,因为政府垄断了土地,所以市场会以最小的代价把财富转让给政府。这里可以明显看出来政府对于土地财政的依赖,而房产税更是火上浇油,同时可以看到政府不愿意损失自己的利益,否则增加土地出让的速度,控制出让的价格是明眼人都能看出来更有效的途径。
其次,这个事情无法调节贫富差距。某些垄断了重要资源的既得利益集团在没有任何有效制约的情况下必然是无休止地聚敛财富,真的能有效统计出他们有多少房产?那样的话估计很多人民的公仆都可以直接双规了。另一方面,如果租房市场的供给不充分,房东是很容易把这个代价转移到租房者的身上,而我没有看到任何相匹配的措施比如新建大量的公共租赁房。所以结果很可能适得其反。
我觉得房产税不过是掩耳盗铃中的手罢了。顺便感慨一下,同一阳光之下没有新的东西,比如去年的恨爹不成刚,在史记货殖列传中便有“千金之子,不死于市”的谚语。我也相信小到一个家庭,大到一个国家都是”富无经业,货无常主,能者辐射,不肖者完结”,有些事情前车之鉴尤未远,却没有看到成为后事之师,也许中国还是跳不出那个循环吧。
不好,不能愤青!

Patterns of Enterprise Application Architecture Chapter 1&2

After reading several design pattern books including “Head first design pattern” and “Java and Pattern” I turned my focus to one new book named Patterns of Enterprise Application Architecture. From the comments of amazon it seems that it’s one pretty good book. Considering the limited memory now, writing down some key ideas from the book should be able to keep the reading more interesting.
The preface section defines the scope of this book which is architecture for enterprise application. The common patterns of enterprise applications include data persistence, concurrent access, huge data process, complex UI, and integration to other enterprise application.  Here the UI involves Web and traditional rich client application. Also the authors gives some points on the measurement for performance. Finally the form of pattern is given which contains name, intention, summary,  how it works, when to use it and further reading, also some examples maybe also presented for better understanding.
The first chapter talks about layering. This topic starts from the evolution from the Client/Server model to three principal layers. One problem of the traditional C/S model is that the domain logic is hard to organized. It’s a bad idea to mix the logic in client UI directly which may easily causes duplicated code and maintain issues. Alternative way is putting them to the server side which usually presented as database store procedure. Here the store procedure is limited and may causes difficulty to switch to different database.
These short comes naturally involves idea to separate the domain logic in the object oriented world. This results in the new three principle layers including Presentation, Domain and Data source. one interesting point raised by author to think about the Presentation and Data source layer is that “Presentation is an external interface for a service your system offers to someone else, whether it be a complex human or a simple remote program. Data source is the interface to things that are providing a service to you”. Also one principle here is “The domain and data source should never be dependent on the presentation” which means we should be able to easily change our presentation layer without requiring changes in domain logic layer.
The benefits of layering contains: Easy to understand separated layer, minimize dependencies between different layers, substitute layers with alternative implementations of the same basic services. One obvious drawback of layering is that performance as we need to pass data to different layers. But compare to the benefits usually the cost is worthwhile.
The chapter 2 discusses about the way to organize domain logic.  Transaction Scripts, Domain Model, and Table Module. They all have pros and cons. The recommended way is Domain Model which is good at complexity when the problems scope increase.

以卜筮者尚其占

最近在读《后汉书》比较靠后面的一些文章,是一些综合性的介绍某一方面人物的,比如循吏,酷吏,儒林,文苑,独行,方术等等。其中最没有意思的文章当属儒林和文苑了,不得不说读书人的事情实在是没有意思,无聊的很,全是诗词歌赋,可惜我要读的是历史。读方术列传的时候,突然有种感觉,似乎自己在读的不是历史,而是神话小说,但至少还算有趣。
题目卜筮者以尚其占是这一篇文章引用易经的一段话,“易有圣人之道四焉:以言者尚其辞,以动者尚其变,以制器者尚其象,以卜筮者尚其占”,就是圣人会用卜筮来预测未来,查了下,这个卜筮是不过三次,就是第一次如果不吉,可以第二次,再不吉可以第三次,但是不可超过三次,就是所谓“筮不过三”,后来的“事不过三”据说就是从这个来的。
文章介绍了不少善于预测事情的人物,估计也的确有一些是真实的事情吧,当然必定也有一些以讹传讹的故事,只是占卜似乎也的确是很有技术含量的一件事情,不知道如果自己花费些时间读易经,能否也能学个几招,然后去摆个地摊算命,哈哈。

疑留不断,至于殄败

题目是后汉书宦官列传里面提到窦武和何进时候的感慨,倒也非常贴切。
窦武的长女被立为皇后,作为外戚而被封侯,为人“清身疾恶,礼赂不通,妻子衣食裁充足而已”。首先是上书救了党锢之祸的士族李膺,杜密,后面参与立灵帝,他的长女也就成为了太后。因为看不惯宦官弄权,于是借太后诏除掉了宦官管霸,苏康,但是要杀另一个曹节的时候,太后不忍,于是“事久不发”。后面计划泄露,于是宦官曹节,王甫劫持灵帝,窦武发兵但最终兵败被枭首示众,诛九族。这里面还提到了一个传说,窦武在出生的时候他的母亲同时产一蛇,蛇被送到森林里面去了。后来他母亲过世的时候,这个蛇在墓前“若哀戚之容”。这个说明史书有时候也会八卦。
何进,就比较有名了,还是因为三国演义的缘故。他的同父异母的妹妹被立为皇后,因为剿灭黄巾起义被封侯。这个何皇后生的是刘辩,但是灵帝觉得他轻佻没有威仪,倾向于刘协,就是后来的汉献帝。但是皇后有宠,何进又有重权,所以一直到死都没有立太子,其实这个汉献帝也够惨的,小时候他的生母就被何皇后给杀了,他实际上和董太后抚养的,这也是后来董卓立他的原因之一。灵帝死的时候把刘协托付给了宦官蹇硕,蹇硕准备杀了何进立刘协,但是何进知道了计划,不去皇宫,所以还是刘辩即位,蹇硕被别的宦官出卖被杀。后来何进准备杀其他宦官但是何太后不同意,最终也是拖了很久没有决断,最终宦官决定先下手为强,何进又没有听进别人的劝告又去了皇宫劝说何太后,结果被杀。这也引发了何进手下领兵进宫屠杀宦官,最终董卓之乱起。
历史有时候或许真的是必然和偶然的结合体。就那个时代而言,汉朝灭亡是必然的,但是窦武,何进的死却是其自身的一念之间的失误,所谓当断不断反受其乱,然也。

新和谐关键词: "诺*贝*尔*和*平*奖”

今天看到诺*贝*尔$和*平*奖公布了,得主是刘*晓*波,心里觉得不妙,估计有新的关键词要出来了。果然很快各大网站就撤下了诺贝尔奖的专题,用Google搜诺*贝*尔$和*平*奖立即被盾,用wikipedia搜刘*晓*波也一样的结局。水木上有人开玩笑说估计诺贝尔瓷砖也快要完蛋了,呵呵。
第一次关注这个人是因为*零*八*宪*章的事情,在一个神奇星球的神奇国度里面,很多宪法中的东西能写,但是你不能宣传,不然就是煽动颠覆国家政权罪,似乎还记得当年的不锈钢老鼠上街宣传马克思主义的事情,而如今类似的事情便不断上演。想起网络上一个经典帖子的回复:“不顶不是中国人”,下面有人回“Re, 不顶下辈子还是中国人!”,接着有人回“顶!不顶下辈子中朝轮换!”。
也许历史总是这么的相似吧,道路以目,焚书坑儒,党锢之祸,文字狱,所谓“防民之口甚于防川”总会被人们忘记。不禁想起前几天YD在接受CNN采访时还指出言论自由在任何国家不可或缺的,他和中国人民都相信,中国将继续进步,人民对民主及自由的渴求和需要是不可抗拒的,可惜当我用“温家宝 民主 自由 不可抗拒”搜索Google,结果又被盾了!