Posts: 1,481
Threads: 122
Joined: Oct 2009
Reputation:
25
11-04-2009, 01:06 AM
(This post was last modified: 11-04-2009, 01:08 AM by Extasey.)
I made a program to shutdown my computer. It has two buttons, one to shut it down, the other to exit the program.
When I run it out of visual basic, everything runs fine. When I compile it, it spawns a random button which, when clicked, opens another copy of the program (shutdown.exe) and then halts.
Here is the code used on the shutdown button:
Code: Private Sub Picture1_Click(Index As Integer)
'Shutdown the computer
Shell ("shutdown.exe -s")
End Sub
Is this my dodgey copy of VB or an error?
Maybe someone else could compile for me?
Posts: 106
Threads: 10
Joined: Oct 2009
Reputation:
3
Maybe you could post your full source code ( Unless you dont want any one having it ) So they can examine more closely.
Posts: 1,481
Threads: 122
Joined: Oct 2009
Reputation:
25
Lol nah, I don't care! here it is:
Form:
Code: Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_STYLE = (-16)
Private Const WS_CAPTION = &HC00000
Option Explicit
Dim TLevel As Integer
Private Sub Command1_Click()
Timer1.Enabled = False
Timer2.Enabled = True
End Sub
Private Sub Form_Load()
Timer2.Enabled = False
TLevel = 5
TransForm Me, Val(TLevel)
End Sub
Private Sub picture2_Click(Index As Integer)
End
End Sub
Private Sub Timer1_Timer()
TLevel = TLevel + 5
TransForm Me, Val(TLevel)
If TLevel = 255 Then
Timer1.Enabled = False
End If
End Sub
Private Sub Timer2_Timer()
TLevel = TLevel - 5
TransForm Me, Val(TLevel)
If TLevel = 5 Then
Unload Me
End If
End Sub
Private Sub Command99_Click()
Dim lStyle As Long
lStyle = GetWindowLong(Me.hWnd, GWL_STYLE)
SetWindowLong Me.hWnd, GWL_STYLE, lStyle And Not WS_CAPTION
End Sub
Private Sub Picture1_Click(Index As Integer)
'Shutdown the computer
Shell ("shutdown.exe -s")
'close program
End
End Sub
Module (for fade effect):
Code: Option Explicit
Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_LAYERED = &H80000
Private Const LWA_ALPHA = &H2
Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hWnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" (ByVal hWnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) _
As Long
Private Declare Function SetLayeredWindowAttributes Lib _
"user32" (ByVal hWnd As Long, ByVal crKey As Long, _
ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Public Function TransForm(Form As Form, TransLevel As Byte) As Boolean
SetWindowLong Form.hWnd, GWL_EXSTYLE, WS_EX_LAYERED
SetLayeredWindowAttributes Form.hWnd, 0, TransLevel, LWA_ALPHA
TransForm = Err.LastDllError = 0
End Function
Posts: 99
Threads: 12
Joined: Oct 2009
Reputation:
3
11-05-2009, 01:25 PM
(This post was last modified: 11-05-2009, 01:27 PM by dunlop03.)
Just use this:
Private Sub btnShutdown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShutdown.Click
System.Diagnostics.Process.Start("shutdown", "-s -t 00")
'This will make the computer Shutdown
End Sub
Private Sub btnRestart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRestart.Click
System.Diagnostics.Process.Start("shutdown", "-r -t 00")
'This will make the computer Restart
End Sub
Private Sub btnLogOff_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogOff.Click
System.Diagnostics.Process.Start("shutdown", "-l -t 00")
'This will make the computer Log Off
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
End
'This will make the program to terminate(end the program)
End Sub
Change "00" to "1000" , and it will execute your command after 1 minute
Posts: 1,481
Threads: 122
Joined: Oct 2009
Reputation:
25
11-05-2009, 11:37 PM
(This post was last modified: 11-05-2009, 11:58 PM by Extasey.)
Appreciated... +Rep
Turns out it was my compiler... having issues with that program...
Works fine now :S Made a restart one and it works fine!
Posts: 99
Threads: 12
Joined: Oct 2009
Reputation:
3
Np m8 , hope you got it working
Posts: 106
Threads: 10
Joined: Oct 2009
Reputation:
3
Lol Vorfin, I see your post made it into the rite thread but.
Posts: 1,481
Threads: 122
Joined: Oct 2009
Reputation:
25
(11-06-2009, 07:31 AM)Fail Ninja Wrote: Lol Vorfin, I see your post made it into the rite thread but.
:S
Posts: 106
Threads: 10
Joined: Oct 2009
Reputation:
3
Huh? Im also confused. Vorfin posted the code for a fade in application in here. But he must have deleted his post.
Posts: 1,481
Threads: 122
Joined: Oct 2009
Reputation:
25
Haha, its in the other thread now
|