Click here to Skip to main content
15,896,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I establish and save a connection in Windows7 command line to my work network shared folder?
Posted
Updated 7-Oct-11 15:40pm

Use the following :
net use p: \\servername\sharename /persistant:yes


Where p: is the drive letter you want to map to.
 
Share this answer
 
Source of the problem:
I am using a Microsoft Access DB for the data store in my application.
The application requires a small group of clients to access(RD/WR) the database.
The clients are within a local network.
The set is so that there is a server machine on which the database file (ie database.accdb) is stored.
I am using the Microsoft.ACE.OLEDB.12.0 Provider! the provider does not have functionality of servicing http urls! (so the data source=http://host/ is not allowed).
The ACE provider can only access the database file within local paths.
So i was required to map the drive(the server HDD) on which my database is living.
another condition is that all machines must be on the same network(ie, homegroup or work).
A Solution:
1)map the drive automatically and assign a drive name such as X:, Z:, R:!
2)have all the client machines to be connected to the same network (i,e Work network)
3)use a a batch file and start a process on application load.
So what is in the batch file?
4) the HDD of the server must be shared!
it is possible to map a drive and log on to it using the follwing command

net use X: \\192.168.1.X\sharename {password} /USER:username /P:yes


explanations of the above:
net use
is the command to connect to a local drive
X:
this can be any letter followed by a semi colon. as long as the machine on which the batch is being run does not have this drive letter in use!
\\ip
this is the static ip of the server or can be the machine name(windows machine name)
\share-name
this is the name of the location being shared on the server machine. user who sets up sharing will assign this name
{password}
the complete highlighted term (ie including the braces) is the password to the server machine
/USER:username
the username is replaced by the user name of the server machine.
/P:yes
this means that this connection is persistent. this will keep the connection live for the duration of which the client machine is on and will disconnect with a reboot!.

further details:
By having the batch file to run with a command such as this in VB.net
process.start("C:\folder\connect.bat")
on the event of application load
we can cheat our way of logging in to the server and gain access to the database file. but of course one should keep track of the path to the database dynamically.(i will not get into the ways here!)
 
Share this answer
 
Comments
Member 9346617 5-Apr-19 7:08am    
I have the similar challenge. I want to access the shared folder and need to display files within that shared folder which are older than 4 days.
But I can't use net use X: \\192.168.1.X\sharename {password} /USER:username /P:yes command since I can't pass username and password of production server.
Any help is much appreciated.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900