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!

API call to pass an application the username

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...
 
Private Declare Function GetUserID Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Public Function GetUserName() As String
Dim lR As Long
Dim sDump As String
sDump = String(255, " ")
lR = GetUserID(sDump, 255)
GetUserName = Left$(sDump, InStr(1, sDump, vbNullChar) - 1)
End Function
Private Sub Command1_Click()
MsgBox GetUserName
End Sub
 
After re-reading your post I think this is more what you're looking for.

Shell "C:\Folder\AppToOpen.exe Parameter"

In form Load event of the AppToOpen do something like this:

Private Sub Form_Load()
If Command = "Parameter" Then
'Do something
End If
End Sub

 
Thanks DrJavaJoe, 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.
 
I don't see the problem, just unload the first application after calling the shell function.


Private Sub Command1_Click()
Shell "C:\Folder\AppToOpen.exe Parameter"
'Unload all Forms
Dim i As Integer
For i = (Forms.Count - 1) To 0 Step -1
Unload Forms(i)
Next i
end Sub

'In form Load event of the AppToOpen do something like this:

Private Sub Form_Load()
If Command = "Parameter" Then
'Do something
End If
End Sub
 
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.
 
You could make the 2nd app an ActiveX exe and when it is done raise an event calling the main program. Take a look at this thread thread710-344915.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top