Content by Category
.NET 1.x
.NET 2.0
.NET 3.0
.NET 3.5
.NET 4.0
.NET 4.5
.NET Assemblies
.NET Framework
.NET Getting Started
Accessibility
ADO.NET
Advertorials
Agile Development
AJAX
Amazon Web Services
Analysis Services
Android
Architecture
Arduino
ASP .NET Web API
ASP.NET
ASP.NET MVC
ASP.NET WebForms
Azure
B2B (Business Integration)
BDD
Big Data
Bing
BizTalk
Book Excerpts
Build and Deploy
Business Intelligence
C#
C++
ClickOnce
Cloud Computing
Code Contracts
CODE Framework Info - non Technical
CODE on the Road!
COM+
Community
Conferences
Continuous Integration
Crystal Reports
CSLA.NET
CSS
Data
Debugger
Design Patterns
Development Process
Display Technologies
Distributed Computing
Document Database
DotNetNuke
DSL
Dynamic Languages
Dynamic Programming
Editorials
Enterprise Services ("COM+")
Entity Framework
Events
Expression Blend
F#
Fox to Fox
Frameworks
Functional Programming
Git
Graphics
HTML 5
Internet Explorer 8.0
Interviews
IOS
iPhone
Iron Ruby
Java
Java Script
JavaScript
jQuery
JSON
Lightswitch
LINQ
Linux
LUA
Mac OS X
MDX
Messaging
Metro
Microsoft Application Blocks
Microsoft Business Rules Framework
Microsoft Dynamics
Microsoft Expression
Microsoft Office
Mobile Development
Mobile PC
Mono
MsBuild
MVVM
MySQL
Network
NHibernate
node.js
NOSQL
Nuget
Object Oriented Development
Objective C
Odata
OLAP
Open Source
Opinion
Opinions
Oracle
ORM
Other Languages
Parallel Programming
Patterns
PHP
Podcasts
Post Mortem
PowerPoint
Print/Output
Prism
Product News
Product Reviews
Project Management
Prolog
Python
Q&A
Rails
Rake
Razor
Reporting Services
REST
RIA Services
Ruby
Ruby on Rails
Scheme
Search
Security
Services
SharePoint
SignalR
Silverlight
SOA
Social Networks
Software & Law
Software Business
Source Control
Speech-Enabled Applications
SQL Server
SQL Server 2000
SQL Server 2005
SQL Server 2008
SQL Server 2012
SQL Server CE/AnyWhere/Mobile/Compact
SSIS
Subversion
Sync Framework
Tablet PC
TDD
Team System
Techniques
Testing and Quality Control
TFS
Tips
TypeScript
UI Design
UML
User Groups
VB Script
VB.NET
Version Control
VFP and .NET
VFP and SQL Server
Virtual Earth
Vista
Visual Basic
Visual Basic 6 (and older)
Visual FoxPro
Visual Studio .NET
Visual Studio 11
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
Visual Studio 2011
Visual Studio 2012
Visual Studio Tools for Office
VSX
WCF
Web Development (general)
Web Services
WebMatrix
WF
Whitepapers
Windows 7
Windows 8
Windows Azure
Windows Live
Windows Phone 7
Windows Phone SDK
Windows Server
Windows Vista
WinForms
WinRT
Workflow
WPF
XAML
Xiine Documentation
XML
XNA
XSLT



LearnNow


XAMALOT
 


SSWUG

Reader rating:
Click here to read 1 comment about this article.
Article source: CoDe (2000 - Spring)


Article Pages: < Previous - 1 2  3  4 - Next >


The Windows Scripting Host (Cont.)

Shell Object Properties and Methods

Environment: This property provides access to environment collection. Information such as number of processors, paths, OS, etc can be determined from this collection.

oEnv = wshshell.environment
For Each x In oEnv
   ?oEnv
Next x

The following is a partial listing of some typical environmental variables:

  • NUMBER_OF_PROCESSORS
  • OS
  • PROCESSOR_ARCHITECTURE
  • PROCESSOR_IDENTIFIER
  • WINDIR

So, to find out the number of processors:

Numprocessors = oEnv.Item("NUMBER_OF_PROCESSORS")

Like most collections, if you want to find out how many members are contained in the collection, you can refer to the Count Property:

Numitems = oEnv.Count

To be compliant with the Java Language, collections in the Windows Scripting Host also support the Length Property ? which provides the same functionality as the Count Property:

Numitems = oEnv.Length

SpecialFolders: This property provides access to the collection of Windows Shell Folders. The following is a listing of folders:

  • AllUsersDesktop
  • AllUsersStartMenu
  • AllUsersPrograms
  • AllUsersStartup
  • Desktop
  • Favorites
  • Fonts
  • MyDocuments
  • NetHood
  • PrintHood
  • Programs
  • Recent
  • SendTo
  • StartMenu
  • Startup
  • Templates

To find the actual path of the desktop folder, issue this line of code:

