Results 1 to 16 of 16

Thread: Password for folder

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    54

    Password for folder

    VB Code:
    1. If Dir(Infile) = "" Then    'Checking scanhold.dat exists or not
    2.         Msg = Infile & " does not exist."
    3.     Else
    4.         Mydate = Format(Date, "YYMMDD")
    5.         Mytime = Format(Time, "HHMMSS")
    6.         NewName = "\\sapt01\KPIINTERFACE\pbl\in\" & PlantName & strPreFix & Mydate & Mytime & ".txt"
    7.         Name Infile As NewName 'Cut n paste
    8.         'FileCopy Infile, NewName 'copy n paste
    9.         Msg = Infile & " has changed name to " & PlantName & strPreFix & Mydate & Mytime & ".txt"
    10.     End If
    11.     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?

  2. #2
    Lively Member
    Join Date
    Jun 2004
    Location
    INDIA
    Posts
    76

    Lightbulb 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!

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    54

    Re: Password for folder

    is there are other method than this one?

  4. #4

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    54

    Re: Password for folder

    Quote 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..

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    54

    Re: Password for folder

    i hope i can use back my code and just add some extra code to open the protected file..

  6. #6

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    54

    Re: Password for folder

    Quote 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..

  7. #7
    Lively Member
    Join Date
    Jun 2004
    Location
    INDIA
    Posts
    76

    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!

  8. #8
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    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

  9. #9

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    54

    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")

  10. #10
    Lively Member
    Join Date
    Jun 2004
    Location
    INDIA
    Posts
    76

    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!

  11. #11

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    54

    Re: Password for folder

    yes i did reference the Microsoft Wscript Host in Project->Reference.. but the error still occur

  12. #12
    Lively Member
    Join Date
    Jun 2004
    Location
    INDIA
    Posts
    76

    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!

  13. #13

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    54

    Re: Password for folder

    thanks arun..how to check whether the connection failed/succeed or connection already exist

  14. #14

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    54

    Re: Password for folder

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim ND As WshNetwork
    3. Set ND = New WshNetwork
    4. ND.MapNetworkDrive "H:", "\\bg3matpbl03\c$"
    5. End Sub
    6.  
    7.  
    8. Private Sub Command2_Click()
    9. Dim ND As WshNetwork
    10. Set ND = New WshNetwork
    11. ND.RemoveNetworkDrive "H:"
    12. 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

  15. #15
    Lively Member
    Join Date
    Jun 2004
    Location
    INDIA
    Posts
    76

    Cool 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!

  16. #16

    Thread Starter
    Member
    Join Date
    Sep 2006
    Posts
    54

    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
  •  



Click Here to Expand Forum to Full Width