Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Find out the command line

Posted on 2001-06-29
13
429 Views
Last Modified: 2008-03-17
can somebody help me how to use the GetCommandLine function of Win32 API in Visual Basic?  My VB Application crashes whenever i call this function. I want to find out the complete path from where my program has started. I have the same problem when i use the GetStartupInfo function and try to access returned data.
0
Comment
Question by:riaz9
  • 5
  • 2
  • 2
  • +3
13 Comments
 
LVL 4

Expert Comment

by:joachimc
ID: 6237266
Why don't you do like this?

create a button and a textbox.

in the button_click try this

text1.text = app.path

/Joachim
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6237430
Joachimc, you are hardly a new EE member so should be aware of the guidelines on comments vs answers. Please re-read this at the bottom of this page. Whilst I would agree that app.path may well return the desired result it does not necessarily answer the question as posted.

Nor in fact does this but it is a nicer way of getting the same information. I too have had problems with the GetCommandLine call though I have managed to get it to work occasionally. One thing to remember with GetCommandLine is that it doesn't necessarily return the full path on windows NT.

Private Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
Private Declare Function GetWindowWord Lib "user32" (ByVal hwnd As Long, ByVal nIndex As Long) As Integer
Const GWW_HINSTANCE = (-6)
Private Sub Form_Load()
    'KPD-Team 2000
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Dim ModuleName As String, FileName As String, hInst As Long
    'create a buffer
    ModuleName = String$(128, Chr$(0))
    'get the hInstance application:
    hInst = GetWindowWord(Me.hwnd, GWW_HINSTANCE)
    'get the ModuleFileName:
    'enter the following two lines as one, single line:
    ModuleName = Left$(ModuleName, GetModuleFileName(hInst, ModuleName, Len(ModuleName)))
    'set graphics mode to persistent
    Me.AutoRedraw = True
    'show the module filename
    Me.Print "Module Filename: " + ModuleName
End Sub
0
 
LVL 4

Expert Comment

by:joachimc
ID: 6237990
I am very well aware of the guide lines. But I am also aware of the anarchy that exists when choosing answers to accept a comment. There is really no solution to that today.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 14

Expert Comment

by:wsh2
ID: 6239828
Why are you using APIs?

The Program startup directory is stored in:

App.Path

and the VB

COMMAND

function will return the command line parameters as a string, which you can then parse according to your needs.

==================================================
joachimc.. I wholeheartedly agree with TimCottee.. the only anarchy in this forum.. is YOU for locking down this question, precluding riaz9 from getting a full discussion of his/her question. Please change your Answer to a Comment.

riaz9.. if you reject joachimc's answer.. your question will be retuned to the much more well traveled areas of this forum.. affording you the opportunity for your question to recieve the proper amount of consideration it deserves. IF, at a later time.. you feel that joachimc's comment is the most apprpriate to your cause.. you can then accept it as the answer.. regardless of the fact that it was once rejected.. <smile>.
0
 
LVL 1

Author Comment

by:riaz9
ID: 6240343
thanks a lot for the proposed answer joachimc, your solution gives me the appl. path, but it does not tell me how to exactly use the getcommandline function to get the same result (i am aware that in NT, the full appl. path is not returned).  The actual problem that i am facing here, is that when i execute GetCommandLine or GetStartupInfo function and access the results returned.  Please help me as to how to use this functions without my program terminating.
0
 
LVL 1

Author Comment

by:riaz9
ID: 6240344
thanks a lot for the proposed answer joachimc, your solution gives me the appl. path, but it does not tell me how to exactly use the getcommandline function to get the same result (i am aware that in NT, the full appl. path is not returned).  The actual problem that i am facing here, is that when i execute GetCommandLine or GetStartupInfo function and access the results returned, my application crashes.  Please help me as to how to use this functions without my program terminating.
0
 
LVL 1

Author Comment

by:riaz9
ID: 6240345
thanks a lot for the proposed answer joachimc, your solution gives me the appl. path, but it does not tell me how to exactly use the getcommandline function to get the same result (i am aware that in NT, the full appl. path is not returned).  The actual problem that i am facing here, is that when i execute GetCommandLine or GetStartupInfo function and access the results returned, my application crashes.  Please help me as to how to use this functions without my program terminating.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 6424438
As you are active again here.. what is your status with this Question? As I pointed out above.. there is NO need for APIs as the VB Command function will give you the Command Line the program was started.

PLEASE tend to your Question here with a comment, BEFORE proceeding with your Aug 25 Questions.. <smile>.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7139958
Hi riaz9@devx,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Refund points and save as a 0-pt PAQ.
*** useful comments, but question is clear... and was not answered.

EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Author Comment

by:riaz9
ID: 7140078
Hi DanRollins,

I am somewhat confused here now.  My main problem here was the way the functions GetCommandLine and GetStartupInfo were working, so thats the reason why i had put these here.  I wanted to know what i was doing wrong that these functions were not working.

Are you suggesting that i reduct points to 0 and accept joachimc's answer? (because this did not solve my problem of my application crashing?)

Or do I post a request to delete the question?

Please help me how to proceed!

Thanks
Riaz
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7140321
Hi Riaz,
We are cleaning up these old question.  In general, it is up the the Asker (you) to try to finalize them, but if you stop responding to Expert comments, we assume that you are unavailable and the Comminity Support Moderators come along and force a decision.

At this point, it is unlikely that you will get your question answered.  So your options are:

o Accept one of the above comments as an answer (in case you want to reward an expert even though you did not get a solution).

o Post a question to Community Support and ask them to delete this question.

o Just do nothing.  In one week a Moderator will pass through here and refund your points; the Mod will reduce the points to 0 and save this question in the PAQ because there is some good information here.

--- If you still need an answer, it would be best to post a new question in this Topic Area.  That will get attention.  This one will probably not.

-- Dan
0
 
LVL 1

Author Comment

by:riaz9
ID: 7144058
Thanks for the reply. I will wait for a week for the moderator to reduce the points and save question as PAQ - because as you said this question might really help others (who want to know what the command line for their vb program is).

Riaz
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 7178838
Placed in PAQ

Computer101
E-E Moderator
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question