Click to See Complete Forum and Search --> : Shell ("net use " )


buligi
04-13-2006, 06:55 AM
Hi to all.

I need to map a drive on the net with vb6

I'm using the command

Shell ("net use 192.168.254.254 /USER:administrator ")

but the password is blank

Using this shell the command line responds to enter a valid password, and if I press the enter key the drive is mapped correctly

How do can I pass the password?

thank You in advance for any help.

Buligi

Sync
04-13-2006, 08:07 AM
The syntax of this command is:

NET USE
[devicename | *] [\\computername\sharename[\volume] [password | *]]
[/USER:[domainname\]username]

[/USER:[dotted domain name\]username]
[/USER:[username@dotted domain name]
[/SMARTCARD]
[/SAVECRED]
[[/DELETE] | [/PERSISTENT:{YES | NO}]]

NET USE {devicename | *} [password | *] /HOME

NET USE [/PERSISTENT:{YES | NO}]


or

Class Name : NetworkServices


Private Type NETRESOURCE
dwScope As Long
dwType As Long
dwDisplayType As Long
dwUsage As Long
lpLocalName As String
lpRemoteName As String
lpComment As String
lpProvider As String
End Type

Private Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (lpNetResource As NETRESOURCE, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Long) As Long
Private Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags As Long, ByVal fForce As Long) As Long
Private Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" (ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long


Public Function UserName(Optional strLocalPath As String = "")

Dim strBuffer As String * 255
Dim lngReturn As Long

lngReturn = WNetGetUser(strLocalPath, strBuffer, 255)
UserName = Trim(strBuffer)

If lngReturn <> 0 Then
Err.Raise vbObjectError, "NetworkServices.UserName", _
"Error #" & lngReturn & " occurred during request."
End If


End Function

Public Sub DropConnection(strLocalPath As String, Optional blnForce As Boolean = False)

Dim lngReturn As Long

lngReturn = WNetCancelConnection2(strLocalPath, 0, blnForce)

If lngReturn <> 0 Then
Err.Raise vbObjectError, "NetworkServices.DropConnection", "Error #" & lngReturn & " occurred during connection drop."
End If

End Sub


Public Sub AddConnection(strLocalPath As String, strNetworkPath As String, _
Optional strUserName As String = "", Optional strPassword As String = "")

Dim typNet As NETRESOURCE
Dim lngReturn As Long

With typNet
.dwType = RESOURCETYPE_DISK
.lpLocalName = strLocalPath
.lpRemoteName = strNetworkPath
.lpProvider = ""
End With

lngReturn = WNetAddConnection2(typNet, strPassword, strUserName, 0)

If lngReturn <> 0 Then
Err.Raise vbObjectError, "NetworkServices.AddConnection", "Error #" & lngReturn & " occurred during connection."
End If

End Sub



usage:

Dim objNet As NetworkServices

Set objNet = New NetworkServices
objNet.AddConnection "F:", "\\Server\C$", "domainname\usr", ""
MsgBox objNet.UserName
''objNet.DropConnection "F:"

Building a Network Service Object
http://www.devx.com/getHelpOn/10MinuteSolution/20405
Map a network drive
http://www.vb-helper.com/howto_map_network_drive.html

[code]
Set objNetwork = CreateObject("WScript.Network")
strDriveLetter = "DriveLetter:"
strHomeServer = "\\server\share"
objNetwork.MapNetworkDrive strDriveLetter, strHomeServer
[code]

http://207.150.176.83/archive/index.php?t-45632.html
http://www.vbforums.com/showthread.php?p=2425036#post2425036


Try.. Hope it works.....