中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-24 17:59
47,812 topics / 349,910 posts / today 1 new / 48,262 members
WinPE、PowerShell及其它命令行系统专区 » [Recommendation] Power Shell is here, how far is the distance between Windows and Unix?
Printable Version  5,826 / 10
Floor1 qzwqzw Posted 2007-05-16 18:41
银牌会员 Posts 636 Credits 2,343
Source: Next Generation Shell Scripting Language, Windows Power Shell!
Author: Zealic


Today, I went home and browsed cnbeta.com as usual to see what new content there was.
Then, I saw that there was such a Windows Power Shell 1.0
Well, I'm very interested in this thing. After all, the current Shell of Windows is really too weak. Immediately, I downloaded from the Microsoft site, installed it. I found that it was released in the form of a patch package, not a regular MSI. Then, I estimated that Vista already came with this thing.
Next, I will try to understand PowerShell (referred to as PS below)
After the installation is complete, open the program menu. It seems that M$'s old habits are still well maintained, and the help is very detailed
Release Notes
Quick Reference
Getting Started
User Guide
Other details are not elaborated.

After reading the document, I found that an important point is that PS is written in .Net and fully supports any object of .Net.
.Net! What?
Take out the Dragon Slaying Sword Reflector to open all the DLLs in the main program and directory of PowerShell. It failed: the CLR header is invalid, and none of them are decompiled correctly. Isn't it said that PS is written in .Net? How... Is M$ fooling us?


Then how does it operate .Net objects?
Then again, take out PE Explorer to open the main program of PS and look at its API imports. I found that the main program of PS.
Referenced the function CorBindToRuntimeEx of mscoree.dll
MSDN explains CorbindToRuntimeEx like this: It enables unmanaged hosts to load the common language runtime into the process.
This shows that PS executes the necessary initialization with unmanaged code before running, and then enters the CLR. It may also be to establish a mixed environment to facilitate the interactive execution of managed and unmanaged code; then, where is the host program?


Use the search function of Windows to search for the keyword "PowerShell", but it failed. All the found ones are things in the program directory!~~~
After thinking carefully, I decided to start from the root. The Windows patch program is packaged with CAB, so it can be opened directly with WinRAR. Open WindowsXP-KB926140-x86-CHS.exe with WinRAR, and found the thing I need "_sfx_manifest_". Open it in text format to view, and found some things I need:
"microsoft.powershell.consolehost.dll" = "_sfx_0008._p", "powershell.exe"
"system.management.automation.dll" = "_sfx_0009._p", "microsoft.powershell.consolehost.dll"
"microsoft.powershell.security.dll" = "_sfx_0010._p", "system.management.automation.dll"
......


This fully shows that the host program exists. It is Microsoft.PowerShell.ConsoleHost.dll. Then, why can't I find these files?
Considering again, I think these things may be in the GAC. Open the GAC directory to view; Ha, they are all there?
But there is still a problem with Reflector! Reflector can't find these assemblies~~~, and using Open Cache can't find them either!!!
No way, just extract the files from the patch package. After extracting them and opening them with Reflector, I was stupid. "File is not a portable executable. DOS header does not contain 'MZ' signature." The file header is incorrect. Open it with Notepad and find that the file header is actually "PA19". What format is this? Why have I never seen it before? Native code generated by NGEN? Or encrypted Managed DLL?


Don't care about this for now. Find other ways to get the assemblies in the GAC.
The GAC directory has been taken over by a Shell Extension. So what I need to do now is to get the files in the directory out. I tried dialog boxes and copying folders one after another, but it didn't work. Finally, I solved it with a command line:
xcopy /e C:\Windows\assembly\GAC_MSIL G:\GAC_MSIL

Then look for the required assemblies in the copied directory. Ha, now we can see the code of PS. This will be a very pleasant thing.
In addition, through the _sfx_manifest_ file and Reflector analyzing the assembly references, I found that there is an additional assembly "System.Management.Automation.dll", and its EXE comment is "Microsoft Command-Line Shell Engine Core Assembly"
I packaged these extracted assemblies and uploaded them. Click here to download. We can analyze its code with Reflector, or package it together with the main program of PS for XCOPY deployment, and use it as the script system of the product.


Here, we have all the code assemblies. Let's see what exactly PowerShell is and what it can do:
Due to the following reasons, Windows PowerShell uses its own language instead of reusing the existing language:
•Windows PowerShell needs a language for managing .NET objects.
•The language needs to provide a consistent environment for using cmdlets.
•The language needs to support complex tasks without making simple tasks more complicated.
•The language needs to be consistent with advanced languages used in .NET programming, such as C#.


