programming4us
programming4us
DESKTOP

Windows Vista : Programming the WshNetwork Object

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

WshNetwork is a generic name for an object that enables you to work with various aspects of the Windows network environment. You can determine the computer name and username, you can enumerate the mapped network drives, you can map new network drives, and more. The next couple of sections show you how to work with this object.

Referencing the WshNetwork Object

WshNetwork refers to the Network object exposed via the Automation interface of WScript. This means you use CreateObject to return this object, as shown here:

Set objWshNetwork = WScript.CreateObject("WScript.Network")

From here, you use the WshNetwork variable to access the object’s properties and methods.

WshNetwork Object Properties

The WshNetwork object supports three properties:

ComputerNameReturns the network name of the computer
UserDomainReturns the network domain name of the current user
UserNameReturns the username of the current user

Mapping Network Printers

The WshNetwork object supports several methods for working with remote printers. For example, to map a network printer to a local printer resource, use the WshNetwork object’s AddWindowsPrinterConnection method:

WshNetwork.AddPrinterConnection strPrinterPath
						

WshNetworkThe WshNetwork object
strPrinterPathThe UNC path to the network printer

Here’s an example:

Set objWshNetwork = WScript.CreateObject("WScript.Network")
objWshNetwork.AddWindowsPrinterConnection "\\ZEUS\printer"

To remove a remote printer mapping, use the WshNetwork object’s RemovePrinterConnection method:

WshNetwork.RemovePrinterConnection strPrinterPath [, bForce] [, bUpdateProfile]


					  

WshNetworkThe WshNetwork object
strPrinterPathThe UNC path to the network printer
bForceIf True, the resource is removed even if it is currently being used
bUpdateProfileIf True, the printer mapping is removed from the user’s profile

Here’s an example:

Set objWshNetwork = WScript.CreateObject("WScript.Network")
objWshNetwork.RemovePrinterConnection "\\ZEUS\inkjet"

Mapping Network Drives

The WshNetwork object supports several methods for mapping network drives. To map a shared network folder to a local drive letter, use the WshNetwork object’s MapNetworkDrive method:

WshNetwork.MapNetworkDrive strLocalName, strRemoteName, [bUpdateProfile], [strUser], [strPassword]


					  

WshNetworkThe WshNetwork object
strLocalNameThe local drive letter to which the remote share will be mapped (for example, F:)
strRemoteNameThe UNC path for the remote share
bUpdateProfileIf True, the drive mapping is stored in the user’s profile
strUserUse this value to enter a username that might be required to map the remote share (if you’re logged on as a user who doesn’t have the proper permissions, for example)
strPasswordUse this value to enter a password that might be required to map the remote drive

Here’s an example:

Set objWshNetwork = WScript.CreateObject("WScript.Network")
objWshNetwork.MapNetworkDrive "Z:", "\\ZEUS\SharedDocs"

To remove a mapped network drive, use the WshNetwork object’s RemoveNetworkDrive:

WshNetwork.RemoveNetworkDrive strName, [bForce], [bUpdateProfile]

WshNetworkThe WshNetwork object.
strNameThe name of the mapped network drive you want removed. If you use a network path, all mappings to that path are removed; if you use a local drive letter, only that mapping is removed.
bForceIf True, the resource is removed even if it is currently being used.
bUpdateProfileIf True, the network drive mapping is removed from the user’s profile.

Here’s an example:

Set objWshNetwork = WScript.CreateObject("WScript.Network")
objWshNetwork.RemoveNetworkDrive "Z:"
Other  
 
Top 10
Free Mobile And Desktop Apps For Accessing Restricted Websites
MASERATI QUATTROPORTE; DIESEL : Lure of Italian limos
TOYOTA CAMRY 2; 2.5 : Camry now more comely
KIA SORENTO 2.2CRDi : Fuel-sipping slugger
How To Setup, Password Protect & Encrypt Wireless Internet Connection
Emulate And Run iPad Apps On Windows, Mac OS X & Linux With iPadian
Backup & Restore Game Progress From Any Game With SaveGameProgress
Generate A Facebook Timeline Cover Using A Free App
New App for Women ‘Remix’ Offers Fashion Advice & Style Tips
SG50 Ferrari F12berlinetta : Prancing Horse for Lion City's 50th
- Messages forwarded by Outlook rule go nowhere
- Create and Deploy Windows 7 Image
- How do I check to see if my exchange 2003 is an open relay? (not using a open relay tester tool online, but on the console)
- Creating and using an unencrypted cookie in ASP.NET
- Directories
- Poor Performance on Sharepoint 2010 Server
- SBS 2008 ~ The e-mail alias already exists...
- Public to Private IP - DNS Changes
- Send Email from Winform application
- How to create a .mdb file from ms sql server database.......
programming4us programming4us
programming4us
 
 
programming4us