Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Values Returned by Win32API With WNetAddConnection
Message
From
19/12/2000 03:10:54
 
 
To
17/12/2000 14:03:38
Peter Wagner
Point Informática Ltda.
Limeira, Brazil
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00454296
Message ID:
00454944
Views:
25
>First: thanks form help
>Second:
>>Declare integer WNetAddConnection in WIN32API string,string,string
>>drive_letter = "G:"
>>Machine_name = "\\boss500\"
>
>>The format of a share is \\MachineName\ShareName - you've omitted the >sharename, so the WNetAddConnection() will inherently fail. You need to >specify both parts of the UNC.
>
>I send MachineName and Drive_letter to the WNetAdConnection()
>and somthing I dont understand happens: Look
>NetWork type: Peer-to-Peer (TCP/IP)
>The system must work with Office(.DOC, .XLS ) and those files are in stored in different computers, 1 computer is Win2K Pro, 2 computers Win98/95
>
>I'm triying to create a connection every time my application starts
>To be sure the application is working with the network.
>So I try to get the network driver mapping and if the station is
>not connected, make the connection.
>
>Got 2 problems:
>
>1) Using WScript, in Win2K pro
>Sometimes this sequence returns 0, even if the network is connected
>
>ONET = CREATEOBJECT("WScript.Network")
>oNetDrives = ONET.EnumNetworkDrives
>x = oNetDrives.COUNT
>? x && Return's 0, why if I open Explorer I see the drives from other Stations.
>
>* shouldnt EnumNetworkDrives return the current network drive mappings ??
>* Also don't get the CD player from each Station

The CD drive is a local resource - it won't be listed. The network drive enumeration has two items per network drive, 0-indexed. The even-numbered item is the local device name - the drive letter associated with the share. The odd numbered entry is UNC mapped to the local resource. With one network drive mapped on this Win2K station to my Win98 machine';s C: drive, the entries are as follows:

? oNetDrives.Count && 2 - one drive lettr mapped
? oNetDrives.Item(0) && "Z:" - the drive letter mapped to the share
? oNetDrives.Item(1) && "\\Ed98\ME-C" - the ME-C share on the machine \\Ed98

To map the drive, I'd give the command:

oNet.MapNetworkDrive("Z:","\\Ed98\ME-C") && maps Z: to the ME-C share on \\Ed98

The share name - the part following the single "\" has nothing to do with the drive letter associated on the system mapping the drive. If I had a share named "D" on my "\\Ed98" sysatem, and I wanted to map it to my F: drive, I'd give the command:

oNet.MapNetworkDrive("F:","\\Ed98\D")

A given share can be mapped to any local device, regardless of what drive letter or share name it is associated with on the sharing machine. If I wanted to map the same drive to "D:", I'd give the command:

oNet.MapNetworkDrive("D:","\\Ed98\D")

Just because a share name is assocaited with a letter on the sharing machine, it has nothing to do with how it's mapped on the client system. Share names do not have to be given the one letter abbreviation that matches the local device name on the server; Windows if left on its own map suggest that as a share name but you are not required to use it. I normally give a longer share name to a given share; you can map a subdirectory, or asocaite several share names with the same folder, with the intent of giving different privieleges based on shich share is accessed. You're fooling yourself into thinking that the second part of the UNC, the share name, has anything at all to do with the drive letter associated on the client. In addition, unless a drive letter is specifically mapped to a given share, it doesn't show up under EnumNetworkDrives - EnumNetworkDrives only tells you what shares are currently assigned to be used by a given system, it does not list all available sharable resources. TO generate that list, download my NETRESOURCE class, which has sample code that will find all shares available on a given network regardless of whether they are currently mapped to the local system.

>
>2)
>DECLARE INTEGER WNetAddConnection IN WIN32API STRING,STRING,STRING
>ONET = CREATEOBJECT("WScript.Network")
>oNetDrives = ONET.EnumNetworkDrives
>FOR lni = 0 TO oNetDrives.COUNT - 1
> ? oNetDrives.ITEM(lni) && Displays the drive mapping
> * this return's those stings from each computer:
> * "\\BOSS700\C" FROM COMPUTER 1
> * "\\BOSS300\G" FROM COMPUTER 3
> * "\\BOSS500\E" FROM COMPUTER 2
> * "\\BOSS500\F" FROM COMPUTER 2
> * "\\BOSS300\I" FROM COMPUTER 2
> * "\\BOSS700\C" FROM COMPUTER 3
> net_drive = oNetDrives.ITEM(lni)
> IF NOT EMPTY(net_drive)
> Machine_name = SUBSTR(net_drive,1, AT("\",net_drive,3))
> DriveLetter = SUBSTR(net_drive,AT("\",net_drive,3)+ 1,1) + ":"
> z=WNetAddConnection(Machine_name, "", DriveLetter)
> ?z
> ENDIF
>NEXT
>
>****
>In computer 1 (win 98)
>z returns 85 -> the device is alredy connected.
>In computer 3 (win 95)
>z returns 85 -> the device is alredy connected.
>In computer 2 (win 2K Pro)
>z returns 67 -> the remote name is not valid or cannot be located
>If I go to the Win2K computer (2), open explorer
>I can get Drives from the other Stations (1 & 3)
>
>What im doing wrong here, because Win2k allways returns error 67
>Exist a better way to get the information e create the connection ??
>
>Thanks in Advance
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform