|
I need to create a tool that will recursively take ownership of a folder for our helpdesk team, we logon with admin tokens to perform administrative tasks so anyone who uses this tool will only be IT personnel and will have local admin rights when they logon with their token. Users are losing data because of corrupt file synchronization. The only way we can retrieve it is to take ownership of the c:\windows\csc and its contents. This is a very short explanation of why I need a tool, the story is much longer but this lays out why I started this project. I am new to visual basic and programming.
I wrote a program that will allow you to browse to the folder you want to take ownership of but I can't figure how get all the subdirectories. Can someone please help me make this program work recursively?
Here is the main part of the code and this will take ownership on the parent directory eg. c:\test:
#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
Private Sub bnDoit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnDoit.Click
If tbUserName.Text = "" Then
MsgBox("Please type your NMEA account name (eg. Domain\adminaccountname)", MsgBoxStyle.Exclamation)
Exit Sub
End If
strPath = folderName.Text
For Each Folder In IO.Directory.GetDirectories(strPath, "*", IO.SearchOption.AllDirectories)
Next
strPath = folderName.Text
strUser = tbUserName.Text
Try
ChangeOwner(strPath, strUser)
Catch ex As Exception
MsgBox("Error: " & ex.Message, MsgBoxStyle.Critical)
End Try
MsgBox("Done!")
End Sub
|
|
|
|
|
You would need to create the method in a recursive way but before going to that, wouldn't it be easier to execute takeown using a new process?
In other words something like
Process.Start("takeown /F directoryname /R /A")
For more info, see takeown[^]
|
|
|
|
|
It would be easier but I want to do it this first. Once I get this working I may do two more projects one with Takeown and one using WMI Win32_Directory TakeOwnershipEx Then test all 3 and see which one I like better. Takeown and WMI have been suggested to me but I really want to make this work first.
I have used takeown a lot as well as icacls from the command line.
How would I create the method in a recursive way? I have tried numerous way I have found numerous ways searching the internet but I can't do anything the right way. I even used the WMI Code Creator with elevated privileges and it fails even though I can take ownership of the parent directory with my tool. I am new to programming and I am learning but I need help.
|
|
|
|
|
If you want to create a recursive function you need to loop through the directories and for each directory call the same function again.
Consider the following code:
Sub HandleDir(directory As String)
Try
System.Diagnostics.Debug.WriteLine("I'm in directory " & directory)
For Each subdir As String In System.IO.Directory.GetDirectories(directory)
HandleDir(subdir)
Next subdir
Catch exception As System.Exception
System.Diagnostics.Debug.WriteLine(exception.Message)
End Try
End Sub
You can try that by calling it for example like this
HandleDir("C:\")
That should list all the directories where you have access.
|
|
|
|
|
once I add this how do I connect that with the part of the code that executes the change owner?
Try
ChangeOwner(strPath, strUser)
Catch ex As Exception
MsgBox("Error: " & ex.Message, MsgBoxStyle.Critical)
End Try
Would I change this to?
Subdir = Me.FolderName.Text
Try
System.Diagnostics.Debug.WriteLine("I'm in directory " & directory)
For Each subdir As String In System.IO.Directory.GetDirectories(directory)
ChangeOwner(subdir, strUser)
Next subdir
Catch exception As System.Exception
System.Diagnostics.Debug.WriteLine(exception.Message)
End Try
strpath comes from here:
If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
Me.folderName.Text = FolderBrowserDialog1.SelectedPath
End If
I really appreciate your help by the way.
|
|
|
|
|
Just put the code to change the ownership of a single directory in place of the debug.writeline. Or if you need to set the ownership before entering the directory, then inside the loop. Just remember to pas the user as a parameter
For example
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
And to call
HandleDir(Me.folderName.Text, strUser)
|
|
|
|
|
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.
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
|
|
|
|
|
You're welcome, glad it helped
|
|
|
|
|
Good day friends! I have been surfing the net for some days now but all yield no result. This is what I want; I created autorun file in text file for my vb app and place the app along with the autorun file in the root directory of my flash drive. When I plugged the flash in my pc using win 7 OS, my expectation failed. The program didn't run rather the normal dialog appeared asking what I want to do with the flash. The question is how could I achieve this in win 7 OS? Thanks in advance,
|
|
|
|
|
Windows Vista disabled auto run as it was a security risk. So Win7 has it disabled as well. There is no way to enable it again, either.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
There is no way to get around that dialog box. One of the options, I think, is to execute the autorun, but I could be wrong. I haven't used it in a long time.
|
|
|
|
|
From a security perspective, I will NEVER autorun an application on a flash drive.
I've seen an entire network get a virus from a flash drive.
|
|
|
|
|
I have database like this
Manufacture Model No Length Width height
Manufacture 1 MD-01 200 300 100
Manufacture 1 MD-02 300 400 100
Manufacture 1 MD-03 400 300 150
Manufacture 2 MAD-01 200 450 100
Manufacture 2 MAD-02 250 400 100
Manufacture 3 MDI-01 300 300 100
Manufacture 4 MOv-01 350 300 100
I would like to create 2 combobox -
1) Manufacture 2 ) model No
Manufacture should display for above example Manufacture 1,Manufacture 2,Manufacture 3, Manufacture 4
when particular manufacture selected for example Manufacture 2 -> combox should display only MAD-01 & MAD 02.
Based on both selection text box must me loaded with length, width , height.
i tried sample code & try to assign the combox with database value. I found duplicate list of column. Like for combobox1 accumulate
Manufacture 1
Manufacture 1
Manufacture 1
Manufacture 2
Manufacture 2
Manufacture 3
Manufacture 4
Is there any example program available to do this. How can do this.
|
|
|
|
|
You have to create separate data sources for these and bind the dropdowns to them. You'll have to execute a Distinct Select on whatever columns from the datasource you're trying to bind to.
|
|
|
|
|
am i request to to provide COde for hotel management system hope u will do my needfull thank u
|
|
|
|
|
|
Not going to happen, ever.
First, VB6 is long since dead and is unsupported by Microsoft.
Second, no we're not doing your homework or paid work for you. We will gladly help you with writing your own code, but we're not going to write it for you.
|
|
|
|
|
You do realize VB 6 has been dead for about 10 years, right? Also, this site isn't a place where people just hand over code.
"I've seen more information on a frickin' sticky note!" - Dave Kreskowiak
|
|
|
|
|
Try check in
planetsourcecode.com
I still use vb6 its not dead yet. Still alive and rocks. 👍😀
|
|
|
|
|
That you use it does not mean it is a supported scenario.
Some people still use ancient Latin; it might never go away completely, but it is not alive; it is not being updated, it is actively phased out.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
This question is wide and you do not expect anyone to give out such application source code just like that. Vb6 is not widely supported but luckily for you, I have written this application for some of my clients in vb6 and .net. The best I can do for you is
1. Sit, think on how hotel manual system works
2. Implement it into automated system. While trying to implement, call for help in any of the module if you get stuck. Or better still, place an order for the complete project.
|
|
|
|
|
I have HUAWEI E1550 USB modem with Sim card, this modem connects COM3 virtually, what i need is a vb.net small app that has combo box to navigate with COM port has the USB virtually connected, a listview which shows messages that the sim received, and this listview must get the message immediately without clicking any event or refreshing the app. when new sms comes it appears the list immediately.
more thanks
|
|
|
|
|
If you need help, you'd need to ask a specific question. If you are looking for someone to build this for you, then you'd need another site.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello,
I wanted to develop a code in VB inside MS Excel that allows the user to select his name from a drop down menu placed in an Excel Cell. Then the code asks the user for a password against his username and further unlock selected columns for him to edit.
I have created a drop down list via this help:
http://spreadsheetpage.com/index.php/tip/create_a_drop_down_list_of_possible_input_values/[^]
How to proceed further for asking the user for a password?
|
|
|
|
|
Excel has a built in system for password protecting worksheets or specific cells.
|
|
|
|
|