CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2012
    Posts
    4

    Post Reassignig drive letters (VB 2010)

    Hi guys

    I'm currently writing a program which has a requirement to reassign drive letters if a drive with a particular volume name is plugged in to ensure that it is assigned to the correct drive letter.

    Now, I've managed to build some code for checking which drive letters are free. However I've not had much luck with actual drive letter reassignment and google has let me down ().

    One way to do this would be to have the program write a script file which does it and then launch that in conjunction with diskpart... but that's a bit messy and I'd prefer to do it with code.

    Any ideas?

    [EDIT] Maybe another way is to force-eject a drive (after checking to see if it is removable and with the user permission).. but again I'm not sure how to do this.

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Reassignig drive letters (VB 2010)

    This logic does not make sense at all. Why on earth would this be necessary?

    Or... Am I just being daft?

  3. #3
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Reassignig drive letters (VB 2010)

    Is there some reason why the drive must have a specific drive letter? What drive letter are you trying to go for? What if that drive letter is already in use on the given system and needs to remain as is?

    In general I can think of only one reason to require a specific drive letter and that would be that someone hardcoded a drive letter in some software which should really never be done.
    Always use [code][/code] tags when posting code.

  4. #4
    Join Date
    May 2012
    Location
    Bonn, Germany
    Posts
    43

    Re: Reassignig drive letters (VB 2010)

    Maybe he can't control it because it's some third-party software.
    I think you should go with a system call to diskpart.
    You can use this method to create the process and give it the necessary command line arguments: http://msdn.microsoft.com/en-us/library/h6ak8zt5.aspx

  5. #5
    Join Date
    May 2012
    Posts
    4

    Re: Reassignig drive letters (VB 2010)

    Thanks for your replies.

    The code is for windows backup for someone else - he keeps forgetting to swap his drive letters and so every so often his backups fail. I'm writing some code which detects the backup drives by label when plugged in and asks if the user would like to reassign the letter if detected.(it does locate a free letter and reassign any drive using the requisite drive letter).
    So far it mostly works.

    With regard to reassigning drives: I've gone ahead with the diskpart method which works well.The only problem is trying to prevent autoplay from scanning the newly reassigned drives. So far I've tried setting reg key for the appropriate local group policy but it still runs autoplay. So still some work ahead

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

Featured