Results 1 to 18 of 18

Thread: [RESOLVED] Cmd in vb and Super hidden files

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    9

    Resolved [RESOLVED] Cmd in vb and Super hidden files

    I looked through the posts and though I found similar questions none quite answered what I needed. I wish to run this command from vb: attrib “filename or folder with complete path” +s +h (without quotes)

    BUT I do not have a set path, as I'd like it to be a variable that I have in my vb program. How would I go about changing the exact path to the variable? Is that possible? and if not how would i ship the batch file to the other person's pc that this program will be run on? Any help and example code would be AWESOME! Its been a while since i've programmed anything, so I'm a little rusty...

  2. #2
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: Cmd in vb and Super hidden files

    Code:
    Dim testPath As String
    testPath = "the path of the file goes here"
    SetAttr testPath, vbHidden + vbSystem
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Cmd in vb and Super hidden files

    from msdn
    SetAttr Statement Example
    This example uses the SetAttr statement to set attributes for a file. On the Macintosh, only the constants vbNormal, vbReadOnly, vbHidden and vbAlias are available.

    SetAttr "TESTFILE", vbHidden ' Set hidden attribute.
    SetAttr "TESTFILE", vbHidden + vbReadOnly ' Set hidden and read-only
    ' attributes.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    9

    Re: Cmd in vb and Super hidden files

    I want the user to pick the path at runtime, then make that folder hidden... I have it so when the user picks the folder it is stored in a variable... Would I use that variable in the "the path of the file goes here" part of the code?

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Cmd in vb and Super hidden files

    yes, replace the file name with the path variable, as in someluke example
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    9

    Re: Cmd in vb and Super hidden files

    well I just can't get it to work... I feel as though I'm missing the command to bring up cmd.exe or something. What should my code look like if I'm trying to execute the command attrib “strSelectedFolder” +s +h... It could be something simple that I'm missing, but I just don't know... its been such a long time since I've worked with vb or programming in general. The event takes place at a button click and I'm thinking I'm going to have to declare the variable selected folder in general declarations since I'm using it in a directory change event AND the button click event. I erased my code for the dos and decided to start from scratch, but now I'm just even more confused... I waited too long to apply what I was asking as I had to continue coding the next day and forgot...so my question is what should it look like?

  7. #7
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Cmd in vb and Super hidden files

    Something like this.
    Code:
    SetAttr “filename or folder with complete path” , vbHidden + vbReadOnly ' Set hidden and read-only
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  8. #8

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    9

    Re: Cmd in vb and Super hidden files

    I pasted that code in the button click event and nothing happens the folder is still visible, and there is no cmd.exe window. what am i doing wrong?

  9. #9
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    Re: Cmd in vb and Super hidden files

    You're not providing the path....
    "the path of the file goes here"
    should be something like
    "C:\FolderName"
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Cmd in vb and Super hidden files

    hidden attribute will only hide the file/folder if the user doesnt have "Show all hidden files and folders" selected in their Folder Options.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    9

    Re: Cmd in vb and Super hidden files

    Quote Originally Posted by RobDog888
    hidden attribute will only hide the file/folder if the user doesnt have "Show all hidden files and folders" selected in their Folder Options.

    I see... then my original question still stands. How do I run dos commands from my vb program? The command I wish to run make a file or folder hidden, I don't need a command to do that, just how to run the one I have using a variable that is declared in my general declarations that the user picks at run time.

    The user picks a folder they wish to hide using the directory control I placed on the form, then they hit a button which hides the folder using the dos command attrib “filename or folder with complete path” +s +h (without quotes) my variable is received when the user selects their folder. So I don't have an exact path until the user selects it and it is passed to the declared variable. so my question is how do I run that command I specified in dos with my declared variable? or can it be done?

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Cmd in vb and Super hidden files

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  13. #13
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Cmd in vb and Super hidden files

    even using dos they will still show in explorer on any computer, set to show hidden and system files
    here is the code, the folder property is hidden and can not be unhidden in explorer, but the folder and contents is still visible
    vb Code:
    1. p = "c:\temp"
    2. Shell "cmd.exe  /c attrib +S +H """ & p & """"
    Last edited by westconn1; Jan 10th, 2009 at 08:23 PM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  14. #14
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Cmd in vb and Super hidden files

    So if you are asking to hide a folder from the operating system but then how would it be able to keep track of it
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  15. #15
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Cmd in vb and Super hidden files

    Why do you still want the DOS Command when SetAttr accomplishes it already? Do have a special reason for that? They just perform the same function.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  16. #16

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    9

    Re: Cmd in vb and Super hidden files

    Quote Originally Posted by RobDog888
    So if you are asking to hide a folder from the operating system but then how would it be able to keep track of it
    With a change in registry to unhide the folder, that I would code in the unhide button.

  17. #17
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Cmd in vb and Super hidden files

    No I mean how Windows would keep track of it with some "super" hidden attribute when it doesnt exist. Its only vbHidden which still will always be able to be shown if the user changes or already has the setting on.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  18. #18

    Thread Starter
    New Member
    Join Date
    Jan 2009
    Posts
    9

    Re: [RESOLVED] Cmd in vb and Super hidden files

    thanks i figured it out with your help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width