KavirM
KavirM

Reputation: 33

Executing a list of commands on command prompt from within my VB.NET Application

I am trying to achieve the following from the application that I am developing.

On click of a button a folder is created in a specific location, (Set in the GUI.) I need this folder to be hidden such that even if the user clicks the "View hidden items" Option, they will not be able to see this folder. I have tried doing this:

            Dim di As DirectoryInfo

        di = Directory.CreateDirectory(path) 'path is a variable with the location

        di.Attributes = FileAttributes.System
        di.Attributes = FileAttributes.Hidden

This however does not work. As an alternative, I created the folder using the application and executed the following code in cmd prompt:

attrib +s +h D:\Documents\FolderName

This works, i.e. it hides the folder even when view hidden items is checked.

What I want to know is, how can I open up cmd prompt from within my application, for argument sake, when the create folder button is clicked, and execute this code in command prompt? I tried using the

process.start("cmd.exe", "attrib +s +h D:\Documents\FolderName")

but this does not work. It just opens cmd prompt with the directory set as my applications debug folder.

My question is, how can I execute my command line statements from within my VB.NET application and after executing the statements, close cmd prompt? I thought of adding a new "Console Application" project to my solution but I have no experience working with it.

Any help would be greatly appreciated.

Thanks.

Upvotes: 0

Views: 662

Answers (1)

user2480047
user2480047

Reputation:

You don't need to execute attrib (what, by the way, can be done by relying on the Process class), just to use the Attributes property right. Sample code:

Dim di As DirectoryInfo = New DirectoryInfo(Path)
di.Create()
di.Attributes = FileAttributes.System Or FileAttributes.Hidden

Upvotes: 2

Related Questions