Click here to Skip to main content
16,020,519 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Navigating folders in listview. Pin
GeekyGirlPanacea17-Sep-15 16:17
GeekyGirlPanacea17-Sep-15 16:17 
QuestionVisual Basic program to recursively take ownership of a folder and all its sub-contents Pin
Member 1186689316-Sep-15 7:15
Member 1186689316-Sep-15 7:15 
AnswerRe: Visual Basic program to recursively take ownership of a folder and all its sub-contents Pin
Wendelius16-Sep-15 7:44
mentorWendelius16-Sep-15 7:44 
GeneralRe: Visual Basic program to recursively take ownership of a folder and all its sub-contents Pin
Member 1186689316-Sep-15 7:58
Member 1186689316-Sep-15 7:58 
GeneralRe: Visual Basic program to recursively take ownership of a folder and all its sub-contents Pin
Wendelius16-Sep-15 8:53
mentorWendelius16-Sep-15 8:53 
GeneralRe: Visual Basic program to recursively take ownership of a folder and all its sub-contents Pin
Member 1186689316-Sep-15 10:10
Member 1186689316-Sep-15 10:10 
AnswerRe: Visual Basic program to recursively take ownership of a folder and all its sub-contents Pin
Wendelius16-Sep-15 17:05
mentorWendelius16-Sep-15 17:05 
GeneralRe: Visual Basic program to recursively take ownership of a folder and all its sub-contents Pin
Member 1186689317-Sep-15 11:13
Member 1186689317-Sep-15 11:13 
Mika thank you so much for helping with this tool. Your suggestion was the difference. I was able to take ownership of only the parent directory at first. So I decided to try and implement recursive permissions first. I got that to work right away. So I put that piece of code at the of the same sub routine that I called the change of ownership and it worked on the first try after permissions were applied. I had ownership of every sub-directory and full control permissions. I have a few more tasks to implement but this was the major obstacle. Once again thank you very much.Thumbs Up | :thumbsup:

Here is the code for the whole thing. Some of it is generated by visual studio express. I also used several examples I found on the internet and molded them into what I needed.
'CSC TAKE OWNERSHIP AND DATA RECOVERY TOOL
'This tools will recursively take ownership of the c:\windows\csc folder. Then copy the affected users
'folder and backup their user profile to a network share then remove all the folders under c:\windows\csc\v2.06\namespace and delete all user profiles.

Imports System.IO
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Security.AccessControl
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private components As System.ComponentModel.IContainer
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents FolderBrowserDialog1 As System.Windows.Forms.FolderBrowserDialog
Friend WithEvents folderName As System.Windows.Forms.TextBox
Friend WithEvents tbUserName As System.Windows.Forms.TextBox
Friend WithEvents bnBrowseFolder As System.Windows.Forms.Button
Friend WithEvents bnDoit As System.Windows.Forms.Button
Friend WithEvents bnQuit As System.Windows.Forms.Button
Friend WithEvents Label2 As Label
Friend WithEvents PictureBox1 As PictureBox
Friend WithEvents Label3 As Label
Friend WithEvents LinkLabel1 As LinkLabel
Friend WithEvents Label4 As System.Windows.Forms.Label
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
Me.folderName = New System.Windows.Forms.TextBox()
Me.tbUserName = New System.Windows.Forms.TextBox()
Me.bnBrowseFolder = New System.Windows.Forms.Button()
Me.Label1 = New System.Windows.Forms.Label()
Me.bnDoit = New System.Windows.Forms.Button()
Me.bnQuit = New System.Windows.Forms.Button()
Me.FolderBrowserDialog1 = New System.Windows.Forms.FolderBrowserDialog()
Me.Label4 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.PictureBox1 = New System.Windows.Forms.PictureBox()
Me.Label3 = New System.Windows.Forms.Label()
Me.LinkLabel1 = New System.Windows.Forms.LinkLabel()
CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'folderName
'
Me.folderName.Location = New System.Drawing.Point(203, 366)
Me.folderName.Name = "folderName"
Me.folderName.Size = New System.Drawing.Size(304, 20)
Me.folderName.TabIndex = 0
'
'tbUserName
'
Me.tbUserName.Location = New System.Drawing.Point(203, 410)
Me.tbUserName.Name = "tbUserName"
Me.tbUserName.Size = New System.Drawing.Size(256, 20)
Me.tbUserName.TabIndex = 11
'
'bnBrowseFolder
'
Me.bnBrowseFolder.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.bnBrowseFolder.Location = New System.Drawing.Point(519, 368)
Me.bnBrowseFolder.Name = "bnBrowseFolder"
Me.bnBrowseFolder.Size = New System.Drawing.Size(71, 19)
Me.bnBrowseFolder.TabIndex = 1
Me.bnBrowseFolder.Text = "Browse..."
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(115, 363)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(88, 24)
Me.Label1.TabIndex = 2
Me.Label1.Text = "Folder Name:"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'bnDoit
'
Me.bnDoit.Location = New System.Drawing.Point(131, 479)
Me.bnDoit.Name = "bnDoit"
Me.bnDoit.Size = New System.Drawing.Size(72, 48)
Me.bnDoit.TabIndex = 6
Me.bnDoit.Text = "Take Ownership"
'
'bnQuit
'
Me.bnQuit.Location = New System.Drawing.Point(255, 479)
Me.bnQuit.Name = "bnQuit"
Me.bnQuit.Size = New System.Drawing.Size(56, 48)
Me.bnQuit.TabIndex = 7
Me.bnQuit.Text = "Quit"
'
'FolderBrowserDialog1
'
Me.FolderBrowserDialog1.Description = "Select the directory that you want to use As the default."
Me.FolderBrowserDialog1.RootFolder = System.Environment.SpecialFolder.Windows
Me.FolderBrowserDialog1.ShowNewFolderButton = False
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(109, 406)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(88, 24)
Me.Label4.TabIndex = 12
Me.Label4.Text = "User Name: "
Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Font = New System.Drawing.Font("Verdana", 21.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label2.Location = New System.Drawing.Point(125, 147)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(465, 35)
Me.Label2.TabIndex = 13
Me.Label2.Text = "SDE CSC FOLDER OWNERSHIP"
'
'PictureBox1
'
Me.PictureBox1.Image = Global.ChangeOwner.My.Resources.Resources.SDELogo_1_9_14
Me.PictureBox1.Location = New System.Drawing.Point(11, 12)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(255, 105)
Me.PictureBox1.TabIndex = 14
Me.PictureBox1.TabStop = False
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.Font = New System.Drawing.Font("Verdana", 21.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label3.Location = New System.Drawing.Point(146, 182)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(426, 35)
Me.Label3.TabIndex = 15
Me.Label3.Text = "AND DATA RECOVERY TOOL"
'
'LinkLabel1
'
Me.LinkLabel1.AutoSize = True
Me.LinkLabel1.LinkBehavior = System.Windows.Forms.LinkBehavior.NeverUnderline
Me.LinkLabel1.Location = New System.Drawing.Point(56, 235)
Me.LinkLabel1.Name = "LinkLabel1"
Me.LinkLabel1.Size = New System.Drawing.Size(616, 78)
Me.LinkLabel1.TabIndex = 16
Me.LinkLabel1.TabStop = True
Me.LinkLabel1.Text = resources.GetString("LinkLabel1.Text")
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(734, 862)
Me.Controls.Add(Me.LinkLabel1)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.PictureBox1)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.bnQuit)
Me.Controls.Add(Me.bnDoit)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.bnBrowseFolder)
Me.Controls.Add(Me.folderName)
Me.Controls.Add(Me.tbUserName)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.Name = "Form1"
Me.Text = "Change Owner"
CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
Me.PerformLayout()

End Sub

#End Region
Private Sub bnBrowseFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnBrowseFolder.Click
If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then

Me.folderName.Text = FolderBrowserDialog1.SelectedPath
End If
End Sub
Private Sub bnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnQuit.Click
Me.Close()
End Sub

Sub HandleDir(directory As String, userName As String)
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
System.Diagnostics.Debug.WriteLine(exception.Message)
End Try
End Sub
Private Sub bnDoit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnDoit.Click
Dim strPath As String
Dim strUser As String
If tbUserName.Text = "" Then
MsgBox("Please type your NMEA account name (eg. domain\administratoraccount)", MsgBoxStyle.Exclamation)
Exit Sub
End If

