|
#1
|
|||
|
|||
|
Shell ("net use " )
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 |
|
#2
|
|||
|
|||
|
Code:
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}]
Class Name : NetworkServices Code:
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
Code:
Dim objNet As NetworkServices Set objNet = New NetworkServices objNet.AddConnection "F:", "\\Server\C$", "domainname\usr", "" MsgBox objNet.UserName ''objNet.DropConnection "F:" 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.....
__________________
Best Regards, Michael Sync http://michaelsync.net The more you share,The more you get Last edited by Sync; 04-13-2006 at 08:10 AM. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Trouble using CALL SHELL() | kevin3306 | VB Classic | 4 | 09-15-2005 07:32 PM |
| Shell Program | none_none | C++ | 13 | 04-19-2005 06:20 PM |
| Shell and Wait Converted to VB.Net - November 2002 Tip of the Month | Larry Rebich | dotnet.announcements | 0 | 10-15-2002 02:20 PM |
| Shell Hook without Shell? | Juergen Thuemmler | VB Classic | 2 | 06-22-2000 11:31 AM |
| Shell Hook without Shell? | Juergen Thuemmler | VB Classic | 0 | 06-22-2000 05:12 AM |