1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need help taking ownership of a user profile in vb.net

Discussion in 'Visual Basic ( VB )' started by umphorton, Oct 16, 2015.

  1. umphorton

    umphorton New Member

    Joined:
    Sep 15, 2015
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    I am working on a user profile back up tool to be used before reimaging a computer. Basically I am just backing up the desktop, document, pictures, and favorites. That part of the code is working. It check if the user profile is there and does this:

    My.Computer.FileSystem.CopyDirectory("C:\users\" & struser & "\Desktop", "\\vhabecapp1r\cscbackup\" & struser & "\Profile\Desktop", True)

    The only problem is I need to take ownership of the folder (profile) to do this. I know how to add permissions but I am having issues taking ownership. I used this piece of code before and it worked but in this project the debugger doesn't like it.
    Code:
    Try
                ChangeOwner(directory, userName)
                For Each subdir As String In System.IO.Directory.GetDirectories(directory)
                    HandleDir(subdir, userName)
                Next subdir
            Catch exception As System.Exception
                Debug.WriteLine(exception.Message)
            End Try
    
    
            Try
                HandleDir(Me.folderName.Text, strUser)
            Catch ex As Exception
                MsgBox("Error: " & ex.Message, MsgBoxStyle.Critical)
                Exit Sub
            End Try
    
    The imports are the same on both project. Any idea why this isn't working on the new project?
     
    Last edited by a moderator: Oct 18, 2015

Share This Page