strPath = folderName.Text
strUser = tbUserName.Text

Try
'ChangeOwner(strPath, strUser)
HandleDir(Me.folderName.Text, strUser)
Catch ex As Exception
MsgBox("Error: " & ex.Message, MsgBoxStyle.Critical)
Exit Sub
End Try
Dim dInfo As New DirectoryInfo(strPath)
Dim dSecInfo As DirectorySecurity = dInfo.GetAccessControl(AccessControlSections.All)
Dim myRuleValue As Integer = 0

myRuleValue = FileSystemRights.FullControl 'Add your wanted Access here
Dim myRule As New FileSystemAccessRule(strUser, myRuleValue, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit Or InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow)

dSecInfo.AddAccessRule(myRule)
dSecInfo.SetAccessRule(myRule)
dInfo.SetAccessControl(dSecInfo)
MessageBox.Show("Finished!")
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Text = "SDE CSC FOLDER OWNERSHIP AND DATA RECOVERY TOOL"
Me.BackColor = Color.LightSteelBlue
Me.Size = New Size(750, 900)
Me.Location = New Point(100, 40)
Me.MaximizeBox = False
End Sub
End Class
GeneralRe: Visual Basic program to recursively take ownership of a folder and all its sub-contents Pin
Wendelius18-Sep-15 22:47
mentorWendelius18-Sep-15 22:47 
QuestionAutorun vb program from removable device Pin
Otekpo Emmanuel14-Sep-15 1:34
Otekpo Emmanuel14-Sep-15 1:34 
AnswerRe: Autorun vb program from removable device Pin
Brisingr Aerowing14-Sep-15 2:00
professionalBrisingr Aerowing14-Sep-15 2:00 
AnswerRe: Autorun vb program from removable device Pin
Dave Kreskowiak14-Sep-15 2:25
mveDave Kreskowiak14-Sep-15 2:25 
AnswerRe: Autorun vb program from removable device Pin
Tim Carmichael14-Sep-15 2:31
Tim Carmichael14-Sep-15 2:31 
QuestionHow Can I Remove Duplicate Item From Combobox With Datasource? Pin
Member 1051522510-Sep-15 2:55
professionalMember 1051522510-Sep-15 2:55 
AnswerRe: How Can I Remove Duplicate Item From Combobox With Datasource? Pin
Dave Kreskowiak11-Sep-15 3:41
mveDave Kreskowiak11-Sep-15 3:41 
Questionasking for source code of visual basic 6.0 Pin
Member 119717979-Sep-15 6:19
Member 119717979-Sep-15 6:19 
AnswerRe: asking for source code of visual basic 6.0 Pin
Richard MacCutchan9-Sep-15 6:23
mveRichard MacCutchan9-Sep-15 6:23 
AnswerRe: asking for source code of visual basic 6.0 Pin
Dave Kreskowiak9-Sep-15 7:03
mveDave Kreskowiak9-Sep-15 7:03 
QuestionRe: asking for source code of visual basic 6.0 Pin
Paul Conrad13-Sep-15 6:08
professionalPaul Conrad13-Sep-15 6:08 
AnswerRe: asking for source code of visual basic 6.0 Pin
RizalAziz16-Sep-15 19:11
RizalAziz16-Sep-15 19:11 
NewsRe: asking for source code of visual basic 6.0 Pin
Eddy Vluggen16-Sep-15 23:00
professionalEddy Vluggen16-Sep-15 23:00 
AnswerRe: asking for source code of visual basic 6.0 Pin
Otekpo Emmanuel28-Sep-15 17:36
Otekpo Emmanuel28-Sep-15 17:36 
Questionhow to receive SMS via USB Modem with SIM Card ? Pin
saedawke9-Sep-15 3:08
saedawke9-Sep-15 3:08 
AnswerRe: how to receive SMS via USB Modem with SIM Card ? Pin
Eddy Vluggen9-Sep-15 3:39
professionalEddy Vluggen9-Sep-15 3:39 
QuestionVB Code to perform an action, when user selects a particular cell in MS Excel Pin
Razanust8-Sep-15 18:00
Razanust8-Sep-15 18:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.