Accessing network share programmatically

Reply

Join Date: Jun 2005
Posts: 6
Reputation: craigmckeeman is an unknown quantity at this point 
Solved Threads: 0
craigmckeeman craigmckeeman is offline Offline
Newbie Poster

Accessing network share programmatically

 
0
  #1
Jun 21st, 2005
I have inherited an application that requires access to a network share, which mean the PC has to have a mapped drive before access can be gained (user and password required). Is it possible to gain access programmatically?
What I need to be able to do is check for existance of files, change their names and open them in notepad
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Accessing network share programmatically

 
0
  #2
Jun 21st, 2005
Quite Possibly by using VBScript, Embeded into a VB6 application, you can simply map the drive.... this page gives you a pretty good idea as to use VBScript to map the drive:
http://visualbasic.ittoolbox.com/doc...ent.asp?i=2938

Let me know what you come up with...
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 6
Reputation: craigmckeeman is an unknown quantity at this point 
Solved Threads: 0
craigmckeeman craigmckeeman is offline Offline
Newbie Poster

Re: Accessing network share programmatically

 
0
  #3
Jun 22nd, 2005
Thanks for the suggestion but I have already done simular using NetShareAdd to map a drive. What I am really looking for is something like a 'virtual' connection that does not create a physical mapping but enables me to see and change file names on a server within the application. At the moment the user has to map a drive using user/password before the application works and I want the application to have a configuration option to enable changing connection, this will avoid logging in every morning. At present the application is hard coded to get details from the server using UNC (\\server\path)

Any ideas would help
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Accessing network share programmatically

 
0
  #4
Jun 22nd, 2005
well, the only thing I can think that would be helpful would be to create a server app that sits on the computer.... then, when you connect, have the server send the client app any information that you would like, and process it accordingly....
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 6
Reputation: craigmckeeman is an unknown quantity at this point 
Solved Threads: 0
craigmckeeman craigmckeeman is offline Offline
Newbie Poster

Re: Accessing network share programmatically

 
0
  #5
Jun 23rd, 2005
Yes I had thought of that but it seemed a bit elaborate, I was hoping for an easier way. It looks like I will just have to continue mapping a drive, possibly programmatically.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Accessing network share programmatically

 
0
  #6
Jun 23rd, 2005
Why not code a server? It's not too difficult to do, I have even posted in a previous post a skeleton server that you can use, and it will simply creation of sockets and what not a whole lot. All you have to do is build the transactions between the server and client....
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 41
Reputation: mrmike is an unknown quantity at this point 
Solved Threads: 0
mrmike mrmike is offline Offline
Light Poster

Re: Accessing network share programmatically

 
0
  #7
Jun 24th, 2005
i've never done this under VB but did write a routine that could map drives under delphi.

the following code is how it works under delphi, you could see if can change to work with VB.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. function ConnectDrive(_drvLetter: String; _netPath: String; _password: String; _username: String; _showError: Boolean; _reconnect: Boolean; _interactive: Boolean): DWORD;
  2. var
  3. nRes :TNetResource;
  4. dwFlags :DWORD;
  5. errCode :DWORD;
  6. begin
  7. FillChar(NRes,SizeOf(NRes),#0);
  8. nRes.dwType:=RESOURCETYPE_DISK;
  9. nRes.lpLocalName:=PChar(_drvLetter);
  10. nRes.lpRemoteName:=PChar(_netPath);
  11. nRes.dwScope:=RESOURCE_GLOBALNET;
  12. dwFlags:=0;
  13. If _reconnect then dwFlags:=CONNECT_UPDATE_PROFILE;
  14. If _reconnect and _interactive then dwFlags:=CONNECT_UPDATE_PROFILE and CONNECT_INTERACTIVE;
  15. Result:=WNetAddConnection3(form1.Handle,nRes,PChar(_password),PChar(_username),dwFlags);
  16. end;
  17.  
  18. function DisConnectDrive(_drvLetter: String; _showError: Boolean; _force: Boolean; _save: Boolean): DWORD;
  19. var
  20. nRes :TNetResource;
  21. dwFlags :DWORD;
  22. errCode :DWORD;
  23. begin
  24. if _save then
  25. dwFlags:=CONNECT_UPDATE_PROFILE
  26. else
  27. dwFlags:=0;
  28. errCode:=WNetCancelConnection2(PChar(_drvLetter),dwFlags,_force);
  29. if (errCode<>NO_ERROR) and (_showError) then
  30. begin
  31. Application.MessageBox(PChar(SysErrorMessage(GetLastError)),
  32. 'Error Disconnecting Drive',
  33. MB_OK);
  34. end;
  35. Result:=errCode; {NO_ERROR}
  36. end;

You could have a couple of text inputs on the form, with a command button. When clicking on this after filling the info in, you could connect the drive. When the program closes you could get it to call the disconnect feature to ensure properly disconnected.

If need further help, I'll try to get it converted to a VB app, but due to workload can be sometime before I get it done.

Good Luck

Mike
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Accessing network share programmatically

 
0
  #8
Jun 24th, 2005
appreciate all the help we can get on this mrmike, but let's try to keep delphi in the delphi forum. Thanx.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 41
Reputation: mrmike is an unknown quantity at this point 
Solved Threads: 0
mrmike mrmike is offline Offline
Light Poster

Re: Accessing network share programmatically

 
0
  #9
Jun 27th, 2005
Sorry comatose,

thought if shown the delphi code, may have been able to convert it to vb code.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC