Page 1 of 2 12 LastLast
Results 1 to 40 of 51

Thread: Need help to put Code together..

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2012
    Posts
    32

    Need help to put Code together..

    I need this
    Code:
     Dim driveletter As String = ""
            Dim allDrives() As System.IO.DriveInfo = System.IO.DriveInfo.GetDrives()
            For Each drive As System.IO.DriveInfo In allDrives
                If drive.DriveType = IO.DriveType.CDRom Then
                    'OK Now we have the CDRom
                    driveletter = drive.RootDirectory.ToString()
                End If
            Next
    and this combined
    Code:
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Process.Start("C:\data\CCleaner\CCleaner.exe").WaitForExit()
            Process.Start("C:\data\Malwarebytes\mbam.exe")
        End Sub
    I am trying to get the program to recognize the CD/DVD drive.... where it is highlighted C:.

    The idea of the program is to make a launcher to automatically launch various freeware programs ergo CCleaner,Malwarebytes,SuperAntiSpyware, etc. Once I get the program to recognize what drive it is then I also need to figure out how to make it Start, Close, then start the next one.... So obviously

    Code:
    Process.Start("C:\data\CCleaner\CCleaner.exe").waitforexit()
    Process.Start("C:\data\Malwarebytes\mbam.exe").Waitforexit()
    Won't work because the .waitforexit() isn't waiting for exit of CCleaner.. WHY? And could a delay be incorporated into this to make it wait for the .waitforexit()? BTW for you trolls I am very very new to VB so as simple as this may be it is my way of learning so GTFO if you have hate mail.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: Need help to put Code together..

    Trolls don't last long around here.

    In this line:

    Process.Start("C:\data\CCleaner\CCleaner.exe").WaitForExit()

    it appears taht you want to replace the C: with whatever is in your variable. To do that, the line would look like this:

    Process.Start(driveletter & "\data\CCleaner\CCleaner.exe").WaitForExit()

    Of course, this would only work if driveletter actually has someting, but you mostly have the code for that. There are two issues to consider. The first is whether or not that first code could fail in such a way that driveletter was never set. That seems unlikely, but possible. Therefore, you'd probably want to explicitly check that driveletter was not an empty string.

    Combined, they would look like this:
    Code:
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim driveletter As String = ""
            Dim allDrives() As System.IO.DriveInfo = System.IO.DriveInfo.GetDrives()
            For Each drive As System.IO.DriveInfo In allDrives
                If drive.DriveType = IO.DriveType.CDRom Then
                    'OK Now we have the CDRom
                    driveletter = drive.RootDirectory.ToString()
                End If
            Next
           
            'Check that there is a letter.
            if driveLetter <> string.empty Then
             Process.Start(driveLetter & "\data\CCleaner\CCleaner.exe").WaitForExit()
             Process.Start(driveLetter & "\data\Malwarebytes\mbam.exe")
            Else
             Windows.Forms.Messagebox.Show("No Drive Letters Found","Nothing Doing")
            End If
        End Sub
    I don't have an answer for why WaitForExit isn't. Not really my area.
    Last edited by Shaggy Hiker; Jan 6th, 2012 at 05:15 PM.
    My usual boring signature: Nothing

  3. #3
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: Need help to put Code together..

    Shaggy, could I ask what a Troll in here means? its the third time I have seen that word in the past week but I do not know what does it refer to.

    * If driveletter is getting the root directory it will get something like "D:\", so the line Shaggy proposes would be

    Process.Start(driveLetter & "data\CCleaner\CCleaner.exe.WaitForExit()

    notice the lack of the first "\"

    But most of all, they are not going to be there because those calls are for the malware software installed in the pc and nothing to do with the cd detected, but you may want to look into a parameter to pass the utility to scan the CD and not the whole PC.

    On the other hand, if CCleaner and Malwarebytes are correctly installed then you could run them by just

    Process.Start("CCleaner").WaitForExit()
    Process.Start("mbam").WaitForExit()
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: Need help to put Code together..

    Quote Originally Posted by kaliman79912 View Post
    Shaggy, could I ask what a Troll in here means? its the third time I have seen that word in the past week but I do not know what does it refer to.
    The meaning is somewhat loose, but it generally refers to people who take pleasure at abusing other people. Lots of forums suffer from people who's sole roll in life is to make denigrating comments at others without being helpful. Quite often, this is directed at the ignorance which comes from being new to something. It's a pretty stupid position, because we are all ignorant before we learn, and we are all learning. That type of person is generally removed from this place pretty quickly, which is one of the things I like about it.
    * If driveletter is getting the root directory it will get something like "D:\", so the line Shaggy proposes would be

    Process.Start(driveLetter & "data\CCleaner\CCleaner.exe.WaitForExit()

    notice the lack of the first "\"
    Oops. I edited a bit too far when I combined those. Still, the points you made after that are even more significant. I was just combining, without considering whether or not it would really work, but I believe that you are right. What I had posted would only apply (had it not had the typo) if the programs were on the CD. I don't even know whether that is possible, though it does seem like this would allow a person to carry around a CD of cleaner apps that could be run, as needed. So, I guess I don't know whether or not the concept is valid or not.
    My usual boring signature: Nothing

  5. #5
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Need help to put Code together..

    that is incorrect. the software in question may not be registered as a shortcut type to the system (environment variables for example) so when you do Process.Start("CCleaner") it will not work if it hasnt registered it like this to the system

    WaitForExit() does work but there seems to be something wrong somewhere else.

    WaitForExit does just that.... its a threadblocking method

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 2012
    Posts
    32

    Re: Need help to put Code together..

    Quote Originally Posted by Shaggy Hiker View Post
    Trolls don't last long around here.

    In this line:

    Process.Start("C:\data\CCleaner\CCleaner.exe").WaitForExit()

    it appears taht you want to replace the C: with whatever is in your variable. To do that, the line would look like this:

    Process.Start(driveletter & "\data\CCleaner\CCleaner.exe").WaitForExit()

    Of course, this would only work if driveletter actually has someting, but you mostly have the code for that. There are two issues to consider. The first is whether or not that first code could fail in such a way that driveletter was never set. That seems unlikely, but possible. Therefore, you'd probably want to explicitly check that driveletter was not an empty string.

    Combined, they would look like this:
    Code:
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim driveletter As String = ""
            Dim allDrives() As System.IO.DriveInfo = System.IO.DriveInfo.GetDrives()
            For Each drive As System.IO.DriveInfo In allDrives
                If drive.DriveType = IO.DriveType.CDRom Then
                    'OK Now we have the CDRom
                    driveletter = drive.RootDirectory.ToString()
                End If
            Next
           
            'Check that there is a letter.
            if driveLetter <> string.empty Then
             Process.Start(driveLetter & "C:\data\CCleaner\CCleaner.exe").WaitForExit()
             Process.Start(driveLetter & "\data\Malwarebytes\mbam.exe")
            Else
             Windows.Forms.Messagebox.Show("No Drive Letters Found","Nothing Doing")
            End If
        End Sub
    I don't have an answer for why WaitForExit isn't. Not really my area.
    I went and tried to place that code in there. Nothing happened it kicked back and said file could not be found...
    Last edited by Matthew.Kaulfers; Jan 6th, 2012 at 05:20 PM.

  7. #7

    Thread Starter
    Member
    Join Date
    Jan 2012
    Posts
    32

    Re: Need help to put Code together..

    A troll is someone who goes around not offering any help whatsoever but they are sure to post hate mail. Like "You don't know what you are doing you noob" or "Are you an idiot" things of that nature. They have nothing good to say only bad.

  8. #8
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: Need help to put Code together..

    there is an overload of WaitForExit() where you put the number of milliseconds to wait as maximum. But the process exit takes precedence.
    Process.WaitForExit(10000)
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: Need help to put Code together..

    Boy did I screw up that code. Not only the missing \ that Kaliman pointed out, but I see that I actually left the C: in one of the lines in the final snippet. I've gone back and edited that to correct it.
    My usual boring signature: Nothing

  10. #10

    Thread Starter
    Member
    Join Date
    Jan 2012
    Posts
    32

    Re: Need help to put Code together..

    Quote Originally Posted by kaliman79912 View Post
    Shaggy, could I ask what a Troll in here means? its the third time I have seen that word in the past week but I do not know what does it refer to.

    * If driveletter is getting the root directory it will get something like "D:\", so the line Shaggy proposes would be

    Process.Start(driveLetter & "data\CCleaner\CCleaner.exe.WaitForExit()

    notice the lack of the first "\"

    But most of all, they are not going to be there because those calls are for the malware software installed in the pc and nothing to do with the cd detected, but you may want to look into a parameter to pass the utility to scan the CD and not the whole PC.

    On the other hand, if CCleaner and Malwarebytes are correctly installed then you could run them by just

    Process.Start("CCleaner").WaitForExit()
    Process.Start("mbam").WaitForExit()
    Actually I just want the program to locate the CD/DVD drive because that is where I ahve the CCleaner and mbam and all that other mumbo jumbo installed at.(on the CD) but if i leave it as process.start(ccleaner.exe).waitforexit() then it will come back and say file could not be found because it is installed on the CD not the PC. That is why I need it to have a directory.

  11. #11
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Need help to put Code together..

    with the code supplied, it will work now. as long as the path exists and file exists... then of course when you start the process, it will work otherwise... you will get the exception that the file/path was not found

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  12. #12

    Thread Starter
    Member
    Join Date
    Jan 2012
    Posts
    32

    Re: Need help to put Code together..

    Quote Originally Posted by Techno View Post
    with the code supplied, it will work now. as long as the path exists and file exists... then of course when you start the process, it will work otherwise... you will get the exception that the file/path was not found
    Not working I have checked and double checked the directories and the files they exist where they are supposed to be but it is still unhandled.

  13. #13
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Need help to put Code together..

    ok if its unhandled.... then that tells you something. if the file/folder was not found then that is correct. not found

    can you paste and inspect the file path/folder the code is obtaining against the actual location. if there is a difference - thats the problem.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  14. #14
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Need help to put Code together..

    Do this:

    if File.Exists(driveLetter & "data\CCleaner\CCleaner.exe") then MessageBox.Show("File exists")
    else MessageBox.Show("Not exists")

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  15. #15
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: Need help to put Code together..

    but does the process start? or does your program just dont wait for it to exit?
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  16. #16

    Thread Starter
    Member
    Join Date
    Jan 2012
    Posts
    32

    Re: Need help to put Code together..

    Code:
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim driveletter As String = ""
            Dim allDrives() As System.IO.DriveInfo = System.IO.DriveInfo.GetDrives()
            For Each drive As System.IO.DriveInfo In allDrives
                If drive.DriveType = IO.DriveType.CDRom Then
                    'OK Now we have the CDRom
                    driveletter = drive.RootDirectory.ToString()
                End If
            Next
    
            'Check that there is a letter.
            If driveLetter <> String.empty Then
                Process.Start(driveletter & "data\CCleaner\CCleaner.exe").WaitForExit()
                Process.Start(driveletter & "data\Malwarebytes\mbam.exe")
            Else
                Windows.Forms.MessageBox.Show("If you got this message then go home.", "Ooop's We messed up.")
            End If
        End Sub
    That's what I have... Still isn't working and I assure you the files are located at D:\data\CCleaner\CCleaner.exe and D:\data\Malwarebytes\mbam.exe.

  17. #17
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Need help to put Code together..

    the poster indicated it did not start and throws an Exception saying that the file was not found

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  18. #18

    Thread Starter
    Member
    Join Date
    Jan 2012
    Posts
    32

    Re: Need help to put Code together..

    Quote Originally Posted by kaliman79912 View Post
    but does the process start? or does your program just dont wait for it to exit?
    LOL right now I just need to get it to launch the program when the CD/DVD drive letter isn't blatantly put out there then I will move to that problem xD

  19. #19
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Need help to put Code together..

    did you do the suggestion I posted for debugging purposes?
    did you step through the code line by line and inspecting the values, seeing if they are sane?

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  20. #20

    Thread Starter
    Member
    Join Date
    Jan 2012
    Posts
    32

    Re: Need help to put Code together..

    I have a feeling the problem lies here somewhere. It isn't the directory.
    Code:
                Process.Start(driveletter & "data\CCleaner\CCleaner.exe").WaitForExit()
                Process.Start(driveletter & "data\Malwarebytes\mbam.exe")
    So.... any ideas? I am 110&#37; stumped...
    Last edited by Matthew.Kaulfers; Jan 6th, 2012 at 05:35 PM. Reason: Wrong Highlight

  21. #21

    Thread Starter
    Member
    Join Date
    Jan 2012
    Posts
    32

    Re: Need help to put Code together..

    Quote Originally Posted by Techno View Post
    did you do the suggestion I posted for debugging purposes?
    did you step through the code line by line and inspecting the values, seeing if they are sane?
    I tried removing the "\" but it didn't change anything still an unhandled exception file not found jada jada BS... XD

  22. #22
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Need help to put Code together..

    Quote Originally Posted by Matthew.Kaulfers View Post
    I have a feeling the problem lies here somewhere. It isn't the directory.
    Code:
                Process.Start(driveletter & "data\CCleaner\CCleaner.exe").WaitForExit()
                Process.Start(driveletter & "data\Malwarebytes\mbam.exe")

    So.... any ideas? I am 110% stumped...

    I think it was mentioned before, there is a \ missing at the beginning. include it but I cannot remember if the DriveLetter will contain a leading backslash, so for sanity sake now:

    Code:
    if not driveletter.EndsWith("\") then driveletter = driveletter & "\"
    Process.Start(driveletter & "data\CCleaner\CCleaner.exe").WaitForExit()
    Process.Start(driveletter & "data\Malwarebytes\mbam.exe")
    again, did you do the suggestion I had posted?

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  23. #23
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Need help to put Code together..

    if the file wasnt found then clearly the path being constructed is incorrect. .NET/computer doesnt lie

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  24. #24
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: Need help to put Code together..

    Quote Originally Posted by Matthew.Kaulfers View Post
    Actually I just want the program to locate the CD/DVD drive because that is where I ahve the CCleaner and mbam and all that other mumbo jumbo installed at.(on the CD) but if i leave it as process.start(ccleaner.exe).waitforexit() then it will come back and say file could not be found because it is installed on the CD not the PC. That is why I need it to have a directory.
    The poster said that if he leaves it as process.start(ccleaner.exe).waitforexit() then it will come back and say file could not be found.

    So the question was valid.

    You may want to do other validation as you can have more than one CD on the PC and your loop will only remember the last one. Or if you have a virtual drive is almost always detected as a CD. Even some USB Flash Drives register as CD.

    Do as Teco said and put a breakpoint and look at the contents of driveletter
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  25. #25

    Thread Starter
    Member
    Join Date
    Jan 2012
    Posts
    32

    Re: Need help to put Code together..

    Quote Originally Posted by Techno View Post
    I think it was mentioned before, there is a \ missing at the beginning. include it but I cannot remember if the DriveLetter will contain a leading backslash, so for sanity sake now:

    Code:
    if not driveletter.EndsWith("\") then driveletter = driveletter & "\"
    Process.Start(driveletter & "data\CCleaner\CCleaner.exe").WaitForExit()
    Process.Start(driveletter & "data\Malwarebytes\mbam.exe")
    again, did you do the suggestion I had posted?
    Did as you suggested to no avail

  26. #26
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: Need help to put Code together..

    Did you stop the code with a breakpoint and step through it looking at the variables? particulary driveLetter?
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  27. #27
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Need help to put Code together..

    Quote Originally Posted by Matthew.Kaulfers View Post
    Did as you suggested to no avail
    you didnt quite do what I said
    print out the path to a messagebox. what does it say?

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  28. #28
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: Need help to put Code together..

    Another test you can do is to put the whole path as you know it is right now instead of the detected drive. Something like:

    "D:\CCleaner\CCleaner.exe"

    does it work that way?
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  29. #29
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Need help to put Code together..

    the user indicated that it does work hardcoding it.... they dont want it hardcoded.

    the problem is clear - the file is not found. the path is formed incorrectly.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  30. #30
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: Need help to put Code together..

    Quote Originally Posted by Techno View Post
    the user indicated that it does work hardcoding it.... they dont want it hardcoded.

    the problem is clear - the file is not found. the path is formed incorrectly.
    Again... The user oroginally hardcoded it using his hard drive. Now he is trying to use the CD drive.

    Please read the posts before dismissing everything I write. This is the second time in this thread that you have mistakenly corrected me.
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  31. #31
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: Need help to put Code together..

    we are all trying to help kaliman relax. sorry you feel that way but nothing I can do about that. in future I wont contribute.
    its a community effort, a team effort, not an individual effort. if you cannot accept this then really it wont work. needlessly to say no one is perfect... and you arent either.
    things like this is off putting to everyone.
    ill leave it here for now.
    I wish the OP the best in this problem and im sure its easily resolved.
    Last edited by Techno; Jan 6th, 2012 at 06:21 PM.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  32. #32

    Thread Starter
    Member
    Join Date
    Jan 2012
    Posts
    32

    Thumbs up Re: Need help to put Code together..

    Quote Originally Posted by kaliman79912 View Post
    Another test you can do is to put the whole path as you know it is right now instead of the detected drive. Something like:

    "D:\CCleaner\CCleaner.exe"

    does it work that way?
    It does launch whenever i put

    process.start("D:\data\CCleaner\CCleaner.exe").waitforexit()

    Not perfectly but it does find the file.

  33. #33

    Thread Starter
    Member
    Join Date
    Jan 2012
    Posts
    32

    Smile Re: Need help to put Code together..

    Quote Originally Posted by kaliman79912 View Post
    Again... The user oroginally hardcoded it using his hard drive. Now he is trying to use the CD drive.

    Please read the posts before dismissing everything I write. This is the second time in this thread that you have mistakenly corrected me.
    Yes I originally hardcoded with the "D:\" but that is a random variable from PC to PC. Lets not get upset over this thing I appreciate help from all. And I am trying each individual idea to see if we can work this thing out. Thanks kaliman I probably should have said that originally but it is my fault for the confusion.

  34. #34

    Thread Starter
    Member
    Join Date
    Jan 2012
    Posts
    32

    Re: Need help to put Code together..

    Quote Originally Posted by Techno View Post
    the user indicated that it does work hardcoding it.... they dont want it hardcoded.

    the problem is clear - the file is not found. the path is formed incorrectly.
    Is there a different way to code it to find the drive in a different manner?? It isn't the file being in the wrong way I believe we are just pointing it in the wrong direction.

  35. #35

    Thread Starter
    Member
    Join Date
    Jan 2012
    Posts
    32

    Re: Need help to put Code together..

    Quote Originally Posted by Techno View Post
    we are all trying to help kaliman relax. sorry you feel that way but nothing I can do about that. in future I wont contribute.
    its a community effort, a team effort, not an individual effort. if you cannot accept this then really it wont work. needlessly to say no one is perfect... and you arent either.
    things like this is off putting to everyone.
    ill leave it here for now.
    I wish the OP the best in this problem and im sure its easily resolved.
    Please continue to contribute. This is a program I would love to send to CNet and put some names on. BTW if you continue to help all peoples involved will have their name on this program.

  36. #36

    Thread Starter
    Member
    Join Date
    Jan 2012
    Posts
    32

    Re: Need help to put Code together..

    Okay here is what I have now. It doesn't work.
    Code:
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim driveletter As String = ""
            Dim allDrives() As System.IO.DriveInfo = System.IO.DriveInfo.GetDrives()
            For Each drive As System.IO.DriveInfo In allDrives
                If drive.DriveType = IO.DriveType.CDRom Then
                    'OK Now we have the CDRom
                    driveletter = drive.RootDirectory.ToString()
                End If
            Next
    
            'Check that there is a letter.
            If driveLetter <> String.empty Then
                Process.Start(driveletter & "data\CCleaner\CCleaner.exe").WaitForExit()
                Process.Start(driveletter & "data\Malwarebytes\mbam.exe")
            Else
                Windows.Forms.MessageBox.Show("If you got this message then go home.", "Ooop's We messed up.")
            End If
    I tried this and it launches the program but only on "D:" Drive. Won't work in all computers.....

    Code:
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Process.start("D:\data\CCLeaner\ccleaner.exe").waitforexit()
            Process.start("D:\data\malwarebytes\mbam.exe").waitforexit()
        End Sub
    End Class
    So I think the problem is here...

    Code:
    Dim driveletter As String = ""
            Dim allDrives() As System.IO.DriveInfo = System.IO.DriveInfo.GetDrives()
            For Each drive As System.IO.DriveInfo In allDrives
                If drive.DriveType = IO.DriveType.CDRom Then
                    'OK Now we have the CDRom
                    driveletter = drive.RootDirectory.ToString()
                End If
            Next
    
            'Check that there is a letter.
            If driveLetter <> String.empty Then
    *****************************************************************
            Else
                Windows.Forms.MessageBox.Show("If you got this message then go home.", "Ooop's We messed up.")
            End If
    (****) Represents the process.start in which I say again. THE DIRECTORY IS THERE.
    Last edited by Matthew.Kaulfers; Jan 6th, 2012 at 10:33 PM. Reason: Forgot to put code in.

  37. #37
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: Need help to put Code together..

    Man, glad I went home for dinner.

    This is a situation where a bit of debugging is needed. There isn't going to be a good way around this. The code I posted is mostly right, but there is something slightly off about it, and it is probably as Techno suggested: The driveletter is not just the letter. What is it? I don't know. I could find out, but you can find out even faster. Here's how:

    Put a breakpoint on this line:

    Process.Start(driveletter & "data\CCleaner\CCleaner.exe").WaitForExit()

    when execution stops on the breakpoint, take a look at what is in 'driveletter'. What is it? Next, highlight this portion:

    driveletter & "data\CCleaner\CCleaner.exe"

    and press Shift+F9. In some way, that is not "D:\data\CCleaner\CCleaner.exe". Either a character is added, or a character is missing. Knowing what the difference is will tell you how to correct the line of code.
    My usual boring signature: Nothing

  38. #38
    Addicted Member
    Join Date
    Nov 2011
    Posts
    129

    Re: Need help to put Code together..

    When you break it on the first Process.Start(...).WaitForExit(), what does DriveLetter contain? I think that is the issue at hand. It will be helpful to everyone if they knew what DriveLetter contained when the program stopped at the breakpoint. I think everyone is assuming that it is either blank, or it is the correct letter. Post what it says it is.

    Note: I just read this from top to bottom, so if you mentioned it in an earlier post, I apologize for forgetting.
    Click "Rate This Post" if I helped you in any way.

    The best process for finding help.
    Step 1: Google it
    Step 2: Google it again
    Step 3: Google it yet again
    Step 4: Ask on a forum
    Step 5: Go to Step 1

  39. #39

    Thread Starter
    Member
    Join Date
    Jan 2012
    Posts
    32

    Re: Need help to put Code together..

    Quote Originally Posted by Shaggy Hiker View Post
    Man, glad I went home for dinner.

    This is a situation where a bit of debugging is needed. There isn't going to be a good way around this. The code I posted is mostly right, but there is something slightly off about it, and it is probably as Techno suggested: The driveletter is not just the letter. What is it? I don't know. I could find out, but you can find out even faster. Here's how:

    Put a breakpoint on this line:

    Process.Start(driveletter & "data\CCleaner\CCleaner.exe").WaitForExit()

    when execution stops on the breakpoint, take a look at what is in 'driveletter'. What is it? Next, highlight this portion:

    driveletter & "data\CCleaner\CCleaner.exe"

    and press Shift+F9. In some way, that is not "D:\data\CCleaner\CCleaner.exe". Either a character is added, or a character is missing. Knowing what the difference is will tell you how to correct the line of code.
    Okay waiting for VB to re install. I am on a friends computer. It is almost done. I CAN FEEL WE ARE CLOSE AS idk.... the hair on our jewels...

  40. #40
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,038

    Re: Need help to put Code together..

    I don't even want to consider that metaphor.
    My usual boring signature: Nothing

Page 1 of 2 12 LastLast

Tags for this Thread

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