﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-面对现实，超越自己-随笔分类-脚本</title><link>http://cppblog.com/wanghaiguang/category/20411.html</link><description>逆水行舟，不进则退</description><language>zh-cn</language><lastBuildDate>Fri, 19 Aug 2016 07:01:22 GMT</lastBuildDate><pubDate>Fri, 19 Aug 2016 07:01:22 GMT</pubDate><ttl>60</ttl><item><title>SWIG实现python对c++封装</title><link>http://www.cppblog.com/wanghaiguang/archive/2016/08/18/214201.html</link><dc:creator>王海光</dc:creator><author>王海光</author><pubDate>Thu, 18 Aug 2016 03:20:00 GMT</pubDate><guid>http://www.cppblog.com/wanghaiguang/archive/2016/08/18/214201.html</guid><wfw:comment>http://www.cppblog.com/wanghaiguang/comments/214201.html</wfw:comment><comments>http://www.cppblog.com/wanghaiguang/archive/2016/08/18/214201.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wanghaiguang/comments/commentRss/214201.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wanghaiguang/services/trackbacks/214201.html</trackback:ping><description><![CDATA[<span style="font-family: Verdana;">一、SWIG环境搭建</span><br /><div>&nbsp; <br /><span style="font-family: Verdana;">&nbsp; &nbsp;1、 下载Swig for Windows：http://www.swig.org/download.html</span></div><div><span style="font-family: Verdana;">&nbsp;&nbsp;&nbsp;2、 解压 .zip 文件到目录，比如：D:\backupsoftware</span></div><div><span style="font-family: Verdana;">&nbsp;&nbsp;&nbsp;3、 添加环境变量到path， 比如： D:\backupsoftware\swigwin-3.0.10</span></div><div><span style="font-family: Verdana;">&nbsp;&nbsp;&nbsp;4、 简单测试安装是否成功：</span></div><div><span style="font-family: Verdana;">&nbsp; &nbsp;打开Dos，在命令行执行： swig --help, 显示 Target Language Options即表明安装成功。</span><br /><br /><span style="font-family: Verdana;">二、以c++为例</span><br /><br /><span style="font-family: Verdana;">1、编写c++源文件</span><br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008000; font-family: Verdana;">//</span><span style="color: #008000; font-family: Verdana;">example.h</span><span style="color: #008000; "><br /></span><span style="font-family: Verdana;">#include&nbsp;&lt;iostream&gt;</span><br /><span style="color: #0000ff; font-family: Verdana;">using</span>&nbsp;<span style="color: #0000ff; font-family: Verdana;">namespace</span><span style="font-family: Verdana;">&nbsp;std;</span><br /><span style="color: #0000ff; font-family: Verdana;">class</span><span style="font-family: Verdana;">&nbsp;Example{</span><br /><span style="color: #0000ff; font-family: Verdana;">public</span><span style="font-family: Verdana;">:</span><br /><span style="color: #0000ff; font-family: Verdana;">void</span><span style="font-family: Verdana;">&nbsp;say_hello();</span><br /><span style="font-family: Verdana;">};</span></div><br /><div style="font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all; background-color: #eeeeee;"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008000; font-family: Verdana;">//</span><span style="color: #008000; font-family: Verdana;">example.cpp</span><span style="color: #008000; "><br /></span><br /><span style="font-family: Verdana;">#include&nbsp;"example.h"</span><br /><br /><span style="color: #0000ff; font-family: Verdana;">void</span><span style="font-family: Verdana;">&nbsp;Example::say_hello()</span><br /><span style="font-family: Verdana;">{</span><br /><span style="font-family: Verdana;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("hello");</span><br /><span style="font-family: Verdana;">}</span></div><br /><span style="color: #333333; font-family: Verdana; line-height: 26px; background-color: #ffffff;">2、再写一个swig模块定义文件如下<br /></span><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="font-family: Verdana;">%module&nbsp;example</span><br /><span style="font-family: Verdana;">%{</span><br /><span style="font-family: Verdana;">#include&nbsp;"example.h"</span><br /><span style="font-family: Verdana;">%}</span><br /><span style="font-family: Verdana;">%include&nbsp;"example.h"</span></div><span style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><br /></span><span style="color: #333333; font-family: Verdana; line-height: 26px; background-color: #ffffff;">3、通过命令行运行：$ swig -python -c++ example.i</span><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="font-family: Verdana;">&nbsp; &nbsp; 如果是使用C源码，则选项：$ swig -</span><a href="http://lib.csdn.net/base/11" class="replace_word" title="undefined" target="_blank" style="color: #df3434; text-decoration: none; font-weight: bold;"><span style="font-family: Verdana;">Python</span></a><span style="font-family: Verdana;">&nbsp;example.i</span></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="font-family: Verdana;">&nbsp; &nbsp; 这样会创建两个不同的文件：example_wrap.cxx（如果用c源码是example_wrap.c），和python文件example.py。</span></p><span style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><br /></span><span style="color: #333333; font-family: Verdana; line-height: 26px; background-color: #ffffff;">4、使用python.distutils生成模块动态库</span><br /><span style="color: #333333; font-family: Verdana; line-height: 25.2px; background-color: #ffffff;">python自带一个distutils工具，可以用它来创建python的扩展模块。使用它也很简单，只需要先定义一个配置文件，通常是命名为setup.py</span><span style="color: #333333; font-family: Verdana; line-height: 26px; background-color: #ffffff;">，如下：</span><br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008000; font-family: Verdana;">#</span><span style="color: #008000; font-family: Verdana;">!/usr/bin/env&nbsp;python</span><span style="color: #008000; "><br /></span><br /><span style="color: #800000; font-family: Verdana;">"""</span><span style="color: #800000; "><br /></span><span style="color: #800000; font-family: Verdana;">setup.py&nbsp;file&nbsp;for&nbsp;SWIG&nbsp;C\+\+/Python&nbsp;example<br /></span><span style="color: #800000; font-family: Verdana;">"""</span><br /><span style="color: #0000ff; font-family: Verdana;">from</span><span style="font-family: Verdana;">&nbsp;distutils.core&nbsp;</span><span style="color: #0000ff; font-family: Verdana;">import</span><span style="font-family: Verdana;">&nbsp;setup,&nbsp;Extension</span><br /><span style="font-family: Verdana;">example_module&nbsp;=&nbsp;Extension(</span><span style="color: #800000; font-family: Verdana;">'</span><span style="color: #800000; font-family: Verdana;">_example</span><span style="color: #800000; font-family: Verdana;">'</span><span style="font-family: Verdana;">,</span><br /><span style="font-family: Verdana;">sources=[</span><span style="color: #800000; font-family: Verdana;">'</span><span style="color: #800000; font-family: Verdana;">example.cpp</span><span style="color: #800000; font-family: Verdana;">'</span><span style="font-family: Verdana;">,&nbsp;</span><span style="color: #800000; font-family: Verdana;">'</span><span style="color: #800000; font-family: Verdana;">example_wrap.cxx</span><span style="color: #800000; font-family: Verdana;">'</span><span style="font-family: Verdana;">,],</span><br /><span style="font-family: Verdana;">)</span><br /><span style="font-family: Verdana;">setup&nbsp;(name&nbsp;=&nbsp;</span><span style="color: #800000; font-family: Verdana;">'</span><span style="color: #800000; font-family: Verdana;">example</span><span style="color: #800000; font-family: Verdana;">'</span><span style="font-family: Verdana;">,</span><br /><span style="font-family: Verdana;">version&nbsp;=&nbsp;</span><span style="color: #800000; font-family: Verdana;">'</span><span style="color: #800000; font-family: Verdana;">0.1</span><span style="color: #800000; font-family: Verdana;">'</span><span style="font-family: Verdana;">,</span><br /><span style="font-family: Verdana;">author&nbsp;=&nbsp;</span><span style="color: #800000; font-family: Verdana;">"</span><span style="color: #800000; font-family: Verdana;">www</span><span style="color: #800000; font-family: Verdana;">"</span><span style="font-family: Verdana;">,</span><br /><span style="font-family: Verdana;">description&nbsp;=&nbsp;</span><span style="color: #800000; font-family: Verdana;">"""</span><span style="color: #800000; font-family: Verdana;">Simple&nbsp;swig&nbsp;C\+\+/Python&nbsp;example</span><span style="color: #800000; font-family: Verdana;">"""</span><span style="font-family: Verdana;">,</span><br /><span style="font-family: Verdana;">ext_modules&nbsp;=&nbsp;[example_module],</span><br /><span style="font-family: Verdana;">py_modules&nbsp;=&nbsp;[</span><span style="color: #800000; font-family: Verdana;">"</span><span style="color: #800000; font-family: Verdana;">example</span><span style="color: #800000; font-family: Verdana;">"</span><span style="font-family: Verdana;">],</span><br /><span style="font-family: Verdana;">)</span></div><br /><span style="color: #ff0000; font-family: Verdana; line-height: 26px; background-color: #ffffff;">注：</span><span style="color: #333333; font-family: Verdana; line-height: 26px; background-color: #ffffff;">swig生成的扩展模块对象名必须使用python模块名并在前面加上下划线_，刚才我们通过swig生成的python文件是example.py，所以这里的模块对象名必须是'_example',否则无法顺利编译。</span><br /><br /><span style="margin: 0px; padding: 0px; color: #333333; font-family: Verdana; line-height: 25.2px; background-color: #ffffff;">5、编译<br /></span><span style="font-family: Verdana; line-height: 26px;">命令行中将当前工作目录切换到文件example.cpp,</span><span style="color: #333333; font-family: Verdana; line-height: 26px; background-color: #ffffff;">example_wrap.cxx</span><span style="font-family: Verdana; line-height: 26px;">,example.py,setup.py所在的目录,然后输入以下命令:</span><br /><span style="color: #333333; font-family: Verdana; line-height: 26px; background-color: #ffffff;">python setup.py build_ext --inplace</span><br /><br /><span style="color: #333333; font-family: Verdana; line-height: 25.2px; background-color: #ffffff;">会在本目录下生成_example.pyd模块。<br /><br /></span><span style="font-family: Verdana;">6、测试</span><br /><span style="font-family: Verdana;">import examlpe</span><br /><div><span style="font-family: Verdana;">example.Example().say_hello()</span><br /><br /><span style="color: red; font-family: Verdana;">注</span><span style="font-family: Verdana;">：如果导入模块失败，需要将模块所在路径添加到sys.path中，在次导入就会成功</span><br /><img src="http://www.cppblog.com/images/cppblog_com/wanghaiguang/swig.jpg" width="648" height="223" alt="" /><br /><br /><br /></div></div><img src ="http://www.cppblog.com/wanghaiguang/aggbug/214201.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wanghaiguang/" target="_blank">王海光</a> 2016-08-18 11:20 <a href="http://www.cppblog.com/wanghaiguang/archive/2016/08/18/214201.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Shell自动生成并安装服务脚本（转载）</title><link>http://www.cppblog.com/wanghaiguang/archive/2014/04/23/206687.html</link><dc:creator>王海光</dc:creator><author>王海光</author><pubDate>Wed, 23 Apr 2014 09:06:00 GMT</pubDate><guid>http://www.cppblog.com/wanghaiguang/archive/2014/04/23/206687.html</guid><wfw:comment>http://www.cppblog.com/wanghaiguang/comments/206687.html</wfw:comment><comments>http://www.cppblog.com/wanghaiguang/archive/2014/04/23/206687.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wanghaiguang/comments/commentRss/206687.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wanghaiguang/services/trackbacks/206687.html</trackback:ping><description><![CDATA[<span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; line-height: 20px; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;一般地，当在目标机器编译安装某个服务程序后，为了使服务能开机自启动和关机自停止，则需要将其添加为系统服务。但不同的Linux系统管理服务的方法不同，如Ubuntu使用update-rc.d命令，而RedHat则使用 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;chkconfig命令。因此为了能自动识别系统的类型，减少人工控制，编写了一个简单的autosrv脚本，要求至少1个最多2个参数，特点如下：</span><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; line-height: 20px;" /><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; line-height: 20px; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;&#9679; 第1个参数只能为install或uninstall，表示安装或卸载服务。</span><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; line-height: 20px;" /><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; line-height: 20px; background-color: #ffffff;">&nbsp; &nbsp; &nbsp;&#9679; 第2参数是可选的，表示系统名称，如果没有指定，那么会自动识别，若出现提示错误，则表示应该要显式指定系统名称了。&nbsp;</span><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; line-height: 20px;">&nbsp;<div align="center"></div></span><div align="center" style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; line-height: 20px;"></div><div align="center" style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; line-height: 20px;"></div><div align="center" style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; line-height: 20px;"></div><div align="center" style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; line-height: 20px;"><div style="border: 1px solid #cccccc; padding: 4px 5px 4px 4px; background-color: #eeeeee; width: 1233.697998046875px; font-size: 13px; word-break: break-all;"><div align="left"><span style="color: #008080;">&nbsp;&nbsp;1</span><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /><span style="color: #000000;">#!&nbsp;/bin/bash<br /></span><span style="color: #008080;">&nbsp;&nbsp;2</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />#&nbsp;autosrv<br /></span><span style="color: #008080;">&nbsp;&nbsp;3</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /><br /></span><span style="color: #008080;">&nbsp;&nbsp;4</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />if&nbsp;[&nbsp;$#&nbsp;-lt&nbsp;1&nbsp;];&nbsp;then<br /></span><span style="color: #008080;">&nbsp;&nbsp;5</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;"Usage:&nbsp;$(basename&nbsp;"$0")&nbsp;install&nbsp;|&nbsp;uninstall&nbsp;[sysname]"<br /></span><span style="color: #008080;">&nbsp;&nbsp;6</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;exit<br /></span><span style="color: #008080;">&nbsp;&nbsp;7</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />elif&nbsp;[&nbsp;"$1"&nbsp;!=&nbsp;"install"&nbsp;-a&nbsp;"$1"&nbsp;!=&nbsp;"uninstall"&nbsp;];&nbsp;then<br /></span><span style="color: #008080;">&nbsp;&nbsp;8</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;"The&nbsp;first&nbsp;parameter&nbsp;must&nbsp;be&nbsp;install&nbsp;or&nbsp;uninstall"&nbsp;<br /></span><span style="color: #008080;">&nbsp;&nbsp;9</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;exit<br /></span><span style="color: #008080;">&nbsp;10</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />fi<br /></span><span style="color: #008080;">&nbsp;11</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /><br /></span><span style="color: #008080;">&nbsp;12</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />action=$1<br /></span><span style="color: #008080;">&nbsp;13</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />sysname=$2<br /></span><span style="color: #008080;">&nbsp;14</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />srv_path=/etc/init.d/srv_name<br /></span><span style="color: #008080;">&nbsp;15</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /><br /></span><span style="color: #008080;">&nbsp;16</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />if&nbsp;[&nbsp;-z&nbsp;"$sysname"&nbsp;];&nbsp;then<br /></span><span style="color: #008080;">&nbsp;17</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;sysname=`lsb_release&nbsp;-a&nbsp;|&nbsp;sed&nbsp;-n&nbsp;'2p'&nbsp;|&nbsp;awk&nbsp;'{if($0~/[Uu][Bb][Uu][Nn][Tt][Uu]/)&nbsp;print&nbsp;"ubuntu";&nbsp;else&nbsp;if($0~/[Dd][Ee][Bb][Ii][Aa][Nn]/)&nbsp;print&nbsp;"debian";&nbsp;else&nbsp;if($0~/[Rr][Ee][Dd][Hh][Aa][Tt]/)&nbsp;print&nbsp;"redhat";&nbsp;else&nbsp;if($0~/[Cc][Ee][Nn][Tt][Oo][Ss]/)&nbsp;print&nbsp;"centos";&nbsp;else&nbsp;print&nbsp;""}'`<br /></span><span style="color: #008080;">&nbsp;18</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;[&nbsp;-z&nbsp;"$sysname"&nbsp;];&nbsp;then<br /></span><span style="color: #008080;">&nbsp;19</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;"Unknown&nbsp;system,&nbsp;please&nbsp;manual&nbsp;special&nbsp;it&nbsp;with&nbsp;the&nbsp;second&nbsp;parameter"<br /></span><span style="color: #008080;">&nbsp;20</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit<br /></span><span style="color: #008080;">&nbsp;21</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;fi<br /></span><span style="color: #008080;">&nbsp;22</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;"Current&nbsp;system&nbsp;is&nbsp;$sysname"<br /></span><span style="color: #008080;">&nbsp;23</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />fi<br /></span><span style="color: #008080;">&nbsp;24</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /><br /></span><span style="color: #008080;">&nbsp;25</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />create_file_ubu</span><span style="color: #000000;">ntu_debia</span><span style="color: #000000;">n()<br /></span><span style="color: #008080;">&nbsp;26</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />{<br /></span><span style="color: #008080;">&nbsp;27</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />cat&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">&lt;&nbsp;END&nbsp;</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">&nbsp;$srv_path<br /></span><span style="color: #008080;">&nbsp;28</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />#!&nbsp;/bin/bash<br /></span><span style="color: #008080;">&nbsp;29</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px; color: #ff0000;" /></span><span style="color: #ff0000;">.&nbsp;/lib/lsb/init-functions</span><span style="color: #000000;"><br /></span><span style="color: #008080;">&nbsp;30</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /><br /></span><span style="color: #008080;">&nbsp;31</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />END<br /></span><span style="color: #008080;">&nbsp;32</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />cat&nbsp;srv_name.body&nbsp;&gt;&gt;&nbsp;$srv_path<br /></span><span style="color: #008080;">&nbsp;33</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />}<br /></span><span style="color: #008080;">&nbsp;34</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /><br /></span><span style="color: #008080;">&nbsp;35</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />create_file_redhat_centos()<br /></span><span style="color: #008080;">&nbsp;36</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />{<br /></span><span style="color: #008080;">&nbsp;37</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />cat&nbsp;</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">&lt;&nbsp;END&nbsp;</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">&nbsp;$srv_path<br /></span><span style="color: #008080;">&nbsp;38</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />#!&nbsp;/bin/bash<br /></span><span style="color: #008080;">&nbsp;39</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /></span><span style="color: #ff0000;">#chkconfig:2345&nbsp;90&nbsp;10</span><span style="color: #000000;"><br /></span><span style="color: #008080;">&nbsp;40</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /></span><span style="color: #ff0000;">#description: srv name</span><span style="color: #000000;"><br /></span><span style="color: #008080;">&nbsp;41</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /><br /></span><span style="color: #008080;">&nbsp;42</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /></span><span style="color: #ff0000;">.&nbsp;/etc/rc.d/init.d/functions</span><span style="color: #000000;"><br /></span><span style="color: #008080;">&nbsp;43</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /><br /></span><span style="color: #008080;">&nbsp;44</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />END<br /></span><span style="color: #008080;">&nbsp;45</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />cat&nbsp;srv_name.body&nbsp;&gt;&gt;&nbsp;$srv_path<br /></span><span style="color: #008080;">&nbsp;46</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />}<br /></span><span style="color: #008080;">&nbsp;47</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /><br /></span><span style="color: #008080;">&nbsp;48</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />chmod_file()<br /></span><span style="color: #008080;">&nbsp;49</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />{<br /></span><span style="color: #008080;">&nbsp;50</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;chmod&nbsp;u+x&nbsp;$srv_path<br /></span><span style="color: #008080;">&nbsp;51</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />}<br /></span><span style="color: #008080;">&nbsp;52</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /><br /></span><span style="color: #008080;">&nbsp;53</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />remove_file()<br /></span><span style="color: #008080;">&nbsp;54</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />{<br /></span><span style="color: #008080;">&nbsp;55</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;rm&nbsp;-f&nbsp;$srv_path<br /></span><span style="color: #008080;">&nbsp;56</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />}<br /></span><span style="color: #008080;">&nbsp;57</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /><br /></span><span style="color: #008080;">&nbsp;58</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />install_ubuntu_debian()<br /></span><span style="color: #008080;">&nbsp;59</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />{<br /></span><span style="color: #008080;">&nbsp;60</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;create_file_ubuntu_debian<br /></span><span style="color: #008080;">&nbsp;61</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;chmod_file<br /></span><span style="color: #008080;">&nbsp;62</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #ff0000;">update-rc.d</span><span style="color: #000000;">&nbsp;srv_name&nbsp;</span><span style="color: #ff0000;">defaults&nbsp;90&nbsp;10</span><span style="color: #000000;"><br /></span><span style="color: #008080;">&nbsp;63</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />}<br /></span><span style="color: #008080;">&nbsp;64</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /><br /></span><span style="color: #008080;">&nbsp;65</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />uninstall_ubuntu_debian()<br /></span><span style="color: #008080;">&nbsp;66</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />{<br /></span><span style="color: #008080;">&nbsp;67</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #ff0000;">update-rc.d&nbsp;-f</span><span style="color: #000000;">&nbsp;srv_name&nbsp;</span><span style="color: #ff0000;">remove</span><span style="color: #000000;"><br /></span><span style="color: #008080;">&nbsp;68</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;remove_file<br /></span><span style="color: #008080;">&nbsp;69</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />}<br /></span><span style="color: #008080;">&nbsp;70</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /><br /></span><span style="color: #008080;">&nbsp;71</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />install_redhat_centos()<br /></span><span style="color: #008080;">&nbsp;72</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />{<br /></span><span style="color: #008080;">&nbsp;73</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;create_file_redhat_centos<br /></span><span style="color: #008080;">&nbsp;74</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;chmod_file<br /></span><span style="color: #008080;">&nbsp;75</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #ff0000;">chkconfig&nbsp;</span><span style="color: #ff0000;">--add</span><span style="color: #000000;">&nbsp;srv_name<br /></span><span style="color: #008080;">&nbsp;76</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />}<br /></span><span style="color: #008080;">&nbsp;77</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /><br /></span><span style="color: #008080;">&nbsp;78</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />uninstall_redhat_centos()<br /></span><span style="color: #008080;">&nbsp;79</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />{<br /></span><span style="color: #008080;">&nbsp;80</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #ff0000;">chkconfig&nbsp;</span><span style="color: #ff0000;">--</span><span style="color: #ff0000;">del&nbsp;</span><span style="color: #000000;">srv_name<br /></span><span style="color: #008080;">&nbsp;81</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;remove_file<br /></span><span style="color: #008080;">&nbsp;82</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />}<br /></span><span style="color: #008080;">&nbsp;83</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /><br /></span><span style="color: #008080;">&nbsp;84</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />case&nbsp;"$sysname"&nbsp;in<br /></span><span style="color: #008080;">&nbsp;85</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;ubuntu|debian)<br /></span><span style="color: #008080;">&nbsp;86</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;[&nbsp;"$action"&nbsp;=&nbsp;"install"&nbsp;];&nbsp;then<br /></span><span style="color: #008080;">&nbsp;87</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;install_ubuntu_debian<br /></span><span style="color: #008080;">&nbsp;88</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;else<br /></span><span style="color: #008080;">&nbsp;89</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;uninstall_ubuntu_debian<br /></span><span style="color: #008080;">&nbsp;90</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;fi<br /></span><span style="color: #008080;">&nbsp;91</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;;;<br /></span><span style="color: #008080;">&nbsp;92</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /><br /></span><span style="color: #008080;">&nbsp;93</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;redhat|centos)<br /></span><span style="color: #008080;">&nbsp;94</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;[&nbsp;"$action"&nbsp;=&nbsp;"install"&nbsp;];&nbsp;then<br /></span><span style="color: #008080;">&nbsp;95</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;install_redhat_centos<br /></span><span style="color: #008080;">&nbsp;96</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;else<br /></span><span style="color: #008080;">&nbsp;97</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;uninstall_redhat_centos<br /></span><span style="color: #008080;">&nbsp;98</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;fi<br /></span><span style="color: #008080;">&nbsp;99</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;;;<br /></span><span style="color: #008080;">100</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" /><br /></span><span style="color: #008080;">101</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;*)<br /></span><span style="color: #008080;">102</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;"Currently&nbsp;only&nbsp;support&nbsp;ubuntu,&nbsp;debian,&nbsp;redhat&nbsp;and&nbsp;centos&nbsp;system"<br /></span><span style="color: #008080;">103</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;exit<br /></span><span style="color: #008080;">104</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />&nbsp;&nbsp;&nbsp;&nbsp;;;<br /></span><span style="color: #008080;">105</span><span style="color: #000000;"><img align="top" src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" alt="" style="border: 0px;" />esac</span></div></div></div><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; line-height: 20px; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; 从上可知，自动识别的方法是获取</span><span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; line-height: 20px; color: #ff0000;">lsb_release -a</span><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; line-height: 20px; background-color: #ffffff;">返回的文本再使用awk来匹配</span><span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; line-height: 20px; color: #ff0000;">ubuntu</span><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; line-height: 20px; background-color: #ffffff;">,</span><span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; line-height: 20px; color: #ff0000;">redhat</span><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; line-height: 20px; background-color: #ffffff;">,</span><span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; line-height: 20px; color: #ff0000;">debian</span><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; line-height: 20px; background-color: #ffffff;">,</span><span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; line-height: 20px; color: #ff0000;">centos</span><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; line-height: 20px; background-color: #ffffff;">这几个子串(忽略大小写)。要注意的是，返回的文本可能有所不同，当系统安装了LSB模块时，返回结果如下</span><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; line-height: 20px;" /><div align="center" style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; line-height: 20px;"><img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/qinqing1984/redhat-lsb-release.jpg" width="1028" height="111" style="border: 0px;" /></div><span style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; line-height: 20px; background-color: #ffffff;">&nbsp; &nbsp; &nbsp; 没有安装时，返回结果如下</span><br style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; line-height: 20px;" /><div align="center" style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; line-height: 20px;"></div><div align="left" style="color: #4b4b4b; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13.333333969116211px; line-height: 20px;"><div align="center"></div><div align="center"></div><div align="center"><img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/qinqing1984/ubuntu-lsb-release-2.jpg" width="1028" height="92" style="border: 0px;" /></div>&nbsp; &nbsp; &nbsp; 无论哪种情况，要提取分析的都是第2行文本，因此使用了<span style="color: #ff0000;">sed -n '2p'</span>。srv_name.body是不同系统相同的用于生成最终服务脚本的部分代码文件，通常包含了start,stop,status,restart几个函数，只是没有包含前面的一部分，而这部分则由autosrv脚本来根据不同的系统生成不同的代码。<br /><br />本文转自：<a href="http://www.cppblog.com/qinqing1984/archive/2014/01/03/205140.html" style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 21.111112594604492px;">http://www.cppblog.com/qinqing1984/archive/2014/01/03/205140.html</a></div><img src ="http://www.cppblog.com/wanghaiguang/aggbug/206687.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wanghaiguang/" target="_blank">王海光</a> 2014-04-23 17:06 <a href="http://www.cppblog.com/wanghaiguang/archive/2014/04/23/206687.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用vbs或者bat脚本修改IE浏览器安全级别和选项</title><link>http://www.cppblog.com/wanghaiguang/archive/2013/09/06/203051.html</link><dc:creator>王海光</dc:creator><author>王海光</author><pubDate>Fri, 06 Sep 2013 08:09:00 GMT</pubDate><guid>http://www.cppblog.com/wanghaiguang/archive/2013/09/06/203051.html</guid><wfw:comment>http://www.cppblog.com/wanghaiguang/comments/203051.html</wfw:comment><comments>http://www.cppblog.com/wanghaiguang/archive/2013/09/06/203051.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wanghaiguang/comments/commentRss/203051.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wanghaiguang/services/trackbacks/203051.html</trackback:ping><description><![CDATA[<p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="font-size: 16px;">1. 首先介绍计算机定义的每个安全区域的项：<span style="font-size: 14px;">Zones 。</span></span>默认情况下，定义以下&nbsp;&nbsp; 5&nbsp;&nbsp; 个区域（编号从&nbsp;&nbsp; 0&nbsp;&nbsp; 到&nbsp;&nbsp; 4）：</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="white-space: pre;">0&nbsp;&nbsp; 我的电脑&nbsp;<br /> 1&nbsp;&nbsp;&nbsp;本地&nbsp;&nbsp; Intranet&nbsp;&nbsp; 区域&nbsp;<br /> 2&nbsp;&nbsp; 受信任的站点区域&nbsp;<br /> 3&nbsp;&nbsp; Internet&nbsp;&nbsp; 区域&nbsp;<br /> 4&nbsp;&nbsp;&nbsp;受限制的站点区域</span></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="white-space: pre;"><span style="color: #cc0000;">注意：默认情况下，&#8220;我的电脑&#8221;不会出现在&#8220;安全&#8221;选项卡的&#8220;区域&#8221;框中。</span><br /> </span></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="white-space: pre;"><span style="color: #cc0000;"><span style="color: #333333;">其中的每项都包含以下&nbsp;&nbsp;  DWORD&nbsp;&nbsp; 值，用于表示自定义&#8220;安全&#8221;选项卡上的相应设置。</span><br /> </span></span></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="white-space: pre;"><span style="color: #ff0000;">注意：除非另外声明，否则每个&nbsp;&nbsp;  DWORD&nbsp;&nbsp; 值等于&nbsp;&nbsp; 0、1&nbsp;&nbsp; 或&nbsp;&nbsp; 3。通常，设置为&nbsp;&nbsp; 0&nbsp;&nbsp; 则将具体操作设置为允许；设置为&nbsp;&nbsp; 1&nbsp;&nbsp; 则导致出现提示；设置为&nbsp;&nbsp; 3&nbsp;&nbsp; 则禁止执行具体操作。</span><br /> </span></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">-----------------------------------------------------------------------&nbsp;<br /><br />1001&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 下载已签名的&nbsp;&nbsp; ActiveX&nbsp;&nbsp; 控件&nbsp;<br />1004&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 下载未签名的&nbsp;&nbsp; ActiveX&nbsp;&nbsp; 控件&nbsp;<br />1200&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 运行&nbsp;&nbsp; ActiveX&nbsp;&nbsp; 控件和插件&nbsp;<br />1201&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 对没有标记为安全的&nbsp;&nbsp; ActiveX&nbsp;&nbsp; 控件进行初始化和脚本运行&nbsp;<br />1206&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 允许&nbsp;&nbsp; Internet&nbsp;&nbsp; Explorer&nbsp;&nbsp; Webbrowser&nbsp;&nbsp; 控件的脚本&nbsp;<br />1400&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 活动脚本&nbsp;<br />1402&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Java&nbsp;&nbsp; 小程序脚本&nbsp;<br />1405&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 对标记为可安全执行脚本的&nbsp;&nbsp; ActiveX&nbsp;&nbsp; 控件执行脚本&nbsp;<br />1406&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 通过域访问数据资源&nbsp;<br />1407&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 允许通过脚本进行粘贴操作&nbsp;<br />1601&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 提交非加密表单数据&nbsp;<br />1604&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 字体下载&nbsp;<br />1605&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 运行&nbsp;&nbsp; Java&nbsp;<br />1606&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 持续使用用户数据&nbsp;<br />1607&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 跨域浏览子框架&nbsp;<br />1608&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 允许&nbsp;&nbsp; META&nbsp;&nbsp; REFRESH&nbsp;&nbsp; *&nbsp;<br />1609&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 显示混合内容&nbsp;&nbsp; *&nbsp;<br />1800&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 桌面项目的安装&nbsp;<br />1802&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 拖放或复制和粘贴文件&nbsp;<br />1803&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 文件下载&nbsp;<br />1804&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在&nbsp;&nbsp; IFRAME&nbsp;&nbsp; 中加载程序和文件&nbsp;<br />1805&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在&nbsp;&nbsp; Web&nbsp;&nbsp; 视图中加载程序和文件&nbsp;<br />1806&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 加载应用程序和不安全文件&nbsp;<br />1807&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 保留&nbsp;&nbsp; **&nbsp;<br />1808&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 保留&nbsp;&nbsp; **&nbsp;<br />1809&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 使用弹出窗口阻止程序&nbsp;&nbsp; **&nbsp;<br />1A00&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 登录&nbsp;<br />1A02&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 允许持续使用存储在计算机上的&nbsp;&nbsp; Cookie&nbsp;<br />1A03&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 允许使用每个会话的&nbsp;&nbsp; Cookie（未存储）&nbsp;<br />1A04&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 没有证书或只有一个证书时不提示选择客户证书&nbsp;&nbsp; *&nbsp;<br />1A05&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 允许持续使用第三方&nbsp;&nbsp; Cookie&nbsp;&nbsp; *&nbsp;<br />1A06&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 允许使用第三方会话&nbsp;&nbsp; Cookie&nbsp;&nbsp; *&nbsp;<br />1A10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 隐私设置&nbsp;&nbsp; *&nbsp;<br />1C00&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Java&nbsp;&nbsp; 权限&nbsp;<br />1E05&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 软件频道权限</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">1F00&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 保留&nbsp;&nbsp; **</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">2000&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 二进制和脚本行为&nbsp;<br />2001&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 运行已用&nbsp;&nbsp; Authenticode&nbsp;&nbsp; 签名的&nbsp;&nbsp; .NET&nbsp;&nbsp; 组件&nbsp;<br />2004&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 运行未用&nbsp;&nbsp; Authenticode&nbsp;&nbsp; 签名的&nbsp;&nbsp; .NET&nbsp;&nbsp; 组件&nbsp;<br />2100&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 基于内容打开文件，而不是基于文件扩展名&nbsp;&nbsp; **&nbsp;<br />2101&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 在低特权&nbsp;&nbsp; Web&nbsp;&nbsp; 内容区域中的网站可以导航到此区域&nbsp;&nbsp; **&nbsp;<br />2102&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 允许由脚本初始化的窗口，没有大小和位置限制&nbsp;&nbsp; **&nbsp;<br />2200&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 文件下载自动提示&nbsp;&nbsp; **&nbsp;<br />2201&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ActiveX&nbsp;&nbsp; 控件自动提示&nbsp;&nbsp; **&nbsp;<br />2300&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 允许网页为活动内容使用受限制的协议&nbsp;&nbsp; **&nbsp;</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"><span style="white-space: pre;">-----------------------------------------------------------------------&nbsp;</span><br /></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">以上介绍完了IE安全选项的基本概念，接下说明如何利用脚本修改。</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">假设我们要修改浏览器的<span style="white-space: pre;">跨域浏览子框架(代号1607)为启用，它默认为禁用状态。</span></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;"></p><div style="background-color: #ffffff; margin: 0px; color: #2c2c2c; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px;"><span style="color: #8a2be2; padding: 0px; margin: 0px; background-color: #fffafa;"><span style="padding: 0px; margin: 0px;">1、VBS篇</span></span></div><div style="background-color: #ffffff; margin: 0px; color: #2c2c2c; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px;"><span style="color: #8a2be2; padding: 0px; margin: 0px; background-color: #fffafa;"><span style="padding: 0px; margin: 0px;">Const HKEY_CURRENT_USER = &amp;H80000001</span></span></div><div style="background-color: #ffffff; margin: 0px; color: #2c2c2c; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px;"><span style="color: #8a2be2; padding: 0px; margin: 0px; background-color: #fffafa;"></span></div><div style="background-color: #ffffff; margin: 0px; color: #2c2c2c; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px;"><span style="color: #8a2be2; padding: 0px; margin: 0px; background-color: #fffafa;"><span style="padding: 0px; margin: 0px;">strComputer = "."</span></span></div><div style="background-color: #ffffff; margin: 0px; color: #2c2c2c; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px;"><span style="color: #8a2be2; padding: 0px; margin: 0px; background-color: #fffafa;"></span></div><div style="background-color: #ffffff; margin: 0px; color: #2c2c2c; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px;"><span style="color: #8a2be2; padding: 0px; margin: 0px; background-color: #fffafa;"><span style="padding: 0px; margin: 0px;">Set objReg = GetObject("winmgmts:" &amp;"{impersonationLevel=impersonate}\\"&amp;strComputer _&amp;</span></span><span style="color: #8a2be2; padding: 0px; margin: 0px; background-color: #fffafa;"><span style="padding: 0px; margin: 0px;">"\root\default:StdRegProv")</span></span></div><div style="background-color: #ffffff; margin: 0px; color: #2c2c2c; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px;"><span style="color: #8a2be2; padding: 0px; margin: 0px; background-color: #fffafa;"></span></div><div style="background-color: #ffffff; margin: 0px; color: #2c2c2c; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px;"><span style="background-color: #fffafa; color: #8a2be2;">strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\" &amp; "Zones\3"&nbsp;</span></div><div style="background-color: #ffffff; margin: 0px; color: #2c2c2c; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px;"><span style="color: #8a2be2; padding: 0px; margin: 0px; background-color: #fffafa;"><span style="padding: 0px; margin: 0px;">strEntryName = "1607"&nbsp;<br style="padding: 0px; margin: 0px;" />dwvalue = 0&nbsp;<br style="padding: 0px; margin: 0px;" />objReg.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strEntryName,dwValue</span></span></div><div style="color: #333333; background-color: #ffffff; margin: 0px; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px;"><span style="color: #2c2c2c;">其中</span><span style="color: #8a2be2; white-space: pre; background-color: #fffafa;">HKEY_CURRENT_USER</span><span style="white-space: pre; background-color: #fffafa;">指的是当前登录用户，此设置不会影响到其它登录的账号。<span style="color: #8a2be2;">strKeyPath</span>为关键字的路径，根据之前关于Zones选项的解释，此路径不难看懂。<span style="color: #8a2be2;">strEntryName</span>为需要设置的选项代号。<span style="color: #8a2be2;">dwvalue</span>为需要设置的安全级别，此处0则代表允许。</span></div><div style="color: #333333; background-color: #ffffff; margin: 0px; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px;"><span style="white-space: pre; background-color: #fffafa;"><br /> </span></div><div style="color: #333333; background-color: #ffffff; margin: 0px; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px;"><div style="margin: 0px; color: #2c2c2c;"><span style="color: #8a2be2; padding: 0px; margin: 0px; background-color: #fffafa;"><span style="padding: 0px; margin: 0px;">2、BAT篇</span></span></div><div style="margin: 0px; color: #2c2c2c;"><span style="color: #8a2be2; padding: 0px; margin: 0px; background-color: #fffafa;"><span style="padding: 0px; margin: 0px;">REG add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3" /v "1607" /t reg_dword /d 0x00000003 /f</span></span></div><div style="margin: 0px;">通过VBS的讲解，此处就不在赘述，不过主要的是以上两种方法的保存格式分别是以vbs和bat类型。例如bat方法，则可以在记事本中考本上一行代码存为IE_modify.bat。<br /><br />本文转自：<a href="http://blog.csdn.net/yingminxing/article/details/7250585">http://blog.csdn.net/yingminxing/article/details/7250585</a></div></div><img src ="http://www.cppblog.com/wanghaiguang/aggbug/203051.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wanghaiguang/" target="_blank">王海光</a> 2013-09-06 16:09 <a href="http://www.cppblog.com/wanghaiguang/archive/2013/09/06/203051.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>bat批处理静默自动安装证书</title><link>http://www.cppblog.com/wanghaiguang/archive/2013/09/06/203050.html</link><dc:creator>王海光</dc:creator><author>王海光</author><pubDate>Fri, 06 Sep 2013 07:56:00 GMT</pubDate><guid>http://www.cppblog.com/wanghaiguang/archive/2013/09/06/203050.html</guid><wfw:comment>http://www.cppblog.com/wanghaiguang/comments/203050.html</wfw:comment><comments>http://www.cppblog.com/wanghaiguang/archive/2013/09/06/203050.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/wanghaiguang/comments/commentRss/203050.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wanghaiguang/services/trackbacks/203050.html</trackback:ping><description><![CDATA[<p align="left" style="background-color: white; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: 12.0pt;font-family:宋体;Trebuchet MS&quot;;Trebuchet MS&quot;;">针对该问题，微软有一个名为</span><span style="font-size:12.0pt;font-family:&quot;Trebuchet MS&quot;,&quot;sans-serif&quot;;">Certmgr.exe</span><span style="font-size:12.0pt;font-family:宋体;Trebuchet MS&quot;;Trebuchet MS&quot;;">的证书管理器工具可以实现此目标，该工具主要用于管理证书、证书信任列表</span><span style="font-size:12.0pt;font-family:&quot;Trebuchet MS&quot;,&quot;sans-serif&quot;;"> (CTL) </span><span style="font-size:12.0pt;font-family:宋体;Trebuchet MS&quot;;Trebuchet MS&quot;;">和证书吊销列表</span><span style="font-size:12.0pt;font-family:&quot;Trebuchet MS&quot;,&quot;sans-serif&quot;;"> (CRL)</span><span style="font-size:12.0pt;font-family:宋体;Trebuchet MS&quot;;Trebuchet MS&quot;;">，</span></p>  <p align="left" style="background-color: white; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: 12pt; font-family: 宋体;">具体参数的示例请参考：</span><em><span style="font-size:9.0pt; font-family:&quot;Trebuchet MS&quot;,&quot;sans-serif&quot;;"><br /> </span></em><span style="font-size: 12pt; font-family: 'Trebuchet MS', sans-serif;"><a href="http://msdn.microsoft.com/zh-cn/library/e78byta0(VS.80).aspx"><span style="color: windowtext;">http://msdn.microsoft.com/zh-cn/library/e78byta0(VS.80).aspx</span></a></span><span style="font-size: 12pt; font-family: 宋体;">。</span><em></em></p>  <p align="left" style="background-color: white; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: 12.0pt;font-family:宋体;Trebuchet MS&quot;;Trebuchet MS&quot;;">该工具是</span><span style="font-size:12.0pt;font-family:&quot;Trebuchet MS&quot;,&quot;sans-serif&quot;;">SDK Tool</span><span style="font-size:12.0pt;font-family:宋体;Trebuchet MS&quot;;Trebuchet MS&quot;;">的一部分，您可以下载最新的</span><span style="font-size: 12.0pt;font-family:&quot;Trebuchet MS&quot;,&quot;sans-serif&quot;;">Windows SDK</span><span style="font-size:12.0pt;font-family:宋体;Trebuchet MS&quot;;Trebuchet MS&quot;;">发行版获得此工具；若您安装了</span><span style="font-size:12.0pt;font-family: &quot;Trebuchet MS&quot;,&quot;sans-serif&quot;;">visual studio</span><span style="font-size:12.0pt; font-family:宋体;Trebuchet MS&quot;;Trebuchet MS&quot;;">，该工具也包含在安装目录中。</span></p>  <p align="left" style="background-color: white; background-position: initial initial; background-repeat: initial initial;"><span style="font-size: 12.0pt;font-family:宋体;Trebuchet MS&quot;;Trebuchet MS&quot;;">为了更好的帮助您解决这一问题，我们可以通过下列步骤实现在客户端简易安装信任证书。<br /></span><span style="font-size: 12pt; font-family: 宋体;">首先，您可以将根证书</span><span style="font-size: 12pt; font-family: 宋体;">导出，并把这个证书保存到一个</span><span style="font-size: 12pt; font-family: 'Trebuchet MS', sans-serif;">share folder</span><span style="font-size: 12pt; font-family: 宋体;">里。<br /></span><span style="font-size: 12pt; font-family: 'Trebuchet MS', sans-serif;">Export </span><span style="font-size: 12pt; font-family: 宋体;">成功之后，在客户端跑下面</span><span style="font-size: 12pt; font-family: 'Trebuchet MS', sans-serif;">2</span><span style="font-size: 12pt; font-family: 宋体;">个命令就可以把这个证书</span><span style="font-size: 12pt; font-family: 'Trebuchet MS', sans-serif;">test.cer</span><span style="font-size: 12pt; font-family: 宋体;">加到</span><span style="font-size: 12pt; font-family: 'Trebuchet MS', sans-serif;">&#8221;trusted publishers&#8221;</span><span style="font-size: 12pt; font-family: 宋体;">和</span><span style="font-size: 12pt; font-family: 'Trebuchet MS', sans-serif;">&#8221;trusted root certification authorities&#8221;</span><span style="font-size: 12pt; font-family: 宋体;">里了。<br /></span><span style="font-size: 12pt; font-family: 宋体;">如果您的</span><span style="font-size: 12pt; font-family: 'Trebuchet MS', sans-serif;">client</span><span style="font-size: 12pt; font-family: 宋体;">端没有</span><span style="font-size: 12pt; font-family: 'Trebuchet MS', sans-serif;">certmgr.exe</span><span style="font-size: 12pt; font-family: 宋体;">，您可以把</span><span style="font-size: 12pt; font-family: 'Trebuchet MS', sans-serif;">certmgr.exe</span><span style="font-size: 12pt; font-family: 宋体;">放到一个</span><span style="font-size: 12pt; font-family: 'Trebuchet MS', sans-serif;">sharefolder</span><span style="font-size: 12pt; font-family: 宋体;">里，比如这里我把它放到</span><span style="font-size: 12pt;"><font face="Trebuchet MS, sans-serif">当前</font></span><span style="font-size: 12pt; font-family: 宋体;">目录下</span></p><p align="left" style="background-color: white;"></p><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; font-size: 12pt;">1</span>&nbsp;<span style="font-size: 12pt;">&nbsp;&#8220;</span><span style="font-size: 12pt;">.\</span><span style="font-size: 12pt;">certmgr</span><span style="font-size: 12pt;">.</span><span style="font-size: 12pt;">exe&#8221;&nbsp;</span><span style="font-size: 12pt;">-</span><span style="font-size: 12pt;">add&nbsp;&#8220;</span><span style="font-size: 12pt;">.\</span><span style="font-size: 12pt;">test</span><span style="font-size: 12pt;">.</span><span style="font-size: 12pt;">cer&#8221;&nbsp;</span><span style="font-size: 12pt;">-</span><span style="font-size: 12pt;">s&nbsp;</span><span style="font-size: 12pt;">-</span><span style="font-size: 12pt;">r&nbsp;localMachine&nbsp;trustedpublisher</span><br /><span style="color: #008080; font-size: 12pt;">2</span>&nbsp;<span style="font-size: 12pt;">&nbsp;&#8220;</span><span style="font-size: 12pt;">.\</span><span style="font-size: 12pt;">certmgr</span><span style="font-size: 12pt;">.</span><span style="font-size: 12pt;">exe&#8221;&nbsp;</span><span style="font-size: 12pt;">-</span><span style="font-size: 12pt;">add&nbsp;&#8220;</span><span style="font-size: 12pt;">.\</span><span style="font-size: 12pt;">test</span><span style="font-size: 12pt;">.</span><span style="font-size: 12pt;">cer&#8221;&nbsp;</span><span style="font-size: 12pt;">-</span><span style="font-size: 12pt;">s&nbsp;</span><span style="font-size: 12pt;">-</span><span style="font-size: 12pt;">r&nbsp;localMachine&nbsp;AuthRoot</span></div><span style="font-size: 12.0pt;font-family:宋体;Trebuchet MS&quot;;Trebuchet MS&quot;;">您可以把上面两行代码拷贝到一个</span><span style="font-size:12.0pt;font-family:&quot;Trebuchet MS&quot;,&quot;sans-serif&quot;;">bat</span><span style="font-size:12.0pt;font-family:宋体;Trebuchet MS&quot;;Trebuchet MS&quot;;">文件中，客户只要双击这个</span><span style="font-size:12.0pt;font-family: &quot;Trebuchet MS&quot;,&quot;sans-serif&quot;;">bat</span><span style="font-size:12.0pt;font-family: 宋体;Trebuchet MS&quot;;Trebuchet MS&quot;;">文件即可完成安装证书，或者通过组策略来强制在域内的指定机器上运行这个</span><span style="font-size:12.0pt;font-family:&quot;Trebuchet MS&quot;,&quot;sans-serif&quot;;">bat </span><span style="font-size:12.0pt;font-family:宋体;Trebuchet MS&quot;;Trebuchet MS&quot;;">文件。<br /><br />静默安装<br />利用vbs文件实现静默安装，脚本示例如下：<br /></span><div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all;"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080; font-size: 12pt;">1</span>&nbsp;<span style="font-size: 12pt;">set&nbsp;ws</span><span style="font-size: 12pt;">=</span><span style="font-size: 12pt;">wscript</span><span style="font-size: 12pt;">.</span><span style="font-size: 12pt;">createobject(</span><span style="font-weight: bold; font-size: 12pt;">"</span><span style="font-weight: bold; font-size: 12pt;">wscript.shell</span><span style="font-weight: bold; font-size: 12pt;">"</span><span style="font-size: 12pt;">)</span><br /><span style="color: #008080; font-size: 12pt;">2</span>&nbsp;<span style="font-size: 12pt;">ws</span><span style="font-size: 12pt;">.</span><span style="font-size: 12pt;">run&nbsp;</span><span style="font-weight: bold; font-size: 12pt;">"</span><span style="font-weight: bold; font-size: 12pt;">installcert.bat&nbsp;/start</span><span style="font-weight: bold; font-size: 12pt;">"</span><span style="font-size: 12pt;">,</span><span style="color: #800000; font-size: 12pt;">0</span></div><p>&nbsp;</p><img src ="http://www.cppblog.com/wanghaiguang/aggbug/203050.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wanghaiguang/" target="_blank">王海光</a> 2013-09-06 15:56 <a href="http://www.cppblog.com/wanghaiguang/archive/2013/09/06/203050.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>xml编码问题</title><link>http://www.cppblog.com/wanghaiguang/archive/2013/05/22/200529.html</link><dc:creator>王海光</dc:creator><author>王海光</author><pubDate>Wed, 22 May 2013 07:24:00 GMT</pubDate><guid>http://www.cppblog.com/wanghaiguang/archive/2013/05/22/200529.html</guid><wfw:comment>http://www.cppblog.com/wanghaiguang/comments/200529.html</wfw:comment><comments>http://www.cppblog.com/wanghaiguang/archive/2013/05/22/200529.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wanghaiguang/comments/commentRss/200529.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wanghaiguang/services/trackbacks/200529.html</trackback:ping><description><![CDATA[<span style="font-family: Verdana; line-height: 26px; font-size: 12pt;">默认情况下，Windows的Notepad把文件保存为ANSI格式,在这种情况，设定不同encoding有不同的结果：</span><br style="font-family: 宋体, Arial; line-height: 26px;" /><span style="font-family: Verdana; line-height: 26px; font-size: 12pt;">&nbsp;&nbsp; encoding="GB2312" ，正常显示；</span><br style="font-family: 宋体, Arial; line-height: 26px;" /><span style="font-family: Verdana; line-height: 26px; font-size: 12pt;">&nbsp;&nbsp; encoding="UTF-8" &nbsp; ，出错，提示文本内容中发现无效字符 ;</span><br style="font-family: 宋体, Arial; line-height: 26px;" /><br style="font-family: 宋体, Arial; line-height: 26px;" /><span style="font-family: Verdana; line-height: 26px; font-size: 12pt;">把xml文件在notepad另包存为UTF-8格式，</span><br style="font-family: 宋体, Arial; line-height: 26px;" /><span style="font-family: Verdana; line-height: 26px; font-size: 12pt;">&nbsp;&nbsp; encoding="GB2312" ，出错，提示不支持从当前编码到指定编码的切换;</span><br style="font-family: 宋体, Arial; line-height: 26px;" /><span style="font-family: Verdana; line-height: 26px; font-size: 12pt;">&nbsp;&nbsp; encoding="UTF-8" &nbsp; ，正常；</span><br style="font-family: 宋体, Arial; line-height: 26px;" /><span style="font-family: Verdana; line-height: 26px; font-size: 12pt;">例外：不设置encoding的值，默认就是UTF-8,所以把这种情况归入UTF-8的情况.</span><img src ="http://www.cppblog.com/wanghaiguang/aggbug/200529.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wanghaiguang/" target="_blank">王海光</a> 2013-05-22 15:24 <a href="http://www.cppblog.com/wanghaiguang/archive/2013/05/22/200529.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux Shell脚本攻略笔记</title><link>http://www.cppblog.com/wanghaiguang/archive/2013/04/03/199075.html</link><dc:creator>王海光</dc:creator><author>王海光</author><pubDate>Wed, 03 Apr 2013 08:58:00 GMT</pubDate><guid>http://www.cppblog.com/wanghaiguang/archive/2013/04/03/199075.html</guid><wfw:comment>http://www.cppblog.com/wanghaiguang/comments/199075.html</wfw:comment><comments>http://www.cppblog.com/wanghaiguang/archive/2013/04/03/199075.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wanghaiguang/comments/commentRss/199075.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wanghaiguang/services/trackbacks/199075.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 1、$表示普通用户，#表示超级用户（root user）。超级用户是Linux系统中权限最高的用户。  2、shell通常以#!起始，例如：#!/bin/bash  3、运行脚本的两种方式：1、将脚本作为sh的命令行参数。2、将脚本作为具有执行权限的可执行文件。  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;例如：$ sh scri...&nbsp;&nbsp;<a href='http://www.cppblog.com/wanghaiguang/archive/2013/04/03/199075.html'>阅读全文</a><img src ="http://www.cppblog.com/wanghaiguang/aggbug/199075.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wanghaiguang/" target="_blank">王海光</a> 2013-04-03 16:58 <a href="http://www.cppblog.com/wanghaiguang/archive/2013/04/03/199075.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>msi程序安装和卸载</title><link>http://www.cppblog.com/wanghaiguang/archive/2012/11/15/195224.html</link><dc:creator>王海光</dc:creator><author>王海光</author><pubDate>Thu, 15 Nov 2012 03:21:00 GMT</pubDate><guid>http://www.cppblog.com/wanghaiguang/archive/2012/11/15/195224.html</guid><wfw:comment>http://www.cppblog.com/wanghaiguang/comments/195224.html</wfw:comment><comments>http://www.cppblog.com/wanghaiguang/archive/2012/11/15/195224.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wanghaiguang/comments/commentRss/195224.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wanghaiguang/services/trackbacks/195224.html</trackback:ping><description><![CDATA[<div><pre id="best-answer-content"  mb10"="" data-accusearea="aContent" style="margin-top: 0px; margin-bottom: 10px; padding: 0px; font-family: Arial; white-space: pre-wrap; word-wrap: break-word; zoom: 1; line-height: 22px; background-color: #fffcf6; ">微软在XP下提供了一个软件程序，SYSTEM32\msiexec.exe<br />在命令行下输入：msiexec /? 显示帮助信息，如下：</pre><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->Windows&nbsp;(R)&nbsp;Installer.&nbsp;V&nbsp;5.0.7600.16385<br /><br />msiexec&nbsp;/Option&nbsp;&lt;Required&nbsp;Parameter&gt;&nbsp;[Optional&nbsp;Parameter]<br /><br />安装选项<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;/package&nbsp;|&nbsp;/i&gt;&nbsp;&lt;Product.msi&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;安装或配置产品<br />&nbsp;&nbsp;&nbsp;&nbsp;/a&nbsp;&lt;Product.msi&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;管理安装&nbsp;-&nbsp;在网络上安装产品<br />&nbsp;&nbsp;&nbsp;&nbsp;/j&lt;u|m&gt;&nbsp;&lt;Product.msi&gt;&nbsp;[/t&nbsp;&lt;Transform&nbsp;List&gt;]&nbsp;[/g&nbsp;&lt;Language&nbsp;ID&gt;]<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;公布产品&nbsp;-&nbsp;m&nbsp;公布到所有用户，u&nbsp;公布到当前用户<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;/uninstall&nbsp;|&nbsp;/x&gt;&nbsp;&lt;Product.msi&nbsp;|&nbsp;ProductCode&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;卸载产品<br />显示选项<br />&nbsp;&nbsp;&nbsp;&nbsp;/quiet<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;安静模式，无用户交互<br />&nbsp;&nbsp;&nbsp;&nbsp;/passive<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;无人参与模式&nbsp;-&nbsp;只显示进度栏<br />&nbsp;&nbsp;&nbsp;&nbsp;/q[n|b|r|f]<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;设置用户界面级别<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;n&nbsp;-&nbsp;无用户界面<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;b&nbsp;-&nbsp;基本界面<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r&nbsp;-&nbsp;精简界面<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f&nbsp;-&nbsp;完整界面(默认值)<br />&nbsp;&nbsp;&nbsp;&nbsp;/help<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;帮助信息<br />重新启动选项<br />&nbsp;&nbsp;&nbsp;&nbsp;/norestart<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;安装完成后不重新启动<br />&nbsp;&nbsp;&nbsp;&nbsp;/promptrestart<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;必要时提示用户重新启动<br />&nbsp;&nbsp;&nbsp;&nbsp;/forcerestart<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;安装后始终重新启动计算机<br />日志选项<br />&nbsp;&nbsp;&nbsp;&nbsp;/l[i|w|e|a|r|u|c|m|o|p|v|x|+|!|*]&nbsp;&lt;LogFile&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i&nbsp;-&nbsp;状态消息<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;w&nbsp;-&nbsp;非致命警告<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e&nbsp;-&nbsp;所有错误消息<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;-&nbsp;操作的启动<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r&nbsp;-&nbsp;操作特定记录<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;u&nbsp;-&nbsp;用户请求<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c&nbsp;-&nbsp;初始用户界面参数<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m&nbsp;-&nbsp;内存不足或致命退出信息<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;o&nbsp;-&nbsp;磁盘空间不足消息<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p&nbsp;-&nbsp;终端属性<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;v&nbsp;-&nbsp;详细输出<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x&nbsp;-&nbsp;额外调试信息<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+&nbsp;-&nbsp;扩展到现有日志文件<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;!&nbsp;-&nbsp;每一行刷新到日志<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;-&nbsp;记录所有信息，除了&nbsp;v&nbsp;和&nbsp;x&nbsp;选项<br />&nbsp;&nbsp;&nbsp;&nbsp;/log&nbsp;&lt;LogFile&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;与&nbsp;/l*&nbsp;&lt;LogFile&gt;&nbsp;相同<br />更新选项<br />&nbsp;&nbsp;&nbsp;&nbsp;/update&nbsp;&lt;Update1.msp&gt;[;Update2.msp]<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;应用更新<br />&nbsp;&nbsp;&nbsp;&nbsp;/uninstall&nbsp;&lt;PatchCodeGuid&gt;[;Update2.msp]&nbsp;/package&nbsp;&lt;Product.msi&nbsp;|&nbsp;ProductCode&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;删除产品的更新<br />修复选项<br />&nbsp;&nbsp;&nbsp;&nbsp;/f[p|e|c|m|s|o|d|a|u|v]&nbsp;&lt;Product.msi&nbsp;|&nbsp;ProductCode&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;修复产品<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p&nbsp;-&nbsp;仅当文件丢失时<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;o&nbsp;-&nbsp;如果文件丢失或安装了更旧的版本(默认值)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e&nbsp;-&nbsp;如果文件丢失或安装了相同或更旧的版本<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;d&nbsp;-&nbsp;如果文件丢失或安装了不同版本<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;c&nbsp;-&nbsp;如果文件丢失或较验和与计算的值不匹配<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;-&nbsp;强制重新安装所有文件<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;u&nbsp;-&nbsp;所有必要的用户特定注册表项(默认值)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m&nbsp;-&nbsp;所有必要的计算机特定注册表项(默认值)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s&nbsp;-&nbsp;所有现有的快捷键方式(默认值)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;v&nbsp;-&nbsp;从源运行并重新缓存本地安装包<br />设置公共属性<br />&nbsp;&nbsp;&nbsp;&nbsp;[PROPERTY=PropertyValue]<br /><br />请查阅&nbsp;Windows&nbsp;(R)&nbsp;Installer&nbsp;SDK&nbsp;获得有关命令行语法的其他文档。<br /><br />版权所有&nbsp;(C)&nbsp;Microsoft&nbsp;Corporation.&nbsp;保留所有权利。<br />此软件的部分内容系基于&nbsp;Independent&nbsp;JPEG&nbsp;Group&nbsp;的工作。</div><br /><span style="background-color: #fffcf6; font-family: Arial; line-height: 22px; white-space: pre-wrap; ">运行CMD后，输入</span>msiexec /i&nbsp;Product.msi&nbsp;/q 即可安装msi程序。&nbsp;<br /><br /><div><span style="background-color: #fffcf6; font-family: Arial; line-height: 22px; white-space: pre-wrap; ">运行CMD后，输入</span>msiexec /x&nbsp;<span style="background-color: #fffcf6; font-family: Arial; line-height: 22px; white-space: pre-wrap; ">ProductCode</span>&nbsp;/q 即可卸载msi安装过的程序。<br /><br /><pre id="best-answer-content"  mb10"="" data-accusearea="aContent" style="margin-top: 0px; margin-bottom: 10px; padding: 0px; font-family: Arial; white-space: pre-wrap; word-wrap: break-word; zoom: 1; line-height: 22px; background-color: #fffcf6; ">ProductCode的值可在注册表中查找，注册表位置：HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall  根据DisplayName键值来确定安装的msi程序，UninstallString的值中包含ProductCode 如：{BC12972C-BF15-4607-A745-948DA0DE63FF}<br /><br />卸载命令可以写成如下所示：msiexec /x "{BC12972C-BF15-4607-A745-948DA0DE63FF}" /q</pre></div></div><img src ="http://www.cppblog.com/wanghaiguang/aggbug/195224.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wanghaiguang/" target="_blank">王海光</a> 2012-11-15 11:21 <a href="http://www.cppblog.com/wanghaiguang/archive/2012/11/15/195224.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>BAT命令</title><link>http://www.cppblog.com/wanghaiguang/archive/2012/06/21/179595.html</link><dc:creator>王海光</dc:creator><author>王海光</author><pubDate>Thu, 21 Jun 2012 04:30:00 GMT</pubDate><guid>http://www.cppblog.com/wanghaiguang/archive/2012/06/21/179595.html</guid><wfw:comment>http://www.cppblog.com/wanghaiguang/comments/179595.html</wfw:comment><comments>http://www.cppblog.com/wanghaiguang/archive/2012/06/21/179595.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wanghaiguang/comments/commentRss/179595.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wanghaiguang/services/trackbacks/179595.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要:  1.批处理文件是一个“.bat”结尾的文本文件，这个文件的每一行都是一条DOS命令。可以使用任何文本文件编辑工具创建和修改。    2.批处理是一种简单的程序，可以用 if 和 goto 来控制流程，也可以使用 for 循环。    3.批处理的编程能力远不如C语言等编程语言，也十分不规范。    4.每个编写好的批处理文件都相当于一个DOS的外部命令，把它所在的目录放到DOS搜索路径(path)中，即可在任意位置运行。    5.C:\AUTOEXEC.BAT 是每次系统启动时都会自动运行的，可以将每次启动时都要运行的命令放入该文件中。    6.大小写不敏感(命令符忽略大小写)    7.批处理的文件扩展名为 .bat 或 .cmd。&nbsp;&nbsp;<a href='http://www.cppblog.com/wanghaiguang/archive/2012/06/21/179595.html'>阅读全文</a><img src ="http://www.cppblog.com/wanghaiguang/aggbug/179595.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wanghaiguang/" target="_blank">王海光</a> 2012-06-21 12:30 <a href="http://www.cppblog.com/wanghaiguang/archive/2012/06/21/179595.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VBS启动应用程序</title><link>http://www.cppblog.com/wanghaiguang/archive/2012/04/16/171607.html</link><dc:creator>王海光</dc:creator><author>王海光</author><pubDate>Mon, 16 Apr 2012 04:41:00 GMT</pubDate><guid>http://www.cppblog.com/wanghaiguang/archive/2012/04/16/171607.html</guid><wfw:comment>http://www.cppblog.com/wanghaiguang/comments/171607.html</wfw:comment><comments>http://www.cppblog.com/wanghaiguang/archive/2012/04/16/171607.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wanghaiguang/comments/commentRss/171607.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wanghaiguang/services/trackbacks/171607.html</trackback:ping><description><![CDATA[<div><span style="font-size: 14pt">VBS中启动exe程序： </span>
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">1</span>&nbsp;<span style="color: #0000ff">set</span><span style="color: #000000">&nbsp;ws</span><span style="color: #000000">=</span><span style="color: #000000">WScript.CreateObject(</span><span style="color: #000000">"</span><span style="color: #000000">WScript.Shell</span><span style="color: #000000">"</span><span style="color: #000000">)&nbsp;<br /></span><span style="color: #008080">2</span>&nbsp;<span style="color: #000000">ws.Run&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">AutoUpdateEx.exe</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">true</span><span style="color: #000000"><br /></span><span style="color: #008080">3</span>&nbsp;<span style="color: #000000">ws.Run&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">打印配置工具.exe</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">true</span><span style="color: #000000"><br /></span><span style="color: #008080">4</span>&nbsp;<span style="color: #000000">ws.Run&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">DOMASClientMonitor.exe</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">true</span><span style="color: #000000"><br /></span><span style="color: #008080">5</span>&nbsp;<span style="color: #000000">ws.Run&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">PrinterMonitorEx.exe</span><span style="color: #000000">"</span><span style="color: #000000">,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">false</span></div><br /><span style="font-size: 14pt">VBS中启动exe程序绝对路径：</span> 
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">1</span>&nbsp;<span style="color: #0000ff">set</span><span style="color: #000000">&nbsp;ws</span><span style="color: #000000">=</span><span style="color: #000000">WScript.CreateObject(</span><span style="color: #000000">"</span><span style="color: #000000">WScript.Shell</span><span style="color: #000000">"</span><span style="color: #000000">)&nbsp;<br /></span><span style="color: #008080">2</span>&nbsp;<span style="color: #000000">ws.Run&nbsp;</span><span style="color: #000000">"""</span><span style="color: #000000">C:\Program&nbsp;Files\Test\AutoUpdateEx.exe</span><span style="color: #000000">"""</span><span style="color: #000000">,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">true</span><span style="color: #000000"><br /></span><span style="color: #008080">3</span>&nbsp;<span style="color: #000000">ws.Run&nbsp;</span><span style="color: #000000">"""</span><span style="color: #000000">C:\Program&nbsp;Files\Test\DOMASClientMonitor.exe</span><span style="color: #000000">"""</span><span style="color: #000000">,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">false</span><span style="color: #000000"><br /></span><span style="color: #008080">4</span>&nbsp;<span style="color: #000000">ws.Run&nbsp;</span><span style="color: #000000">"""</span><span style="color: #000000">C:\Program&nbsp;Files\Test\PrinterMonitorEx.exe</span><span style="color: #000000">"""</span><span style="color: #000000">,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">false</span><span style="color: #000000"><br /></span><span style="color: #008080">5</span>&nbsp;<span style="color: #000000">ws.Run&nbsp;</span><span style="color: #000000">"""</span><span style="color: #000000">C:\Program&nbsp;Files\Test\打印配置工具.exe</span><span style="color: #000000">"""</span><span style="color: #000000">,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #0000ff">false</span></div></div><br />
<p style="text-indent: 21pt; margin: 0cm 0cm 0pt" class="MsoNormal"><span style="font-family: Times New Roman; font-size: 12pt">ws.Run</span><span style="font-size: 12pt">实际参数是"</span><span style="font-family: Times New Roman; font-size: 12pt">C:\Program Files\Test\AutoUpdateEx.exe"</span><span style="font-size: 12pt">，因为带空格，先将它括起来作为一个整体，而两侧的"按要求应该用转义""表示，故成为""</span><span style="font-family: Times New Roman"><span style="font-family: Times New Roman; font-size: 12pt">C:\Program Files\Test\AutoUpdateEx.exe""</span></span><span style="font-size: 12pt">，而</span><span style="font-family: Times New Roman; font-size: 12pt">Run</span><span style="font-size: 12pt">本身调用参数就得在外部加一对引号，故共有三对引号。用</span><span style="font-family: Times New Roman; font-size: 12pt">msgbox"""</span><span style="font-family: Times New Roman"><span style="font-family: Times New Roman; font-size: 12pt">C:\Program Files\Test\AutoUpdateEx.exe"""</span></span><span style="font-size: 12pt">可验证结果为"</span><span style="font-family: Times New Roman"><span style="font-family: Times New Roman; font-size: 12pt">C:\Program Files\Test\AutoUpdateEx.exe"</span></span><span style="font-size: 12pt">。对于</span><span style="font-family: Times New Roman"><span style="font-family: Times New Roman; font-size: 12pt">Run</span></span><span style="font-size: 12pt">方法，可以统一都用三个引号，</span><span style="font-family: Times New Roman"><span style="font-family: Times New Roman; font-size: 12pt">ws.Run"""</span></span><span style="font-size: 14pt"><span style="font-family: Times New Roman"><span style="font-family: Times New Roman; font-size: 12pt">C</span></span></span><span style="font-family: Times New Roman; font-size: 12pt">:\"""</span><span style="font-size: 12pt">同样可以解析；本例也可用</span><span style="font-family: Times New Roman"><span style="font-family: Times New Roman; font-size: 12pt">ws.Run"</span></span><span style="font-family: Times New Roman; font-size: 14pt"><span style="font-family: Times New Roman; font-size: 12pt">C</span></span><span style="font-family: Times New Roman; font-size: 12pt">:\progra~1\Test\AutoUpdateEx.exe"</span><span style="font-size: 12pt">来实现。</span></p><img src ="http://www.cppblog.com/wanghaiguang/aggbug/171607.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wanghaiguang/" target="_blank">王海光</a> 2012-04-16 12:41 <a href="http://www.cppblog.com/wanghaiguang/archive/2012/04/16/171607.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>