Hi, I would like to know how can I stop windows from logging off, restart or shutdown. I want to automatically pause these operations and then send a signal to USB port and then resume the shutdown, log off or restart operation. Is it possible you can help me write the code or give me some guidelines on it as I am learning VB thanks in advance

Recommended Answers

All 12 Replies

Hi,
You can abort the system shutdown using AbortSystemShutdown () win32 API. Please refer this..

Private Sub Form_QueryUnload(Cancel as Integer, UnloadMode as Integer)
if UnloadMode = vbAppWindows then ' // Windows Is Shutting Down
     ' // Instead Of This Stuff, Send Signal To USB Port
     retval = msgbox("Really Shutdown Windows", vbyesno)
     if retval = vbno then
          AbortSystemShutdown vbnullstring ' // Abort Localhost Shutdown
     end if
end if
end sub

thanx for that and is it possible to autorun this application when the windows start-up I know I can place the shourcut in the start-up folder but can I do it with code and also I would like this application to run invisibly so that the user can't see the window!!

Compile it... put the EXE in the folder that you want to run it from, and then run it.

thank you very much I really appriciate it thanks and can you plz tell me if I have to write the name of the exe file in the following code
wsh.regwrite "HKLM\Software\Microsoft\Windows\CurrentVersion\Run\" & App.EXEName, App.Path & "\" & App.EXEName & ".exe", "REG_SZ"

you know were it says App do I have to write the name of the exe file and what I have to write in the Path? and lastly how would I send the signal to USB if for example I want to send the backslash '\' to all USB ports what I have to write thankx

As far as needing to change the wsh.regwrite line, no. It is fine the way it is... basically, app.exename is sort of like a variable that contains the name of the program... so, if someone changed the exe name from reprieve.exe to fun.exe, then app.exename would become fun. Then, app.path literally denotes where on the directory structure the file is... so if the path was: c:\windows\reprieve.exe, then when you run it, app.path would become c:\windows.

As far as sending signals to a USB Port....This is a pretty good start. Some devices hooked to a USB port have a pseudo-serial interface, so it should work with those.... as far as like, sending raw data.... the link is your best bet.

Good Luck.
Comatose.

hey its still not working I done what you expalined me my .exe file is shut.exe and the rest is the same as it was in you file I have attached the file you can see what I changed everything else works perfect except it does not starts when I log on the computer instead it open documents folder I dont know why plz check it thanx

App.path and App.exename need to stay there.

Sorry I don't understand you see I am just learning VB and I don't really understand what you mean you said that teh App.EXEName and App.path needs to stay there then how would I put the name of the path and the exe name in the code?

OK thanks I managed to do it thanks for your help and the website you gave me to send signal to USB port it is a big code if I copy it will it work? and have nice year

Private Sub Form_QueryUnload(Cancel as Integer, UnloadMode as Integer)
if UnloadMode = vbAppWindows then ' // Windows Is Shutting Down
     ' // Instead Of This Stuff, Send Signal To USB Port
     retval = msgbox("Really Shutdown Windows", vbyesno)
     if retval = vbno then
          AbortSystemShutdown vbnullstring ' // Abort Localhost Shutdown
     end if
end if
end sub

i tried ur method ,while system logoff it's asking message, if i click the button NO then also it's getting logoff why?

Private Sub Form_QueryUnload(Cancel as Integer, UnloadMode as Integer)
if UnloadMode = vbAppWindows then ' // Windows Is Shutting Down
     ' // Instead Of This Stuff, Send Signal To USB Port
     retval = msgbox("Really Shutdown Windows", vbyesno)
     if retval = vbno then
          AbortSystemShutdown vbnullstring ' // Abort Localhost Shutdown
     end if
end if
end sub

i tried ur method ,while system logoff it's asking message, if i click the button NO then also it's getting logoff why?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.