Hello guys,
Can someone gv me a Code, to a shutdown script automaticall ? i 'm a newbie, just created a billing software interface.. i created my menus.. File---->> this want i want if any of client..clicks on File menu and click on shutdown.. i want the system to shutdown immediatley and another code if the User wanna Restart the computer by click on File----> Restart. it should restart immedialty..

Lets Codes that i needed is


Thanks in advanced

Method 1:
In your project, add a new standard module, and put this in it:

public Declare Function ExitWindowsEx Lib "user32.dll" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long

public const EWX_FORCE = 4
public const EWX_LOGOFF = 0
public const EWX_POWEROFF = 8
public const EWX_REBOOT = 2
public const EWX_SHUTDOWN = 1

public function Shutdown_Windows
     Dim retval As Long  ' return value
     retval = ExitWindowsEx(EWX_SHUTDOWN Or EWX_FORCE, 0)
     Shutdown_Windows = retval
end sub

public function Reboot_Windows
     Dim retval As Long  ' return value
     retval = ExitWindowsEx(EWX_REBOOT Or EWX_FORCE, 0)
     Shutdown_Windows = retval
end sub

Then In Your File Menu, You can use it like this:

retval = Shutdown_Windows()

Or To Reboot The System:

retval = Reboot_Windows()

Method 2:
Now, I'm not sure which version of windows you will be running this app on. An alternative method to using the API, is that if you are using a later version of windows, such as XP, and I think Win2k Also, There is a command for shutting down the system from the command line. You could use this in your app, if it will be used only on later versions of windows:

To Shutdown:

retval = shell("shutdown.exe -s", vbhide)

And To Reboot:

retval = shell("shutdown.exe -r", vbhide)

Wow, that was a bit long winded! I hope one of these methods works for you, please post and let us know how it turns out.