Visual Basic – Search for the drive locations instead of me setting it (BEFORE compilation to .exe)

115 pts.
Tags:
Visual Basic
This is under console application. After the compilation I take the .exe file and put it in my flash. I tried it when I specify the drive and the location, so F:workcp.bat, works great. So I want to make it so that I don't have to specify a drive F:, because it might not be that drive when I plug in the USB. So maybe have it search for the drive it's in.... (this is before I compile it... since after compilation I can't make changes) One more thing, what line of code should I add so that when I run the .exe instead of the small black window popping up, it's minimized for that ( 1 second ) it's on the screen. THANK YOU



Software/Hardware used:
Visual Basic - under windows XP

Answer Wiki

Thanks. We'll let you know when a new response is added.

BTW

Sub Main()
Dim shell
shell = CreateObject(“wscript.shell”)
shell.run(Chr(34) & (“F:\work\cp.bat”) & Chr(34), 0)
shell = Nothing

End Sub

End Module

This is how the code looks now….

Discuss This Question: 16  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Sdelan
    BTW Sub Main() Dim shell shell = CreateObject("wscript.shell") shell.run(Chr(34) & ("F:workcp.bat") & Chr(34), 0) shell = Nothing End Sub End Module This is how the code looks now....
    115 pointsBadges:
    report
  • Gent01
    Boy, you second questions makes me wonder what your up to. Your first question has to do with the os path variable. You can't do anything about it in your program.
    1,870 pointsBadges:
    report
  • Sdelan
    Well, the second question really doesn't matter... I just don't want it to keep coming up when I start the program. it's not really a big deal... So basically I need to set the location?
    115 pointsBadges:
    report
  • carlosdl
    The question is not clear enough. You talk about putting your exe file in your flash drive, but the path you mention is not the path of your exe file but the path of a BAT script you execute from your program, so, how is the VB program supposed to know where you are going to put the BAT script ? Sorry, this doesn't make much sense to me. However, if the BAT file is always going to be in the same path as the EXE file, then you don't need to specify the path:
    shell.run(Chr(34) & (”workcp.bat”) & Chr(34), 0)
    Please let us know if that is what you meant.
    69,920 pointsBadges:
    report
  • Sdelan
    that's what i mean... I'm just not sure how to make it find the drive... It want's me to set a drive, and I don't know what drive the USB will always be at. Could be F could be J, depends on the amount of drivers in the PC.
    115 pointsBadges:
    report
  • carlosdl
    I don't understand this part "It want’s me to set a drive..." What wants you to set a drive ? Also, where is the application (exe) going to be located ?
    69,920 pointsBadges:
    report
  • Sdelan
    Visual Basic. it's going to be on a flash drive, so the drivers will change. Visual basic wants me to set the specific drive F: E: etc.. but I don't know what the drive will always be...
    115 pointsBadges:
    report
  • carlosdl
    Sledan, I still don't understand. Why do you say that Visual Basic "wants you to set the specific drive" ?
    69,920 pointsBadges:
    report
  • Sdelan
    Because if I don't set a specific drive I can't compile (it won't let me compile).
    115 pointsBadges:
    report
  • carlosdl
    In this line:
    shell.run(Chr(34) & (”F:\workcp.bat”) & Chr(34), 0)
    The drive letter is inside a string, which is a parameter for the RUN command, and it is not verified at compile time. Can you post the exact line of code you use when the drive letter is not specified, and the error message you get ?
    69,920 pointsBadges:
    report
  • Sdelan
    well, that's the thing... I'm not sure what the code would be... (so that it finds the drive of the usb by itself once the .exe is ran)
    115 pointsBadges:
    report
  • carlosdl
    It seems that we have a big communication problem here. You said this: "Because if I don’t set a specific drive I can’t compile (it won’t let me compile)." What I understand from that text is that you tried with some code without specifying the drive letter, and you got an error message. So, what is the code you tried, and what is the error message you got ?
    69,920 pointsBadges:
    report
  • Sdelan
    That's right.
    115 pointsBadges:
    report
  • Vatchy
    If I understand your question correctly, you want to insert a flash drive with a program on it and you want the program to run a batch file that is on the same flash drive without knowing what the actual drive letter is going to be. If that is correct then the answer is easy: copy APP.PATH to a string variable and then get the drive letter from that:
    Drive = left(app.path, 3)
    will get you "F:" (or whatever the drive is)
    1,410 pointsBadges:
    report
  • carlosdl
    I guess that would work, Vatchy. My point was that if both, the application and the script (batch file), are on the same path, then there is no need to specify the path.
    69,920 pointsBadges:
    report
  • Sdelan
    That's what I mean. Could you give me the pre-compilation code, since I'm a newbie... and don't really know much. Thanks
    115 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following