-
April 24th, 2007, 02:01 PM
#1
Getting a programs ui to run at the login prompt
We have a program we upgraded from VB to C# recently and we are trying to get back the functionality to have the program run at startup and show up along with the login prompt.
Right now the program starts and is running when a user logs into a system but I need it to have the ui available before login and after logout.
Any help would be much appreciated.
Last edited by Groller; April 24th, 2007 at 02:13 PM.
-
April 24th, 2007, 05:31 PM
#2
Re: Getting a programs ui to run at the login prompt
How did you do this in VB? Can you show abreviated code?
I'm not sure exactly what you need, but you might want to have a look at the Program.cs file that is created with all Winapps. Editing this section can allow for flexibility in your startup. The Application.Run(new Form()); is the call that sets your program and the event model started:
Code:
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1()); // this is the call that get's your program started
}
}
Last edited by petes1234; April 24th, 2007 at 05:48 PM.
-
April 24th, 2007, 05:43 PM
#3
Re: Getting a programs ui to run at the login prompt
Yeah, I would like to know how to do this as well. My nvidia detenator drivers helper program shows a UI at my login screen. So it can obviously be done.
-
April 24th, 2007, 06:07 PM
#4
Re: Getting a programs ui to run at the login prompt
We inherited this code from someone who no longer works here and a different department wanted us to support it in VB which we said no to. We would support it in C++ or C# tho and so they had a consultant rewrite the program in C#. The one thing the consultant could not do before his time here ended was get it to run at the login prompt. I don't know the VB code very well but all I can see when referring to the window and its state is
Vb code
Code:
Me.WindowState = vbNormal
Code:
Private Sub Form_Load()
' This code is exceuted when the program has loaded the objects on the form, typically
' immediately after Form_Initialize.
' Hide the form while things are being initialized -- NEW 19MAY04
Me.Hide
' Enable logging
If GetValue("Log GUI Events", True) = True Then App.StartLogging App.Path & "\eventlog.log", 0
' Enable the error handler for this sub
On Error GoTo errFormLoad
' Change the color to be the standard colors.
Me.cmdProjOn.BackColor = vbGreen
Me.cmdSource(0).BackColor = UnselectColor
' Initilize data needed by modInteraction
modInteraction.InitModInteraction
' Load the configuration from the file
' LoadConfig GetValue("DEFAULT-DRIVER-PATH", "C:\test.dvr"), False
Me.ShowWait prConnStartup
' Disable the volume contrrol if necessary
If GetControl.VolumeHidden = True Then Me.frmNoVolume.Visible = True Else Me.frmNoVolume.Visible = False
'Me.UpdateGUI ' Update the source buttons
'Me.Show ' Ensure form is loaded
Me.WindowState = vbNormal ' Make sure that the window is visible
Me.Top = Screen.Height - Me.Height - 250 ' Place the window at the bottom of the screen
Me.Left = (Screen.Width - Me.Width) / 2 ' Center the window horizontally
' Initialize the TCP/IP Interface
Socket1.NoDelay = True
Socket1.AddressFamily = 2
Socket1.Protocol = 0
Socket1.SocketType = 1
Socket1.Binary = True
Socket1.BufferSize = 10000
Socket1.Blocking = False
Socket1.HostName = "localhost"
Socket1.RemotePort = 2003
Socket1.Connect
' Disable the volume control if necessary and set the volume message
If GetControl.VolumeHidden = True Then Me.frmNoVolume.Visible = True Else Me.frmNoVolume.Visible = False
Me.lblNoVolume = GetControl.VolumeMessage
' Initialize the TCP/IP Transmit Queue
ReDim TXQueue(0)
errFormLoad: ' Error handler
ProcError
End Sub
reffered to whenever the status of the window is being set, from minimize to showing up at load of the program itself.
This is the program.cs code
Code:
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Onscreen());
}
}
Last edited by Groller; April 24th, 2007 at 06:18 PM.
-
April 24th, 2007, 06:56 PM
#5
Re: Getting a programs ui to run at the login prompt
I think that the real question is what causes the program to run before the login prompt. Do you have the installer for the VB program? Or, are you able to install it and see what registry entries it sets up in order to cause the program to run?
-
April 24th, 2007, 10:14 PM
#6
Re: Getting a programs ui to run at the login prompt
Originally Posted by Groller
... but I need it to have the ui available before login and after logout.
Other questions I have are:
- what are you trying to achieve with this and why?
- What benefit is there to have a ui on the screen before knowing if the login will fail and the program will exit?
- Do you have the VB code available that shows the relationship w/ the ui and the login routine? I didn't see the latter in your snippet.
-
April 24th, 2007, 11:28 PM
#7
Re: Getting a programs ui to run at the login prompt
My nvidia helper program is a service. I dont think there is any way to run a standard .exe before login, then again, who amI to say.....
I was trying for about a week to have a service present a gui at login, and I couldnt do it. I'm sure it can be done........Obviously nvidia has done it........
-
April 25th, 2007, 02:49 AM
#8
Re: Getting a programs ui to run at the login prompt
Running an application on start up usually involves placing a command in windows registry, it doesn't have any direct relation with the application being developed in VB or C#.
So one thing that I can suggest is that you use tools like autoruns from sysinternals on the PC that still has the old application running to check where the registry value is placed.
Do a search on google for 'autoruns sysinternals'.
Also look at this post here on how to setup a startup script on WinXP
http://help.wugnet.com/windows/Run-p...ict566153.html
Last edited by Luthv; April 25th, 2007 at 03:19 AM.
-
April 25th, 2007, 10:22 AM
#9
Re: Getting a programs ui to run at the login prompt
Originally Posted by petes1234
Other questions I have are:
- what are you trying to achieve with this and why?
- What benefit is there to have a ui on the screen before knowing if the login will fail and the program will exit?
- Do you have the VB code available that shows the relationship w/ the ui and the login routine? I didn't see the latter in your snippet.
This program controls the switchers and projector for about 200 classrooms, 1 station per room.
The benefit is we don't have to allow guest users to log into a domain computer to access the projector controls. Thus keeping our network more secure.
After further study of the old VB program I found:
- There is no installer.
- There was a group policy for these machines in active directory telling this program to run at startup.
After further tinkering with the registry I found that putting the new app in
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServices
gets it to run at startup before the login prompt, but the ui disappears behind the desktop after login yet the program is still running.
If someone has any idea how to fix the above registry problem that would work.
I also have written the new app to become a service now, but when I run it I get this error message.
Cannot start service from the command line or a debugger. A windows service must first be installed (using installutil.exe) and then started with the ServerExplorer, Windows Services Administrative tool or the NET START command.
Thanks for the help, I am just picking up C# so still getting my balance as it were.
-
April 25th, 2007, 11:02 AM
#10
Re: Getting a programs ui to run at the login prompt
Originally Posted by Groller
I also have written the new app to become a service now, but when I run it I get this error message.
Cannot start service from the command line or a debugger. A windows service must first be installed (using installutil.exe) and then started with the ServerExplorer, Windows Services Administrative tool or the NET START command.
Thanks for the help, I am just picking up C# so still getting my balance as it were.
A service is not a standard .exe program. You have to install it by running installutil.exe myProgram.exe from the folder with the service, or provide the fully qualified path for myProgram.exe. To do this you use the CMD prompt. Either goto start-run- type in CMD, or better yet, use the framework(or visual studio, I forget where its at - Check your start menu) CMD prompt. Once installed, you can use service manager to start/stop/modify service properties. Or you can use more command line programs like netstart(I think thats it) to start the program or installutil.exe /u myProgram.exe to uninstall the service.
On another note. Services do not interact with the desktop. You have to tell the service to interact. There is a check box in service manager for the service that will enable interaction with desktop. Furthermore, Windows Vista does not allow services to interact with desktop. So if you have a service that requires interaction with desktop, it wont work on Vista.
-
April 25th, 2007, 11:07 AM
#11
Re: Getting a programs ui to run at the login prompt
Originally Posted by Groller
After further tinkering with the registry I found that putting the new app in
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServices
gets it to run at startup before the login prompt, but the ui disappears behind the desktop after login yet the program is still running.
Did the GUI actually appear at the login prompt. Pretty sure I tried using the registry key you indicated, and my program did not run. I've tried launching my program from a service using the process command, and the gui did not appear. In fact as best I could tell at the time, my program didnt actually start running until user logged in, and had a desktop.
By the way. If your program is window goes behind the desktop when user logs in, why dont you try bringing the window to the top of the z-order. I know my nvidia program will sometimes dissapear behind login prompt, but I can use alt-tab to bring it back to foreground. There is also a win32 .dll function call to show and hide windows. I dont have my source code at the moment, but perhaps that might be the solution.
If you were successfull in presenting a GUI at login prompt, please pm me the exact details of how you accomplished this.
Last edited by Traps; April 25th, 2007 at 11:13 AM.
-
April 25th, 2007, 12:11 PM
#12
Re: Getting a programs ui to run at the login prompt
Heres what I get when running installutil.exe
C:\OnScreen\OnScreen\bin\Release>C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\In
stallUtil.exe OnScreen.exe
Microsoft (R) .NET Framework Installation utility Version 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.
Exception occurred while initializing the installation:
System.BadImageFormatException: The format of the file 'OnScreen.exe' is invalid
..
Went and googled some directions to make sure I had the right idea here.
http://www.developer.com/net/csharp/...0918_2173801_1
Was doing what that page said and still get the same error. If I got this to work doing this every time would just be evil on 200 machines that are reimaged on a 90 day basis.
-
April 25th, 2007, 12:28 PM
#13
Re: Getting a programs ui to run at the login prompt
How did you make the program? Did you use visual studio service template? Did you add the installer class to the project? You cant use installutil on any old .exe . It has to be programmed as a service.
Shows how to setup a service project in c# visual studio.
http://support.microsoft.com/kb/816169
-
April 25th, 2007, 12:33 PM
#14
Re: Getting a programs ui to run at the login prompt
http://www.codeproject.com/system/wi...on_package.asp
Programs that run when windows starts, before login, use Winlogon Notify to determine when the shell has started.. My Thinkpad Fingerprint Reader uses this to log me on using my fingerprint
-
April 25th, 2007, 12:42 PM
#15
Re: Getting a programs ui to run at the login prompt
Originally Posted by cjard
Oh man, I think this is what I've been looking for, for nearly a month now. If this launches a windows forms application, and allows for desktop interaction, then thats money in the bank for me. Further more, if I can use this to determine the user who logged in, even better!!
Thank you cjard!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|