Results 1 to 3 of 3

Thread: q on vb and nt command net use

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 1999
    Location
    Atlanta, GA, USA
    Posts
    3

    Post

    I am in the middle of writing a simple program that logs on to a specific dir on a server allows the user to do what he/she needs to do in their private folder then allows them to log off. I got the log in process down, but I am having serious problem with the log off portion. Here is what I have so far:

    'Put this in a module this is needed for the shell executable command.

    Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

    'Now this is the form code.
    Private Sub Command1_Click()

    Dim strTmpText As String

    strTmpText = " use z: \\ServerName\FolderName Passwd /user:UserName"

    Dim lReturn As Long
    lReturn = ShellExecute(hWnd, "open", "net.exe", strTmpText, vbNull, 0)

    Unload Me

    End Sub

    The above works great, but when I try logging off later in the code or try logging off as a total separate program I can't do it. Here's the code I am trying to use:

    ‘I need the same BAS file as above to access the same shell execute command
    ‘This is in a new project / program
    Private Sub Command1_Click()

    Dim strTmpText As String

    strTmpText = " use /delete z:"

    Dim lReturn As Long
    lReturn = ShellExecute(hWnd, "open", "net.exe", strTmpText, vbNull, 0)

    Unload Me

    End Sub

    The error message I get is 'The device is being accessed by an active process'. This tells me that VB is accessing the drive. I can also prove the VB is doing the accessing. I can not manually type in the net use /delete z: command while the VB program is running, but I can do it as soon as I close the program. So, VB is the active process and nothing else. Why should one total separate program be accessing the same drive? I did try and put in a chdir("c:\") in front of the /delete z: command to make sure that VB didn't have the selected/active drive as the z drive, but it didn't help any.

    I could run a batch file that the user could click on to log off, but I am just trying to understand the problem. Also, I would like to integrate the two programs back into one single program (as I originally had them). Any insights or info on this problem would be greatly appreciated! Thanks for your time.

    Dan Griffis
    [email protected]

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Try using the VB Shell Function, ie.
    Code:
    Private Sub cmdConnect_Click()
        Shell "NET USE Z: \\SERVER\C$ PASSWORD /USER:USERNAME"
    End Sub
    
    Private Sub cmdDisconnect_Click()
        Shell "NET USE Z: /DELETE"
    End Sub
    This worked for me.

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]


  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 1999
    Location
    Atlanta, GA, USA
    Posts
    3

    Post

    Aaron,

    Yeap, that worked like a charm! Thanks for your help.

    Dan Griffis

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width