Click here to Skip to main content
15,914,071 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionHOw I can find a sent mail with vba? Pin
Member 1199849020-Sep-15 13:21
Member 1199849020-Sep-15 13:21 
AnswerRe: HOw I can find a sent mail with vba? Pin
Dave Kreskowiak25-Sep-15 14:56
mveDave Kreskowiak25-Sep-15 14:56 
QuestionCan radio buttons have more than 1 function? Pin
Member 1199784020-Sep-15 3:55
Member 1199784020-Sep-15 3:55 
SuggestionRe: Can radio buttons have more than 1 function? Pin
Maciej Los20-Sep-15 5:32
mveMaciej Los20-Sep-15 5:32 
GeneralRe: Can radio buttons have more than 1 function? Pin
Member 1199784020-Sep-15 5:46
Member 1199784020-Sep-15 5:46 
GeneralRe: Can radio buttons have more than 1 function? Pin
Maciej Los20-Sep-15 5:59
mveMaciej Los20-Sep-15 5:59 
QuestionNavigating folders in listview. Pin
GeekyGirlPanacea17-Sep-15 0:29
GeekyGirlPanacea17-Sep-15 0:29 
AnswerRe: Navigating folders in listview. Pin
Brisingr Aerowing17-Sep-15 0:48
professionalBrisingr Aerowing17-Sep-15 0:48 
GeneralRe: Navigating folders in listview. Pin
GeekyGirlPanacea17-Sep-15 1:02
GeekyGirlPanacea17-Sep-15 1:02 
AnswerRe: Navigating folders in listview. Pin
Richard MacCutchan17-Sep-15 0:51
mveRichard MacCutchan17-Sep-15 0:51 
GeneralRe: Navigating folders in listview. Pin
GeekyGirlPanacea17-Sep-15 1:04
GeekyGirlPanacea17-Sep-15 1:04 
GeneralRe: Navigating folders in listview. Pin
Richard MacCutchan17-Sep-15 1:21
mveRichard MacCutchan17-Sep-15 1:21 
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 

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.