Forums
New posts
Search forums
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
C# Community
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
VB.NET
Deployment
How to make only one instance of a program to run?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="sonasivas, post: 29758, member: 6514"] [FONT=Courier, Monospaced][FONT=Courier New]Hi, [/FONT] I have created a vb.net windows application. I finished creating setup project and installtion. Now, i realized that i want to include this option to my application, like, when the application is already running in the desktop(minimised), another same application shouldn't be opened. For this i used this code: Inside Class: ------------------------- Public Sub New() MyBase.New() If InstanceRunning(False) = True Then Dim ans As String = MsgBox("The application is already running in the desktop") Application.Exit() Application.Run() End If GC.KeepAlive(oMutex) End Sub Private oMutex As Mutex Private Function InstanceRunning(ByVal UserContex As Boolean) As Boolean Dim progid As String = "{4C91B499-109B-42c8-B68E-E125F321EED6}" Dim createdNew As Boolean oMutex = New Mutex(False, String.Concat(progid, CStr(IIf(UserContex, System.Environment.UserName, "")))) If oMutex.WaitOne(0, False) = False Then oMutex.Close() Return True End End If End Function ---------------------------------------------------- This is working perfect. If i try to open a second application, it will give the message that "its alreday opened". But, what i want is , after this error message, i want my first application(thats minimised in the desktop) to get popped up infront of the user in the screen. I tried some possibilities like: Me.WindowState = FormWindowState.Maximized Me.ActiveForm.Show() .focus() etc..etc... but, nothing is working... i saw something like the following code from net ----------------------------------------------------------------------------------------: [COLOR=blue][FONT='Courier New']Public[/FONT][/COLOR][FONT='Courier New'] [COLOR=blue]Enum[/COLOR] ShowWindowConstants[/FONT] [FONT='Courier New'] SW_HIDE = 0[/FONT] [FONT='Courier New'] SW_SHOWNORMAL = 1[/FONT] [FONT='Courier New'] SW_NORMAL = 1[/FONT] [FONT='Courier New'] SW_SHOWMINIMIZED = 2[/FONT] [FONT='Courier New'] SW_SHOWMAXIMIZED = 3[/FONT] [FONT='Courier New'] SW_MAXIMIZE = 3[/FONT] [FONT='Courier New'] SW_SHOWNOACTIVATE = 4[/FONT] [FONT='Courier New'] SW_SHOW = 5[/FONT] [FONT='Courier New'] SW_MINIMIZE = 6[/FONT] [FONT='Courier New'] SW_SHOWMINNOACTIVE = 7[/FONT] [FONT='Courier New'] SW_SHOWNA = 8[/FONT] [FONT='Courier New'] SW_RESTORE = 9[/FONT] [FONT='Courier New'] SW_SHOWDEFAULT = 10[/FONT] [FONT='Courier New'] SW_FORCEMINIMIZE = 11[/FONT] [FONT='Courier New'] SW_MAX = 11[/FONT] [COLOR=blue][FONT='Courier New']End[/FONT][/COLOR][FONT='Courier New'] [COLOR=blue]Enum[/COLOR][/FONT] <DllImport("User32.dll")> _ Public Shared Function ShowWindowAsync(ByVal hWnd As IntPtr, ByVal swCommand As Integer) As Integer End Function <STAThread()> _ Public Shared Sub Main() Dim RunningProcesses As Process() = Process.GetProcessesByName("SingletonApp") 'Change the name above to suit your application If (RunningProcesses.Length = 1) Then Application.Run(New Form1) Else ShowWindowAsync(RunningProcesses(0).MainWindowHandle, ShowWindowConstants.SW_SHOWMINIMIZED) ShowWindowAsync(RunningProcesses(0).MainWindowHandle, ShowWindowConstants.SW_RESTORE) End If End Sub --------------------------------------------------------- But, this is not working.. Its telling error with the line: ShowWindowAsync(RunningProcesses(0).MainWindowHandle, ShowWindowConstants.SW_SHOWMINIMIZED) how to set it right? or is there any other way to maximize my first application?? thnx, Priya [/FONT] [/QUOTE]
Insert quotes…
Verification
Post reply
VB.NET
Deployment
How to make only one instance of a program to run?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top
Bottom