Thanks Artion and styno for your help.
The "net use * /delete /y" command did work, but it takes around 10s or 15s to work properly. So, if you close your connection, use the command and someone else access the share in less than that, it will access with the last user used.
So, I solved it with a VBS script. Turning off the navigation of the share, it will be accessed only by the script:
Code:
Set oShell = CreateObject("WScript.Shell")
Set myFile = CreateObject("Scripting.FileSystemObject")
Set msgWait = WScript.CreateObject("WScript.Shell")
Dim count
oShell.Run "net use \\storage /delete /y"
oShell.Run "net use * /delete /y"
oShell.Run "net use /persistent:no"
Set readFile = myFile.OpenTextFile("C:\Storage\log.txt")
OldUser = readFile.ReadLine
UserName = InputBox ("Digite seu usuário:", "ACESSO À REDE")
If (UserName <> "") Then
If (OldUser <> UserName) Then
dteWait = DateAdd("s", 10, Now())
count = 10
Do Until (Now() > dteWait)
msgWait.Popup "AGUARDE " & count & " SEGUNDO, ENQUANTO O ÚLTIMO USUÁRIO É DESCONECTADO", 1, "ACESSO À REDE", 0
count = count -1
Loop
msgBox ("USUÁRIO DESCONECTADO" & WScript.Sleep(1000))
End If
UserPass = InputBox ("Digite sua senha:", "ACESSO À REDE")
If (UserPass <> "") Then
WScript.Sleep 1000
Set writeFile = myFile.OpenTextFile("C:\Storage\log.txt", 2)
writeFile.WriteLine(UserName)
writeFile.WriteLine(UserPass)
writeFile.close()
oShell.Run "net use \\storage " & UserPass & " /user:" & UserName
oShell.Run "C:\Windows\Explorer.exe \\storage\"
oShell.Run "net use \\storage /delete /y"
oShell.Run "net use * /delete /y"
End If
End If
Long story short, it copies the last user into the "log.txt", and uses it to know if the new access is from a new user or the same user.
If it`s from a new user, it will wait at least 10 seconds to try to connect. Enought time to "net use * /delete /y" to work.
;)