Windows won't Shutdown because of this Application

Windows won't shutdown nor logoff because of this application.

Page 1 of 1

9 Replies - 2973 Views - Last Post: 03 April 2009 - 07:05 PM Rate Topic: -----

#1 Ricendithas  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 59
  • Joined: 12-July 08

Windows won't Shutdown because of this Application

Posted 01 April 2009 - 06:18 AM

Hi, I'm new in VB.NET and I was wondering if anyone can help me with my problem?

ntfyIcon is an object NotifyIcon

    Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        e.Cancel = True
        Me.Hide()
        ntfyIcon.Visible = True
    End Sub



This is my code everytime the user attempts to close the program. However, when I try to shutdown or log off the computer, nothing happens. It turns out that this causes Windows to behave differently.

So, I am asking, can anyone help me think of a code that will not cause Windows to behave differently?

Thanks. =)

This post has been edited by Ricendithas: 01 April 2009 - 06:19 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Windows won't Shutdown because of this Application

#2 egof  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 20
  • View blog
  • Posts: 132
  • Joined: 27-March 09

Re: Windows won't Shutdown because of this Application

Posted 01 April 2009 - 01:31 PM

it doesnt look like your cleaning anything up in your code so I dont think you really need and of the form closing method. The e.Cancel=true says to the OS that your not actually going to close anything then you hide everything but didnt close it.
Was This Post Helpful? 0
  • +
  • -

#3 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Windows won't Shutdown because of this Application

Posted 01 April 2009 - 06:25 PM

Agreed. Remove all the code from the Form Closing event, that will solve your problem.
Was This Post Helpful? 0
  • +
  • -

#4 Ricendithas  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 59
  • Joined: 12-July 08

Re: Windows won't Shutdown because of this Application

Posted 02 April 2009 - 02:11 AM

so, if I am going to remove these codes, then my application will be closed. what should I do? All I want is to cancel the closing process and just hide the application. Only a password can close the application.

This post has been edited by Ricendithas: 02 April 2009 - 02:12 AM

Was This Post Helpful? 0
  • +
  • -

#5 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2251
  • View blog
  • Posts: 9,435
  • Joined: 29-May 08

Re: Windows won't Shutdown because of this Application

Posted 02 April 2009 - 04:34 AM

Form_Closing happens when the form is closing, giving you the chance to cancel it.
Form_Closed happens when the form has been closed, put your clean you code here.
Was This Post Helpful? 0
  • +
  • -

#6 Ricendithas  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 59
  • Joined: 12-July 08

Re: Windows won't Shutdown because of this Application

Posted 03 April 2009 - 05:12 AM

the application closes when I use the form_closed event. It doesn't even have any cancel property.
Was This Post Helpful? 0
  • +
  • -

#7 searockruz  Icon User is offline

  • D.I.C Regular

Reputation: 24
  • View blog
  • Posts: 460
  • Joined: 07-March 09

Re: Windows won't Shutdown because of this Application

Posted 03 April 2009 - 05:26 AM

do you simply mean disable the red x close button ?
Was This Post Helpful? 0
  • +
  • -

#8 egof  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 20
  • View blog
  • Posts: 132
  • Joined: 27-March 09

Re: Windows won't Shutdown because of this Application

Posted 03 April 2009 - 05:30 AM

You have an application that you dont want the user to be able to close but when you try to log off the machine you cant (because your app is still running). You will need need to shut your app off first or show the end user how to kill it in the task manager.
Was This Post Helpful? 0
  • +
  • -

#9 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

Re: Windows won't Shutdown because of this Application

Posted 03 April 2009 - 07:59 AM

why dont you have two forms one thats the main form the other shows uop when the user tries to close the program so in form_closing enter me.show as the last object and form2.show (form2 would have an ok button and on the ok button you would validate text in a textbox if its the password then "end" simmples :P :D :) if you dont like using the end statement then you need to build this into the form1_closing
something like this
if form2.visible = true then
goto 1
else
me.show
1:
end if



and build this into form2

ok button_ handles whatever (i dont know them off by heart)
if textbox1.text = "Password" then
'hide icons and other stuff here
Form1.close
me.close
else
msgbox ("Error Incorrect password")
textbox1.text = ""
end if



and the cancel button would just be me.close for form2!!

Have fun :)

EDIT: this would fail if the user found out the rather simple password so you would want to call it from a .dll file :) or make it something more aurkward to guess :)

This post has been edited by Asscotte: 03 April 2009 - 08:02 AM

Was This Post Helpful? 0
  • +
  • -

#10 Ricendithas  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 59
  • Joined: 12-July 08

Re: Windows won't Shutdown because of this Application

Posted 03 April 2009 - 07:05 PM

Finally, I have solved this problem. All I ever wanted is that my application won't be closed by simply clicking the X button. Instead, it will be hidden and will be placed in the system tray. It can only be closed when the user enters the correct password. However, the problem arises when I try to shutdown or logoff the computer when the application is still running. Windows starts to behave differently.

I managed to answer my own question by using this code:
Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing        
        If Me.Visible = True Then
                e.Cancel = True
                Me.Hide()
                ntfyIcon.Visible = True
        End If
End Sub



Now, it will only be closed once the user wants to shut down or logoff the computer or when the user enters the correct password.

Simple as that. Thanks for all your help guys. :)

This post has been edited by Ricendithas: 03 April 2009 - 07:08 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1