| | |
Accessing network share programmatically
![]() |
•
•
Join Date: Jun 2005
Posts: 6
Reputation:
Solved Threads: 0
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
What I need to be able to do is check for existance of files, change their names and open them in notepad
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...
http://visualbasic.ittoolbox.com/doc...ent.asp?i=2938
Let me know what you come up with...
•
•
Join Date: Jun 2005
Posts: 6
Reputation:
Solved Threads: 0
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
Any ideas would help
•
•
Join Date: May 2005
Posts: 41
Reputation:
Solved Threads: 0
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.
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
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)
function ConnectDrive(_drvLetter: String; _netPath: String; _password: String; _username: String; _showError: Boolean; _reconnect: Boolean; _interactive: Boolean): DWORD; var nRes :TNetResource; dwFlags :DWORD; errCode :DWORD; begin FillChar(NRes,SizeOf(NRes),#0); nRes.dwType:=RESOURCETYPE_DISK; nRes.lpLocalName:=PChar(_drvLetter); nRes.lpRemoteName:=PChar(_netPath); nRes.dwScope:=RESOURCE_GLOBALNET; dwFlags:=0; If _reconnect then dwFlags:=CONNECT_UPDATE_PROFILE; If _reconnect and _interactive then dwFlags:=CONNECT_UPDATE_PROFILE and CONNECT_INTERACTIVE; Result:=WNetAddConnection3(form1.Handle,nRes,PChar(_password),PChar(_username),dwFlags); end; function DisConnectDrive(_drvLetter: String; _showError: Boolean; _force: Boolean; _save: Boolean): DWORD; var nRes :TNetResource; dwFlags :DWORD; errCode :DWORD; begin if _save then dwFlags:=CONNECT_UPDATE_PROFILE else dwFlags:=0; errCode:=WNetCancelConnection2(PChar(_drvLetter),dwFlags,_force); if (errCode<>NO_ERROR) and (_showError) then begin Application.MessageBox(PChar(SysErrorMessage(GetLastError)), 'Error Disconnecting Drive', MB_OK); end; Result:=errCode; {NO_ERROR} 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
![]() |
Similar Threads
- Network Share Login As (Windows NT / 2000 / XP)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: I get a Runtime Error 424 when trying to access a file in VB
- Next Thread: plz help
| Thread Tools | Search this Thread |
* 6 2007 access activex add age basic birth bmp calculator cd cells.find click client code connection connectionproblemusingvb6usingoledb creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit excel excelmacro file filename form header iamthwee image inboxinvb internetfiledownload listbox listview liveperson login looping microsoft movingranges objectinsert open oracle password program prompt range-objects readfile reading remotesqlserverdatabase report save search sendbyte sites sql sql2008 sqlserver subroutine tags time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web windows






