|
-
Nov 16th, 2006, 03:47 AM
#1
Thread Starter
Member
Password for folder
VB Code:
If Dir(Infile) = "" Then 'Checking scanhold.dat exists or not
Msg = Infile & " does not exist."
Else
Mydate = Format(Date, "YYMMDD")
Mytime = Format(Time, "HHMMSS")
NewName = "\\sapt01\KPIINTERFACE\pbl\in\" & PlantName & strPreFix & Mydate & Mytime & ".txt"
Name Infile As NewName 'Cut n paste
'FileCopy Infile, NewName 'copy n paste
Msg = Infile & " has changed name to " & PlantName & strPreFix & Mydate & Mytime & ".txt"
End If
MsgBox Msg
i used this code to copy a file from one destination to other..but the destination folder (\\sapt01\KPIINTERFACE\pbl\in\) need a password to open it. this will cause failed to open path in my program. how to set a password to open a locked folder?
-
Nov 16th, 2006, 06:25 AM
#2
Lively Member
Re: Password for folder
Connect to the UNC Path, using "NEt Use" command, (Map the folder to a Driveletter), do the filecopy and then disconnect the Drive.
Here's the link for "Net Use " USAGE
http://www.ss64.com/nt/net_use.html
IBM poster explaining virtual memory 1978
If it's there and you can see it--it's real
If it's not there and you can see it--it's virtual
If it's there and you can't see it--it's transparent
If it's not there and you can't see it--you erased it!
-
Nov 21st, 2006, 08:12 PM
#3
Thread Starter
Member
Re: Password for folder
is there are other method than this one?
-
Nov 21st, 2006, 08:45 PM
#4
Thread Starter
Member
Re: Password for folder
 Originally Posted by aruns1978
Connect to the UNC Path, using "NEt Use" command, (Map the folder to a Driveletter), do the filecopy and then disconnect the Drive.
Here's the link for "Net Use " USAGE
http://www.ss64.com/nt/net_use.html
can someone show me example of code in how to using this method..
-
Nov 21st, 2006, 10:46 PM
#5
Thread Starter
Member
Re: Password for folder
i hope i can use back my code and just add some extra code to open the protected file..
-
Nov 22nd, 2006, 08:00 PM
#6
Thread Starter
Member
Re: Password for folder
 Originally Posted by aruns1978
Connect to the UNC Path, using "NEt Use" command, (Map the folder to a Driveletter), do the filecopy and then disconnect the Drive.
Here's the link for "Net Use " USAGE
http://www.ss64.com/nt/net_use.html
hello everyone..please help..how to use the use net code in vb? can someone show me the example of code..step by step would be the best..
-
Nov 23rd, 2006, 03:58 AM
#7
Lively Member
Re: Password for folder
Within Visual basic goto Projects ->references and Include
Windows Script host Object model.
And paste the following code ( I have written this in Command1_Click event...
Private Sub Command1_Click()
Dim snet As WshNetwork
Dim strRemotePath As String
Dim strDrive As String
strRemotePath = "\\ServerName\ShareName"
strDrive "P:"
Set snet = CreateObject("Wscript.WshNetwork")
Call snet.MapNetworkDrive(strDrive, strRemotePath, , "USERNAME", "PASSWORD")
' Do your Copy file Stuff here
'End copy file routine
Call snet.RemoveNetworkDrive(strDrive)
End Sub
hope this helps!
IBM poster explaining virtual memory 1978
If it's there and you can see it--it's real
If it's not there and you can see it--it's virtual
If it's there and you can't see it--it's transparent
If it's not there and you can't see it--you erased it!
-
Nov 23rd, 2006, 05:41 AM
#8
Re: Password for folder
Dear Arun,
What will happen, it the drive is alreay mapped.Is there any way avalible to detect it?
Please mark you thread resolved using the Thread Tools as shown
-
Nov 23rd, 2006, 09:10 PM
#9
Thread Starter
Member
Re: Password for folder
Hi arun,
i have follow your method but get a debug error "ActiveX component can't create object" in this line: Set snet = CreateObject("Wscript.WshNetwork")
-
Nov 23rd, 2006, 09:45 PM
#10
Lively Member
Re: Password for folder
hi eject,
did you refernce , the Microsoft Wscript Host in Project->Reference, What is your operating system?
to check whether the drive is already mapped , you can iterate through all drives in "My Computer" and check if its already mapped...
I will post the code for the same shortly..
Cheers
arun S
IBM poster explaining virtual memory 1978
If it's there and you can see it--it's real
If it's not there and you can see it--it's virtual
If it's there and you can't see it--it's transparent
If it's not there and you can't see it--you erased it!
-
Nov 23rd, 2006, 09:49 PM
#11
Thread Starter
Member
Re: Password for folder
yes i did reference the Microsoft Wscript Host in Project->Reference.. but the error still occur
-
Nov 23rd, 2006, 11:45 PM
#12
Lively Member
Re: Password for folder
Try this...
Private Sub Command1_Click()
Dim a As WshNetwork
Set a = New WshNetwork
a.MapNetworkDrive "p:", "\\servername\foldername", , "username", "password"
a.RemoveNetworkDrive "p:"
End Sub
IBM poster explaining virtual memory 1978
If it's there and you can see it--it's real
If it's not there and you can see it--it's virtual
If it's there and you can't see it--it's transparent
If it's not there and you can't see it--you erased it!
-
Nov 24th, 2006, 02:26 AM
#13
Thread Starter
Member
Re: Password for folder
thanks arun..how to check whether the connection failed/succeed or connection already exist
-
Nov 24th, 2006, 03:15 AM
#14
Thread Starter
Member
Re: Password for folder
VB Code:
Private Sub Command1_Click()
Dim ND As WshNetwork
Set ND = New WshNetwork
ND.MapNetworkDrive "H:", "\\bg3matpbl03\c$"
End Sub
Private Sub Command2_Click()
Dim ND As WshNetwork
Set ND = New WshNetwork
ND.RemoveNetworkDrive "H:"
End Sub
Thanks again..my program is running now..
Above is working code..
but i have to put some extra code to check whether the drive is aready exist or maybe the server path is not exist(server down), if disconnect non exist drive..can u help me on this
-
Nov 25th, 2006, 10:47 AM
#15
Lively Member
Re: Password for folder
You can Have some error Trapping like this
Private function mapDrive()
On local error goto mapDrive_Err:
' Your Drive mapping Goes here
mapDrive_Close:
exit Function
mapDrive_Err:
if err.number = 1234 ' Find then error number returned when the server is not reachable and put it here
msgbox "server " & strservername & is not reachable now" & err.description
else if err.number = 2525 ' fin tne error number when the drive is alrady mapped and put it here
msgbox "drive already mapped"
else
msgbox err.description
end if
goto mapDrive_Close:
End function
This should do the trick for you!
IBM poster explaining virtual memory 1978
If it's there and you can see it--it's real
If it's not there and you can see it--it's virtual
If it's there and you can't see it--it's transparent
If it's not there and you can't see it--you erased it!
-
Nov 26th, 2006, 08:56 PM
#16
Thread Starter
Member
Re: Password for folder
Thanks Arun..now solve my problem..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|