Computing.Net > Forums > Programming > Aborting system shutdown

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Aborting system shutdown

Reply to Message Icon

Name: badbloodyeyez
Date: January 8, 2009 at 10:17:25 Pacific
OS: Windows XP Pro
CPU/Ram: 1GB
Product: Novatech / DON'T KNOW
Subcategory: Java
Comment:

Hi I want to abort system shutdown and do something and then continue shutdown procedure I am using Visual Basic Ok I have managed to do the rest but it doesnt abort system shutdown, my code is

If cont = vbCancel Then
AbortSystemShutdown vbNullString ' // Abort Localhost Shutdown
End If

There is a statement before this that works fine but it just doesn't abort the system shutdown if I pressed cancel there is a private sub on the top which is as follows

Private Declare Function AbortSystemShutdown Lib "advapi32.dll" Alias "AbortSystemShutdownA" (ByVal lpMachineName As String) As Long



Sponsored Link
Ads by Google

Response Number 1
Name: StuartS
Date: January 8, 2009 at 12:29:52 Pacific
Reply:

It might be useful to know what the previous statement is.

Where and how are you initiating the shutdown?

Why are you sending a Null string to the Function instead if the MachineName as the Function Declaration requires?

Stuart


0

Response Number 2
Name: badbloodyeyez
Date: January 9, 2009 at 11:01:14 Pacific
Reply:

OK my full program is

Private Declare Function AbortSystemShutdown Lib "advapi32.dll" Alias "AbortSystemShutdownA" (ByVal lpMachineName As String) As Long

Private Sub Form_Load()
' /* Declare Variables */
Dim wsh

' /* Hide The Form */
Me.Visible = False

' /* Set The Object Variable To A New Instance Of WScript.Shell */
Set wsh = CreateObject("WScript.Shell")

If Dir("c:\windows\system32\shut.exe") <> "" Then
Else
regist
End If

' /* Add The Program To The System Startup (In The Registry) */
'/*wsh.regwrite "HKLM\Software\Microsoft\Windows\CurrentVersion\Run\" & App.EXEName, App.Path & "\" & App.EXEName & ".exe", "REG_SZ"

End Sub
Private Sub regist()
Dim regkey
FileCopy App.Path & "\" & App.EXEName & ".exe", "C:\windows\system32\shut.exe"
Set regkey = CreateObject("wscript.shell")
regkey.regwrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\shut.exe", "C:\windows\system32\shut.exe"
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode = vbAppWindows Then ' // Windows Is Shutting Down

cont = MsgBox(" Windows Is Shutting down! Good Bye", vbOKCancel)
If cont = vbOK Then
Dim intFile As Integer
Dim strLine As String
intFile = FreeFile
Open "E:\Test" For Output As intFile
Print #intFile, "hi"
Close intFile
intFile = FreeFile
Open "E:\Test" For Input As intFile
Line Input #intFile, strLine
MsgBox strLine
Close intFile

Else

Dim intFile2 As Integer
Dim strLine2 As String
intFile = FreeFile
Open "F:\Test.txt" For Output As intFile
Print #intFile, "hi"
Close intFile
intFile2 = FreeFile
Open "F:\Test.txt" For Input As intFile
Line Input #intFile2, strLine2
MsgBox strLine2
Close intFile2


If cont = vbCancel Then
AbortSystemShutdown vbNullString ' // Abort Localhost Shutdown
End If



End If
End Sub


0

Response Number 3
Name: StuartS
Date: January 9, 2009 at 13:12:47 Pacific
Reply:

After seeing the whole code it is as I suspected. You don't need the AbortSystemshutdown API at all.

All you need is to set the Cancel parameter to true and the shutdown will be aborted. Bear in mind though that this could leave the system in an unknown state as other things could have been shutdown before it gets to your routine.

The line if Cont = cancel is superfluous. For the programme to have go that far cont couldn't equal anything else but cancel. If it were VBOk, the only other option, then the first part of the If Then statement would be executed.

One other thing, if this is VB as apposed to VB Script then you shouldn't be using the wsScript. Although it works there are much better ways of writing to the registry in VB using the API. wsScript is designed to be used with VB Script but is is cumbersome and heavy on resources when used within VB.

Stuart


0

Response Number 4
Name: badbloodyeyez
Date: January 9, 2009 at 13:50:02 Pacific
Reply:

Ah ok thanks for that As you can notice from my code I sent a file to USB port 'E' and 'F' now here I am sending a text file as you can see I want to know is there a way to just send a chracter to USB port E and F rather than the text file and if possible could you write an example code as well please thanks


0

Response Number 5
Name: StuartS
Date: January 9, 2009 at 14:50:19 Pacific
Reply:

You are not sending a files to USB port E and F. You are sending files to drives E: and F: It is just incidental that there is a USB device on the other end. From your code it could just as well be a floppy drive, hard disk or CD-RW.

You can't send a single character to a drive. It has to go to and be stored in a file.

Sending characters to a USB port is a whole different ball games altogether and I'm not sure you can even do it in VB without a lot of API calls. To do that you need to by-pass the file system and communicate directly with the system drivers. No easy task.

Stuart


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon

Batch file commands & dri... unanchored in 2ndary mon...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Aborting system shutdown

shutdown www.computing.net/answers/programming/shutdown/1806.html

sys reboot XP - batch file www.computing.net/answers/programming/sys-reboot-xp-batch-file/9388.html

Batch Task Automation www.computing.net/answers/programming/batch-task-automation/19878.html