Some characteristics of the PS language:
1. Some characteristics of advanced languages (variables, arrays, operators, hash tables, functions, conditional statements, loop statements...)
2. Can directly navigate in the file system, registry, certificate store, and drive, and the navigation method is very similar to the DOS navigation method we are familiar with.
3. Powerful wildcard and string search functions
4. Can create and operate .Net objects and COM objects
5. Can use any object (including .Net and COM objects) to interact with the target based on the object pipeline function
7. Can directly access WMI objects.
8. Can write .Net assemblies to extend PS. Through extension, the functions of PS can be expanded almost infinitely.

For other characteristics, please refer to the help document of PowerShell.

Common commands:
Get-Date - Get the current date.
Get-Help - Get help.
Get-Member - View the object structure (can use this command to view the members of .Net objects).
Get-WmiObject - Get WMI objects.
Get-Process - Get process objects.
Get-Service - Get Windows service objects.


Now it's dark and the wind is high, urging people to sleep. I can only wait until tomorrow to continue the research. Finally, let's end with the classic Hello World. Tomorrow, we will come to further study PS:
Use the output command
Write-Output "Hello World!"
Use .Net to output
::ForegroundColor = ::Blue
::WriteLine(
"Hello World!")

It's really a powerful Shell!


PS:
I have always hoped that M$ can provide a non-graphical interface. It seems that the time is still early, but now it is developing in a good direction. PowerShell gives me hope. Maybe PowerShell is the prototype of the future non-graphical interface Server.
Therefore, I boldly predict that Vienna (the next OS after Vista, completely rewriting the kernel) will separate the kernel and the graphical interface, rather than the current NT-based kernel, where the kernel and the graphical interface will be together. And there will be a non-graphical interface Server and the current graphical Server, and both will coexist for a long time. As for who will be replaced, I don't think it's possible.
Therefore, what I can imagine is that Microsoft will upgrade Windows PE to make it use the core of Vienna, and will include .Net Framework X.Y, and be divided into character interface and graphical interface. In this way, Windows PE will become an extremely handy system diagnosis and troubleshooting tool.
Windows Server is getting closer to Unix/Linux Server.
Floor2 wjxsjd Posted 2007-05-16 21:07
初级用户 Posts 15 Credits 31
Learning
Floor3 qkl12345 Posted 2007-06-03 13:31
初级用户 Posts 12 Credits 27
Yes, it feels like Microsoft is competing with UNIX's SHELL. Although Microsoft says its PS is not mature yet.
Floor4 driver1998 Posted 2008-05-30 16:55
高级用户 Posts 373 Credits 740 From 中国,广东
It seems that Microsoft abandoned DOS and instead took up Unix.
Floor5 wwwcccyyy Posted 2008-06-02 18:03
中级用户 Posts 110 Credits 224 From 广东
Floor6 cjm7065 Posted 2008-07-27 12:50
初级用户 Posts 16 Credits 32
It's relatively professional and not easy to understand!
Floor7 bailang3106 Posted 2008-09-24 17:09
初级用户 Posts 19 Credits 36
Batch processing has much fewer functions than the Linux shell. It's time for some action.
Floor8 ifly Posted 2008-10-12 16:43
初级用户 Posts 14 Credits 25
The introduction is very detailed, I've learned it.
Floor9 fjke Posted 2008-11-04 09:50
新手上路 Posts 9 Credits 16
I'm very ashamed, I can't understand it very well
Floor10 listme07 Posted 2008-11-13 12:34
新手上路 Posts 2 Credits 3
Floor11 speedide Posted 2008-11-23 00:01
新手上路 Posts 10 Credits 17
WINDOWS always has to be compatible with previous products....
Now it seems that WINDOWS 7 still uses the NT kernel...

Although I don't understand programming, I think one advantage of WINDOWS servers is that the setup is very convenient and the functions are also very powerful.
If there really is a kernel that doesn't use a graphical interface, then either a lot of past products have to be rewritten (writing another set of products or writing a command-line program and then writing a graphical program as the front end are all very terrifying....)

Although there is that MIN WIN kernel video online, whether such a company will really use it depends on how the company develops.
Look at all of Microsoft's current products......The list is so long....

I don't know who can solve this problem for them....
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023