DesktopPath = WSHShell.SpecialFolders("Desktop")
CreateShortcut (strPathname)

This method creates and returns a shortcut object. The following block of code illustrates how to create a desktop shortcut:

*/ Read desktop path using WshSpecialFolders object
DesktopPath = WSHShell.SpecialFolders("Desktop")
*/ Create a shortcut object on the desktop
MyShortcut = ;
  WSHShell.CreateShortcut(DesktopPath + "\Shortcut to MyFile.lnk")
*/ Set shortcut object properties and save it
FileName = GetFile()
If !Empty(FileName)
   FileDir = JustPath(FileName)
   With MyShortcut
      .TargetPath = Filename
      .WorkingDirectory = FileDir
      .Save
   EndWith   
Endif

The CreateShortcut Method returns a WSHShortcut Object. This object is only exposed through the CreateShortcut Method. The WSHShortcut object has the following properties:

Arguments             Parameters to a shortcut object.

Description            A description of a shortcut object.

Hotkey                 The hot key of a shortcut object.

IconLocation         The icon location of a shortcut object.

TargetPath           The target path of a shortcut object.

WindowStyle         The window style of a shortcut object.

WorkingDirectory    The working directory of a shortcut object.

The WSHShortcut Object only has one method, Save(), which saves the shortcut object to the file system.

ExpandEnvironmentSettings (strString)

This method expands a process environment variable and returns the result. A typical environment variable is WINDIR. The following code illustrates how this method works:

Fullpath = WSHShell.ExpandEnvironmentStrings("%windir%\notepad.exe, 0")
Popup (strText, [natSecondsToWait], [strTitle], [natType])

This method displays the Window MessageBox. Unlike the existing MessageBox Function, the Popup method accepts an optional argument to clear the dialog after a specified amount of time. The following line of code illustrates how the Popup Method works:

WSHShell.Popup("Message",1,"Title",64)
RegDelete(strName)
RegRead(strName)
RegWrite(strName, anyValue, [strType] )

The Windows Scripting Host Shell Object provides three methods for working with the Windows Registry. With these methods, entries can be created, written, read, and deleted. If you attempt to write to a key that does not exist, the key will be created. The following code illustrates how these three methods work:

To create a new key:

WSHshell.RegWrite("HKCU\Software\Microsoft\VisualFoxPro\6.0\Desktop\JVP",'Default Value')

Then, to modify the value:

WSHshell.RegWrite("HKCU\Software\Microsoft\VisualFoxPro\6.0\Desktop\JVP",'New Value')

Next, to just read a value from a key:

WSHshell.RegRead("HKCU\Software\Microsoft\VisualFoxPro\6.0\Desktop\JVP")

Finally, to delete a key:

WSHshell.RegDelete("HKCU\Software\Microsoft\VisualFoxPro\6.0\Desktop\JVP")
Run(strCommand, [intWindowStyle], [blnWaitOnReturn]) 

The Run Method creates a new process that executes a specified command with a specified window style. In addition to being able to specify the command and the window style, a third parameter can be used to determine if script execution should pause until the new process has terminated.

Applications windows can be started in several states. The following outlines the various options available:

SW_HIDE                                 0

SW_MINIMIZE                           6

SW_RESTORE                            9

SW_SHOW                                5

SW_SHOWMAXIMIZED                 3

SW_SHOWMINIMIZED                  2

SW_SHOWMINNOACTIVE              7

SW_SHOWNA                             8

SW_SHOWNOACTIVATE                4

SW_SHOWNORMAL                      1

The following code starts Notepad with a normal window:

WSHshell.Run("notepad",1)

This code starts Notepad with a maximized window. In addition, the user must close Notepad before control will return to Visual FoxPro:

WSHshell.Run("notepad",3,.T.)

Fully qualified paths can be used to denote a file to execute. The following code starts Visio:

WSHshell.Run("D:\VISIO\VISIO32.EXE")

Also, script files can be executed with the Run Method as well:

WSHshell.Run("hello world.vbs")
WSHshell.Run("hello world.js")
&


Article Pages: < Previous - 1 2  3  4 - Next Page: 'Network Object Properties and Methods' >>

Page 1: The Windows Scripting Host
Page 2: The scripting host objects
Page 3: Shell Object Properties and Methods
Page 4: Network Object Properties and Methods

How would you rate the quality of this article?
1 2 3 4 5
Poor      Outstanding

Tell us why you rated the content this way. (optional)

Average rating:
3.3 out of 5

27 people have rated this article.

Instantly Search Terabytes Of Text
“Lightning Fast”
– Redmond Mag
“Covers all data
sources” – eWeek
25+ fielded & full-text search options
dtSearch’s own document filters highlight hits in popular file types
Web Spider supports static & dynamic data
APIs for .NET, Java, C++, SQL, etc.
Win / Linux (64-bit & 32-bit)
www.dtSearch.com
 

      AppsWorld Europe

 

Sharepoint TechCon