User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 426,442 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,213 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums
Views: 1788 | Replies: 1
Reply
Join Date: May 2005
Posts: 4
Reputation: developerszone is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
developerszone developerszone is offline Offline
Newbie Poster

VB Newbie Help pls

  #1  
May 26th, 2005
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

SHUTDOWN
RESTART

Thanks in advanced
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation: Comatose is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 108
Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Moderator

Re: VB Newbie Help pls

  #2  
May 26th, 2005
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Visual Basic 4 / 5 / 6 Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum

All times are GMT -4. The time now is 2:51 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC