Kbase P138385: 4GL/ABL: How to use the Windows Script Host Object Model to access shared resources on the network t
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  12/8/2008 |
|
Status: Unverified
GOAL:
4GL/ABL: How to use the Windows Script Host Object Model to access shared resources on the network to which your computer is connected?
GOAL:
How to use the Windows Shared Network Object (WshNetwork) to access shared resources on the network to which your computer is connected?
GOAL:
How to access the WshNetwork Object properties and call its methods?
GOAL:
How to call the WshNetwork Object EnumPrinterConnections Method to get current network printer mapping information?
GOAL:
How to invoke WshNetwork Object EnumNetworkDrives Method to access current network drive mapping information?
FIX:
The following code demonstrates the use of Windows Script Host Object to access shared network resources.
It uses the Windows Shared Network Object (WshNetwork) to access shared resources on the network to which your computer is connected?
Specifically, it accesses the WshNetwork Object UserDomain, ComputerName and UserName properties to obtain the current User Domain Name, Computer Name and User Name respectively.
It also invokes the WshNetwork Object WshNetwork Object EnumNetworkDrives Method to list the current network drive mapping information and calls the WshNetwork Object EnumPrinterConnections Method to get the current network printer mapping information:
DEFINE VARIABLE chNetwork AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chDrives AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chPrinters AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE iCounter AS INTEGER NO-UNDO.
DEFINE VARIABLE cMessage AS CHARACTER NO-UNDO.
CREATE "WScript.Network" chNetwork.
ASSIGN
chDrives = chNetwork:EnumNetworkDrives
chPrinters = chNetwork:EnumPrinterConnections.
cMessage =
"Domain:~t~t" + chNetwork:UserDomain + "~n" +
"Computer Name:~t" + chNetwork:ComputerName + "~n" +
"User Name:~t" + chNetwork:UserName.
MESSAGE cMessage
VIEW-AS ALERT-BOX INFO BUTTONS OK TITLE "Domain, Computer & User Names".
ASSIGN
cMessage = "".
DO iCounter = 0 TO chDrives:COUNT - 1 BY 2:
ASSIGN
cMessage = cMessage + chDrives:Item(iCounter) + "~t" + chDrives:Item(iCounter + 1) + "~n".
END.
MESSAGE cMessage
VIEW-AS ALERT-BOX INFO BUTTONS OK TITLE "Networked Drives & Mapping Information".
ASSIGN
cMessage = "".
DO iCounter = 0 TO chPrinters:COUNT - 1 BY 2:
ASSIGN
cMessage = cMessage + chPrinters:Item(iCounter) + "~t" + chPrinters:Item(iCounter + 1) + "~n".
END.
MESSAGE cMessage
VIEW-AS ALERT-BOX INFO BUTTONS OK TITLE "Networked Printers Local and UNC Names".
RELEASE OBJECT chDrives.
RELEASE OBJECT chPrinters.
RELEASE OBJECT chNetwork.