Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Username Parameter to Application 1

Status
Not open for further replies.

solidjp

Programmer
Jul 16, 2002
29
US
I have a login screen that allows the user access to the Main Application. If the user successfully logs in, the Main App displays a list of command buttons that when clicked, will execute another application. Now what I need is to pass the application being launched the username of the user logged in. Which in turn checks the database to see if the user has access to open the application. If the user has access, the application will launch and vice versa. I DON'T want to do this using the registry or by reading an external file. Is there a certain API call that I can make that will allow me to pass such a parameter as this. I looked at ShellExecute but couldn't see how this would work. I also looked at WindowsMessaging and couldn't figure out how to handle it once I got it. Thanks in advance...
 
There is a command line string in VB that contains any parameters that accompany a program name. If you were to launch an app as follows:

Shell "C:\program.exe Tom", vbNormalFocus

What you'll find is that the command string (called command)in the app will be set to "Tom" - you can manipulate that then however you want. What we tend to do is put an indicator in front as sometimes we have several parameters being passed:

Shell "C:\program.exe /User=Tom", vbNormalFocus

Command will be set to "/User=Tom"

Hope this helps....
 
Thanks Tom, the only problem with this is that the other application is going to still be open along with the new application. Sorry to leave that out when I posted.
 
shell causes the app to open asynchronously, or is that your point.

if you need your first app to close after you have opened your second app, just use brute force "end" statement or the elegant unload me statement!

good luck

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
File Formats Galore @
 
Solidjp

May not be pretty but it does work...

We have something like that, what we do is to place a textbox on the login screen. Set the visible=false. We store the users password there. Then call the other app. with a text box with the same setting on the load screen.

Using the linkitem, linkmode, linktimeout and linktopic we
link the text box from the login screen to the load screen
of the 2nd app. passing each users password to what ever
app. is called to verify permission rights

Hope this gives you an ideal.

Good Luck!
 
I need the 2nd app to run synchronously. So the main app will know when the 2nd app has finished executing. I need a Win32 API call to process another thread or so I've heard.
 
WZUP, that sounds interesting and like a good solution. Could you tell me more on how you use the LinkItem ect. Like the syntax on how you use them. Thanks.
 
solidjp

On each startup screen, Logon and called app. add a textbox-txtpassword and store your users password. On our logon screen we require a name and password.

On the called program(s)
Go into properties for the textbox

Linkitem : txtpassword
Linkmode : 1-Automatic
Linktimeout: 50
Linktopic: Logon|frmLogon

Logon- is whatever your logon project name.
frmLogon- is the form you use for users login

This will create a link between forms. So when the called programs load the password from the logon screen is automaticly passed. Then just check for permission. One word
of caution, make sure the visible properties are disabled or the users password will display on the screen.

Let me know if it works for you.

Jerry

 
WZUP,

I keep getting a "No foreign application responded to a DDE initiate" error everytime I try to change the LinkMode from 0. I have set the other properties LinkTopic, LinkItem etc...
 
solidjp,

Make sure your logon program is up and running on your P.C.
at the same time you set the link properties on your called program.

When you set the link properties for the textbox on your called program you should be able to see the password appear in the textbox when you set the linkmode to 1.

This is a direct link to the Logon form/txtpassword.

One other thing, by using this method your logon program MUST be running on your development P.C. when you compile or run the called programs, if not your link will be wiped out.

 
WZUP, Dude, I'm sorry... I can't get this thing to work. I know I must be doing something wrong but I keep getting the same error. Instead of a textbox, I am using a label. I am only having to pass the username so I don't have to hide it. Here is what I have going on.

Logon Form:
The lblUsername contains username after a user logs in. On lblUsername, I don't have any Link stuff set. User clicks cmdButton to launch other app.

2nd App:
The label is called the same thing as the label(lblUsername) in the logon form. LinkTopic is set to the Logon app project + the Logon app form name (LogonProj|frmFront). LinkItem is set to the label name from the Logon form (lblUsername).

I have the Logon form running with the user logged in. I try to set the LinkMode property to anything beside 0 and I get the same error. So what am I doing wrong?
 
hmmmmmmmmm.........

How are you loading the username into a label on logon?
I guessing based upon a password. I guess you don't have two guys named John working there :)

Double check your syntax, I only time I get this
error is due to the Logon program NOT running in the back-ground or from typo's..

Kinda busy right now, let me re-create using Labels and double check my Logon object properties.

Although I can't see how using a label would make a dif..

I'll check back..
 
WZUP,
Thanks for all of your help. I finally got it to work. I made to sample projects and tried it that way and it worked like a charm. I still can't get it to work in my "real" applications but I must be doing something wrong. I will keep trying since I know it will work. Thanks again for your excellent help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top