Shell ("net use " )


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Shell ("net use " )

  1. #1
    Join Date
    Oct 2005
    Posts
    8

    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. #2
    Join Date
    Dec 2004
    Posts
    717
    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}]
    or

    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
    usage:
    Code:
    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.....
    Last edited by Sync; 04-13-2006 at 08:10 AM.
    Best Regards,
    Michael Sync
    http://michaelsync.net

    The more you share,The more you get

Similar Threads

  1. Trouble using CALL SHELL()
    By kevin3306 in forum VB Classic
    Replies: 4
    Last Post: 09-15-2005, 07:32 PM
  2. Shell Program
    By none_none in forum C++
    Replies: 13
    Last Post: 04-19-2005, 06:20 PM
  3. Shell and Wait Converted to VB.Net - November 2002 Tip of the Month
    By Larry Rebich in forum dotnet.announcements
    Replies: 0
    Last Post: 10-15-2002, 02:20 PM
  4. Shell Hook without Shell?
    By Juergen Thuemmler in forum VB Classic
    Replies: 2
    Last Post: 06-22-2000, 11:31 AM
  5. Shell Hook without Shell?
    By Juergen Thuemmler in forum VB Classic
    Replies: 0
    Last Post: 06-22-2000, 05:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center