PDA

Click to See Complete Forum and Search --> : q on vb and nt command net use


MrDanG
Jan 11th, 2000, 02:24 AM
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
thisismewith@yahoo.com

Aaron Young
Jan 11th, 2000, 03:01 AM
Try using the VB Shell Function, ie.

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
aarony@redwingsoftware.com
ajyoung@pressenter.com

MrDanG
Jan 11th, 2000, 07:49 PM
Aaron,

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

Dan Griffis