Question

I have two computers in a Windows Domain.
One of them runs an application that accesses network shares on the other, as it is authorized via a Domain account. However, in a freshly booted configuration, the access on the shares fails.
The user workaround is to click the share in Windows Explorer and from that time on, it is accessible by the application.
The Windows Command Prompt (cmd) has the same problem: dir s: (s being the shared drive letter) fails until you click the drive in Explorer.
Is there any system call I can invoke to "open" the network share programatically from my application, rather than clicking it in Explorer?
Thx

Was it helpful?

Solution

connecting and reconnecting a network share is somewhat tricky, windows sometimes misses to restore connections from laptops roaming from one net to another.

I use this little strategy in some of my BAT files...

IF NOT EXIST s:\NUL (
   NET USE s: /D
   NET USE s: \\computername\sharename
)

if the current user name exists and have the same password in the domain or in the server, or if the client domain is in the trust list of the domain controller, access is allowed. If not, you will need to specify the username in the command and will be prompted for the password (specifying the password in the BAT file is a very bad idea)

NET USE s: \\computername\sharename /USER:username *

see http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/net_use.mspx?mfr=true for more information

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top