Freigeben über


Support for Existing apps in Monad

Monad provides strong support for existing apps and technology. If you use native cmdline exes, vbscripts, batch files, perl scripts etc to manage and maintain windows, you can pretty much use them the same way from monad as you would from cmd.exe.

For example, I am used to findstr.exe and xcopy.exe. I can use them from monad as is.

MSH C:\> findstr Monad monad.txt

"Monad Rocks"

MSH C:\>

MSH C:\> xcopy monad.txt monad2.txt

Does monad2.txt specify a file name

or directory name on the target

(F = file, D = directory)? f

C:monad.txt

1 File(s) copied

MSH C:\>

You can also use get-command cmdlet to discover them if they are in your PATH.

MSH C:\> get-command findstr

CommandType Name Definition

----------- ---- ----------

Application findstr.exe C:\WINDOWS\system32\findstr.exe

MSH C:\>

Let’s look at a vbscript example. Script Center website has a good collection of useful vbscripts. Today we will play with this one. The script uses WMI to query the machine for computer system and processor information. You can run it in Monad as follows

MSH C:\> cscript processor.vbs

Microsoft (R) Windows Script Host Version 5.6

Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

Computer Name: ABHISHEK1

System Type: X86-based PC

Number Of Processors: 2

Manufacturer: GenuineIntel

Name: Intel(R) Pentium(R) 4 CPU 3.00GHz

Description: x86 Family 15 Model 2 Stepping 9

Processor ID: BFEBFBFF00000F29

Address Width: 32

Data Width: 32

Family: 2

Maximum Clock Speed: 2992

Manufacturer: GenuineIntel

Name: Intel(R) Pentium(R) 4 CPU 3.00GHz

Description: x86 Family 15 Model 2 Stepping 9

Processor ID: BFEBFBFF00000F29

Address Width: 32

Data Width: 32

Family: 2

Maximum Clock Speed: 2992

MSH C:\>

If you look at the vbscript example above, it is using WMI to query for some system properties. WMI is a useful existing management technology and Monad provides strong support for it. The primary interface to WMI in Monad is the get-wmiobject cmdlet. Let’s use it to get the same information we got from the vbscript.

First we query for an instance of the win32_ComputerSystem class

MSH C:\> get-wmiobject win32_computersystem | format-list SystemType,Name,NumberOfProcessors

SystemType : X86-based PC

Name : ABHISHEK1

NumberOfProcessors : 2

MSH C:\>

How did the get-wmiobject cmdlet discover the namespace? The default namespace used by the cmdlet is root\cimv2. But you can supply the namespace via the –Namespace parameter. The cmdlet also supports accessing information via WMI from remote machines and can also be used to browse the namespace for class information. But more on this cmdlet later; let’s complete the task at hand. We need to query WMI for instances of win32_processor class.

 

MSH C:\> $processor = get-wmiobject win32_processor

MSH C:\> $processor | format-list Name,ProcessorID,MaxClockSpeed,AddressWidth,Description

Name : Intel(R) Pentium(R) 4 CPU 3.00GHz

ProcessorID : BFEBFBFF00000F29

MaxClockSpeed : 2992

AddressWidth : 32

Description : x86 Family 15 Model 2 Stepping 9

Name : Intel(R) Pentium(R) 4 CPU 3.00GHz

ProcessorID : BFEBFBFF00000F29

MaxClockSpeed : 2992

AddressWidth : 32

Description : x86 Family 15 Model 2 Stepping 9

Using get-wmiobject and about 3 lines of monad script we have ported the above vbscript to monad! Monad will also provide support for COM interop. You will be able to use Monad scripts for COM automation.

That’s all I have time for today. Hope you find it useful!

-Abhishek

Comments

  • Anonymous
    August 26, 2005
    What about Unix-style file descriptor handling? Does Monad provide a convenient syntax for capturing the output (or error messages on stderr) of external programs?
  • Anonymous
    August 26, 2005
    The comment has been removed
  • Anonymous
    August 27, 2005
    > MSH>write-error error 2>&1 | foreach { $err = $_ }

    Looks good!

    > When we release a newer build

    I've not followed the latest news about Monad. AFAIK, there is a beta standalone release that can be downloaded, and another as part of the WinFX beta SDK. On the other hand, there was an announcement that Monad will not be included in Windows Vista.

    I'm aware that you may not be able to say anything on this subject (either because nothing has been decided yet, or for policy reasons), but I'd be very interested if you could elaborate this "When we release a newer build". Monad seem very powerful, and potentially very useful already. I'd like to have a better idea of how far from completion it is, and whether it could be released first as some kind of powertoy for Windows Vista / Vista Server beta / 2003 server. More generally, what are the plans for Monad's future (or what you can tell about it)?
  • Anonymous
    August 27, 2005
    > More generally, what are the plans for Monad's future (or what you can tell
    > about it)?

    There is no news to share on this at this time. We are working the issue vigorously and expect to announce a plan within a couple of months. If the good lord willin' and the creek don't rise - I think you'll be pretty pleased by how things turn out. :-)

    jps
  • Anonymous
    August 27, 2005
    While we are on the topic. $? is a bool which tells you whether the last thing that ran completed successfully or not. $LastExitCode contains the exitcode of the last process lauched from the shell.

    MSH> ping localhost

    Pinging jpslap03.ntdev.corp.microsoft.com [127.0.0.1] with 32 bytes of data:

    Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
    Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
    Reply from 127.0.0.1: bytes=32 time<1ms TTL=128
    Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

    Ping statistics for 127.0.0.1:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
    Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms
    MSH> "$? $LastExitCode"
    True 0
    MSH> ping nosuchmachine
    Ping request could not find host nosuchmachine. Please check the name and try again.
    MSH> "$? $LastExitCode"
    False 1
    MSH>
  • Anonymous
    August 29, 2005
    $LastExitCode is very useful but unfortunatelly it doesn't work *.cmd files. Is there any principal problem with *.cmd or can it be improved?
    Thanks a lot for your possible answer
    Vojta
  • Anonymous
    September 02, 2005
    i got the standalone beta download and there's nothing in the documentation about providers and some of the things that are in the help files are wrong (new-provider is nowhere to be found)

    i realize this is a beta but i would like to know where to go for this kind of information... or at least how to install a new provider... i suppose the rest could be easily discovered using reflector ;)
  • Anonymous
    March 30, 2006
    > MSH C:> xcopy monad.txt monad2.txt

    What about running non-executables?  In the standard CMD.EXE, I can type in the name of the file and CMD.EXE will launch the application associated with that file for you.  For example, in CMD.EXE, doing this:
    C:WINDOWS>greenstone.bmp
    opens Windows Picture and Fax Viewer to view greenstone.bmp.

    I'm probably the only person who uses CMD.EXE to open regular files... ;-) I'm pretty sure there's a CmdLet or something to mimic this in MONAD, but I'm new.  Any thoughts?
  • Anonymous
    March 30, 2006
    ALl you have to do is the following:

       Invoke-item .greenstone.bmp

    We have an alias so you can just do this:

       ii .greenstone.bmp

    Enjoy!
    Jeffrey Snover
  • Anonymous
    April 01, 2006
    Great idea of your article. We are fully agry with you. Maybe you can talk more for us.
  • Anonymous
    May 01, 2006
    Wellcome more info...