2014年8月27日 星期三

C++簡介


歷史
Bjarne Stroustrup在攻取Ph.D 時就有一個構想,如何研究出一套方便又好用的程式語言。1979他參考了Simula的功能後,開始修改c語言,而在AT&T Bell Labs製作出Simula-like 的加強版C語言,稱做"C with Classes"的程式語言,這就是C++的前身,他將以下的功能(features)加入C語言的編譯器:class、derived class、strong typing、inlining和default argument
在1983才將其命名為 C++ (++ 是C語言的increment operator),新增的features 包含virtual functions、function name 和operator overloading、references、constants、ype-safe free-store memory allocation (new/delete)、improved type checking和BCPL style single-line comments with two forward slashes (//),以及C++的 compiler for C++(Cfront)。
在1985,第一個C++ Programming Language 版本被發行被released,而第一版商業化的C++在同年10月被released。
C++ 2.0在1991發行,新的features包含multiple inheritance、abstract classes、static member functions、const member functions和protected members. 在1990,C++ 的參考手冊被發行。後續更陸續新增了一些feature,包含 templates、exceptions、namespaces、new casts和 boolean type。
在2011,C++11 被發行,而且新增了更多的 features和standard library。


2014年7月16日 星期三

Powershell與WMI Provider的簡介和使用(新增和設定rigistry key)

目的:了解如何使用Powershell使用WMI Provider
目標:1、經由Powershell Console呼叫WMI Provider來修改rigistry key和設定其default value。
      2、經由Powershell Script呼叫WMI Provider來修改rigistry key和設定其default value。

WMI Provider簡介

WMI是Windows system的資訊database,經由 WMI Service連結到database來query database的資訊。
經由以下的步驟可以經由開啟WMI Control Properties來看到 WMI的詳細資訊(Name space)
1、經由Administrative Tools打開 "Computer Management"
2、展開 "Services and Applications."
3、Right-click "WMI Control" 和選擇Properties.



WMI Namespace 底下包含許多classes, class則由properties和methods所組成。我們可以經由PowerShell 來使用WMI 的class做一些系統環境的設定。
以下顯示如何使用Get-WmiObject cmdlet來list出 Namespace的classes

2014年7月13日 星期日

PowerShell Provider的簡介和使用(新增和設定rigistry key)

PowerShell Providers 是 .NET programs允許mount "data stores"成 drives來工作,簡單的存取PowerShell environment的外部資料,如如同file system 般的存取registry。這意味著能如同使用存取files和 folders的cmdlets,可以參考以下的 table 。

簡短的敘述
Windows PowerShell providers提供簡單的command line來存取data和components不須另外的command,data類似一個file system drive般的呈現。

完整描述
Windows PowerShell providers 是NET programs ,使Windows PowerShell 可以簡單的view和manage在特殊data store的data。
Provider將data呈現在drive,如同一個hard drive,可以使用provider支援的built-in cmdlets來管理資料,另外也可特別針對一些data來製作custom cmdlets。
Providers 也可以搭配 "dynamic parameters"來使用 built-in cmdlets,當cmdlet被使用來存取provider data。
Provider 也被稱為 "snap-in" ,如同PowerShell 的dynamic link library (.dll), library當執行command時,指示PowerShell來做action的code。也就是說如果使用VBScript 來讀取registry,不需要再寫code。 可以寫新的和 Custom 的Providers,請參考 The PowerShell Software Developers Kit provides documents should you wish to build your own Providers.

列出PowerShell 的Providers
使用 "Get-PSProvider" cmdlet


2014年7月11日 星期五

PowerShell Fist programming(1):如何使用cmdlets來新增和設定rigistry key

我們試著執行一個example,在HKEY_LOCAL_MACHINE\SOFTWARE底下建立一個新的"MyKey"的registry key,和將該registry key的default value設定為"MyValue"。
·         使用PowerShell console
使用New-Item cmdlet新增"MyKey" 的registry key和寫入"MyValue"的default value的command如下:
New-Item -Path HKLM:\Software\MyKey -Value "MyValue"


新增的registry key和寫入該key的default value,結果如下:

Powershell Function call

Powershell 既然是一個script language,就有所謂的function call。

·         directly executable code
以下是直接在script file裡面來呼叫sum function
1、將寫好的script存成.ps1檔案。



PowerShell Simply induction

Windows PowerShell 是一個新的任務基礎(task-based)的command-line shell和 scripting language,是特別為系統的管理(administration)而設計。
Windows PowerShell 是以.NET Framework為基礎來建立,, 可以幫助 IT professionals 和power users控制和自動化windows OS和應用程式的管理。
此外, Windows PowerShell有豐富的expression parser和完整先進的scripting language。
Windows PowerShell is very different.
  • Windows PowerShell不處理text,他處理以.NET Framework platform為基礎的 objects。
  • Windows PowerShell 有自己的 built-in commands,所有的shell commands使用相同的command parser和一致的介面。
Windows PowerShell 使用自己的語言,而非使用既有已經存在的語言,因為:
  • Windows PowerShell 需要管理Microsoft .NET Framework objects.的語言。
  • 這個語言需要一致的環境來使用cmdlets。
  • 這個語言需要支援complex tasks,而不是使簡單的tasks更複雜。
  •  這個語言需要與如C#般在.NET Framework中使用的higher-level languages一致。

2014年7月4日 星期五

WMI First using sample:Method 2:To connect to WMI and retrieve an object using a moniker --- Creating a Registry Key Using VBScript

WMI monikers can consist of three parts: one mandatory component and two optional components. The mandatory component is the "winmgmts:" prefix.
All WMI monikers must begin with "winmgmts:" as shown here:
Set objSWbemServices = GetObject("winmgmts:")
After you have obtained a reference to SWbemServices, you can then invoke one of the object methods as shown here:
Set colSWbemObjectSet = objSWbemServices.InstancesOf("Win32_LogicalDisk")

Step 1、write the vb script as following, and save it as "NEW_RegistryKey.vbs"

WMI First using sample:Method 1: To connect to WMI using SWbemLocator--- Creating a Registry Key Using VBScript

You can use the methods of the SWbemLocator object to obtain an SWbemServices object that represents a connection to a namespace on either a local computer or a remote host computer. You can then use the methods of the SWbemServices object to access WMI.
You can use the methods of an SWbemServices object to perform operations against a namespace on either a local host or a remote host. This object cannot be created by the VBScript CreateObject call.

Step 1、write the vb script as following, and save it as "NEW_RegistryKey.vbs"

2014年6月30日 星期一

Windows WMI的架構簡介

Windows Management Instrumentation (WMI)是management data和操作Windows-based (OS)operating systems的infrastructure。 可以寫WMI scripts或applications來自動化管理remote computers,但是WMI也支援operating system的其他部分和其他產品,如System Center Operations Manager、早期的Microsoft Operations Manager (MOM)、Windows Remote Management (WinRM)。

下圖顯示WMI infrastructure、 WMI providers and managed objects的關係,並且顯示WMI infrastructure、WMI consumers之間的關係。
在 WMI infrastructure,WMI service (Winmgmt,operating system component)作為 management applications和WMI data providers的mediator ,he WMI repository 是一個WMI-related static data 的storage area。
當management application或 script 呼叫連接到一個WMI namespace,WMI service 開始執行。 WMI service經由COM interface 和management applications互動。

2014年6月27日 星期五

如何查看安裝的 .NET Framework 版本為何和是否有做update

可以參考MSDN的資料:

How to: Determine Which .NET Framework Versions Are Installed



Users can install and run multiple versions of the .NET Framework on their computers. When you develop or deploy your app, you might need to know which .NET Framework versions are installed on the user’s computer. Note that the .NET Framework consists of two main components, which are versioned separately:
  • A set of assemblies, which are collections of types and resources that provide the functionality for your apps. The .NET Framework and assemblies share the same version number.
  • The common language runtime (CLR), which manages and executes your app's code. The CLR is identified by its own version number (see .NET Framework Versions and Dependencies).

2014年6月25日 星期三

Auto logon(2):Create auto logon with WMI by using VB Script

''''''Sample code如下''''''''

'Set wshShell = WScript.CreateObject( "WScript.Shell" )
'strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
Set oNetwork = CreateObject("wScript.Network")
strComputerName=oNetwork.Computername         
strDefaultUserName="test6"
strDefaultPassword="pwd6"
strGroup="administrators"
strAutoAdminLogon="1"

2014年6月19日 星期四

Web(6) HTML +xml+ CSS的HELLO WORLD

經由CSS自訂文檔中的元素(XML 元素)的設置樣式,做一個簡單的"Hello world"程式。
l   結果如下:


2014年6月18日 星期三

Web(5) HTML +xml+ XSLT的HELLO WORLD

做一個簡單的"Hello world"程式。
結果如下:




Web(4) HTML +VB Script 的HELLO WORLD

做一個簡單的"Hello world"程式。
l   結果如下:



Web(3) HTML +Java Script 的HELLO WORLD

做一個簡單的"Hello world"程式。
結果如下:



Web(3) HTML +Java Script 的HELLO WORLD with Input Tag

Sample code 如下:
<html>
 <head>
<script type='text/javascript'>
function buttonClickHandler() {
        var userName = document.getElementById("nameInput").value;
        var greetingString = "Hello, " + userName + "!";
        document.getElementById("greetingOutput").innerText = greetingString;
}
</script>
 </head>

2014年6月16日 星期一

Auto logon(1):Create auto logon with WMI by using Power Shell Script


Step1、將以下的指令寫入文字編輯器,並存成"autologon.ps1

######宣告變數,$computer也可以為$computer="localhost
param (
  [Parameter(Mandatory=$false)][String[]]$computer = ".",
  [Parameter(Mandatory=$false)][String[]]$computerName = $env:computername,
  [Parameter(Mandatory=$false)][String]$DefaultDomainName = $env:USERDOMAIN,
  [Parameter(Mandatory=$false)][String]$DefaultUserName = "test",
  [Parameter(Mandatory=$false)][String]$DefaultPassword  = "pwd",
  [Parameter(Mandatory=$false)][String]$Group  = "administrators",
  [Parameter(Mandatory=$false)][Int]$AutoLogonCount
)

Web(2):HTML + CSS 的HELLO WORLD

<!--
XML 元素指的是從(且包括)開始標籤直到(且包括)結束標籤的部分。
元素可包含其他元素、文本或者兩者的混合物。元素也可以擁有屬性。
-->

l   Sample code 如下:
<html>
 <head>
  <style type="text/css">
   h1
   {
    font-family:Verdana, Arial;
    font-size:60px;
    margin-left:30px;
    color: red;
    display: block;
   }
  </style>
 </head>
 <body>
   <h1>Hello World!</h1>
 </body>
</html>

結果如下:



WEB(1):HTML的HELLO WORLD

html的註解方式<!--註解文字 -->
HTML 的註解是由角括號 < 開始,然後一個驚嘆號 ! ,接著兩個連續的破折號 -- ,接著是註解內容,結尾則是兩個連續的破折號 -- ,最後角括號 > 結束,例如
<!-- comment -->
註解可以是多行的,例如
<!-- <!DOCTYPE> 聲明位於文檔中的最前面的位置,處於 <html> 標籤之前。此標籤可告知流覽器文檔使用哪種 HTML 或 XHTML 規範。
-->