IT tutorials
 
Technology
 

Windows Server 2008 : Creating Basic Visual Basic Scripts - Displaying a Message Box with a Visual Basic Script

8/24/2013 9:24:08 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
1. Accessing a Network Share with filesystemobject

You can use the filesystemobject to access a network share. The following code connects to the apps share on DC1:

set objfso = createobject("scripting.filesystemobject")
set objdrive = objfso.getfolder("\\dc1\apps")

Tip

To connect to a different share, just substitute \\dc1\apps with the Universal Naming Convention (UNC) path of your share.

2. Calling Scripts from a Batch File

There might be times when you want to run a script from a batch file. You precede the path and the name of the script with the cscript statement.

Tip

cscript is the command-based script host. There are times when the script runs without the cscript command, but if you want to ensure the script runs without problems, you should use cscript.


For example, if you want a batch file to run a script named logon.vbs, you can use the following line:

cscript c:\scripts\logon.vbs

3. Displaying a Message Box with a Visual Basic Script

There are many times when you want to create a pop-up message box to provide feedback to the user, or even to send a message to a user after logon. The basic syntax is

msgbox "message ",[msg-box-style], "title"

msgbox CommandsComments
Display a basic message.
msgbox "Only Pearson employees
should use this computer.",
vbinformation, "Warning"

Displays a simple message to the user. It includes an information icon and the title bar includes the text “Warning.”
Add blank lines in a message.
msgbox "Only Pearson employees
should use this computer." &
vbcrlf & vbcrlf & "If you are
not an employee of Pearson, you
should terminate this session
immediately.", vbinformation,
"Warning"

If you have a long message, you can choose where line breaks are added with the vbcrlfFigure 1 shows how script is displayed when it is executed. constant.

Note

The msgbox command is entered as a single line in Notepad without pressing Enter at all.


Figure 1. Dialog box with line feeds


The following table shows some of the message box styles you can use as the second parameter in a dialog box.

Note

These styles are actually constants (integers). For example, vbinformation is a constant for the number 64. You can enter the integers instead but the constants are easier to remember.


StyleComments
vbinformationShows a white “i” in a blue circle.
vbexclamationShows a black exclamation mark in a yellow triangle.
vbcriticalShows a black “x” in a red circle.
vbquestionShows a white “?” in a blue circle.
vbokonlyDisplays OK button only (default). The OK button has a return value of 1.
vbokcancelDisplays OK and Cancel buttons. The OK button has a return value of 1 and Cancel returns 2.
vbabortretryignoreDisplays Abort, Retry, and Ignore buttons. The Abort button has a return value of 3, Retry returns 4, and Ignore returns 5.
vbyesnocancelDisplays Yes, No, and Cancel buttons. The Yes button has a return value of 6, No returns 7, and Cancel returns 2.
vbyesnoDisplays Yes and No buttons. The Yes button has a return value of 6, and No returns 7.
vbretrycancelDisplays Retry and Cancel buttons. The retry button has a return value of 4, and Cancel returns 2.
msgboxsetforegroundSets the message box as the foreground window.

You can combine the buttons using the plus character (+) to concatenate message box styles. For example, if you want to use the question mark icon with the YesNo buttons, you can use the following code: vbquestion + vbyesno. and

 
Others
 
- Windows Server 2008 : Creating Basic Visual Basic Scripts - Working with filesystemobject
- Windows 7 : Installing and Upgrading Programs - Common Installation Prompts (part 2) - Type of Installation
- Windows 7 : Installing and Upgrading Programs - Common Installation Prompts (part 1) - Compliance check , The End User License Agreement
- Windows 7 : Installing and Upgrading Programs - Installing and Upgrading from a Disk
- Windows Server 2012 : Using Capacity-Analysis Tools - Other Microsoft Assessment and Planning Tools, Third-Party Toolset
- Windows Server 2012 : Using Capacity-Analysis Tools - Windows Performance Monitor
- Windows Server 2012 : Using Capacity-Analysis Tools - Network Monitor (part 2) - Capturing Network Traffic Between Computers , Parsing Captured Network Traffic Data
- Windows Server 2012 : Using Capacity-Analysis Tools - Network Monitor (part 1) - Using Network Monitor 3.4
- Windows Server 2012 : Using Capacity-Analysis Tools - Task Manager
- Windows Server 2012 : Capacity Analysis and Performance Optimization - Defining Capacity Analysis
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us