Code for restart/shut down PC

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jan 2008
Posts: 17
Reputation: arasten is an unknown quantity at this point 
Solved Threads: 1
arasten's Avatar
arasten arasten is offline Offline
Newbie Poster

Code for restart/shut down PC

 
0
  #1
Jan 3rd, 2008
I made a program that makes someone think his desktop cleaned up, its just for fun and make me learn a littel bit of codes because i'm still a beginner in programming i'm 16 years old in high school grade 11 so i wanna learn more codes because at school the teacher doesn't give us lots of codes because i'm in IT major so in grade 10 we took A+ and grade 11 we are taking programming, DB, and in grade 12 we'll study networking i know that 3 years aren't enough, but we are not studying the whole major because IT is a big major so every year we study something else to decide which major are we going to study in college and i liked the programming so i wanna learn more to prove my self...anyways here is the program download it and take a look on it. http://www.mediafire.com/?autjb3fznrg

please help me with the restart and shut down PC code and if you can teach me a code that disables the program from task manager that would be nice ^_^

and oh yeah i want the code to be after the msgbox i.e when the you click on start it shows you a msgbox and once you click on "ok" the computer restarts or shuts down...



JUST TO AWARE YOU, YOU WONT BE ABLE TO CLOSE THE PROGRAM BY RIGHT CLICK ON IT AND CLOSE OR CLICKING ON "x" ON THE TOP OF THE FORM...YOU'LL HAVE TO USE TASK MANAGER TO END TASK !
Last edited by arasten; Jan 3rd, 2008 at 11:14 am.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 255
Reputation: AndreRet is an unknown quantity at this point 
Solved Threads: 37
AndreRet AndreRet is offline Offline
Posting Whiz in Training

Re: Code for restart/shut down PC

 
0
  #2
Jan 3rd, 2008
What OS are u using? XP, Vista or before?
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 17
Reputation: arasten is an unknown quantity at this point 
Solved Threads: 1
arasten's Avatar
arasten arasten is offline Offline
Newbie Poster

Re: Code for restart/shut down PC

 
0
  #3
Jan 3rd, 2008
I'm using XP
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: Code for restart/shut down PC

 
3
  #4
Jan 4th, 2008
This code Using 'Shell':
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Call Shell("Shutdown /s") 'to shutdown
  2.  
  3. Call Shell("Shutdwon /r") 'to restart
  4.  
  5. Call Shell("Shutdown /l") 'to logoff
  6.  
  7. Call Shell("Shutdown /a") 'to Abort

This Code Using 'Managed Code in .NET':
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. System.Diagnostics.Process.Start (Shutdown", "/s") 'to shutdown
  2.  
  3. System.Diagnostics.Process.Start("Shutdown", "/r") 'to restart
  4.  
  5. System.Diagnostics.Process.Start("Shutdown", "/l") 'to logoff
  6.  
  7. System.Diagnostics.Process.Start("Shutdown", "/a") 'to abort
  8.  

Choose the one as u like..
The code in my post its a standard command...
You can add the function with more argument like described below:
to shutdown remote machine, add the argument ' /m MyRemoteMachineName' or
to make process delay, add the argument ' /t nn' with 'nn' is number of second eg: Call Shell("Shutdown /s /m upstaircomputer /t 30") 'it will shutdown the upstair computer in 30 second
if you want to know another argument, type shutdown /? in command prompt window

by - risky k (owner)
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: Code for restart/shut down PC

 
5
  #5
Jan 4th, 2008
hi arasten...
sorry for my post before...its code for vb.net but for vb its not different
this is the code :
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Shell "shutdown -r -t 00" ' for restart
  2. Shell "shutdown -s -t 00" ' for Shutdown
  3. Shell "shutdown -l -t 00" ' for log off
  4. Shell "shutdown -a -t 00" ' for abort

but its only work in xp os..
ok. all for the best
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 255
Reputation: AndreRet is an unknown quantity at this point 
Solved Threads: 37
AndreRet AndreRet is offline Offline
Posting Whiz in Training

Re: Code for restart/shut down PC

 
1
  #6
Jan 4th, 2008
THE FOLLOWING SHOULD CLARIFY ALL.....

If this works for you please reply so.....

Thanks.

['5 command buttons:
'cmdRestart; cmdLogOff; cmdForceLogOff; cmdShutdown; cmdForceShutdown

Option Explicit
Private Const EWX_LogOff As Long = 0
Private Const EWX_SHUTDOWN As Long = 1
Private Const EWX_REBOOT As Long = 2
Private Const EWX_FORCE As Long = 4
Private Const EWX_POWEROFF As Long = 8


Private Declare Function ExitWindowsEx Lib "user32" _
(ByVal dwOptions As Long, _
ByVal dwReserved As Long) As Long

Private Type LUID
UsedPart As Long
IgnoredForNowHigh32BitPart As Long
End Type

Private Type LUID_AND_ATTRIBUTES
TheLuid As LUID
Attributes As Long
End Type
Private Type TOKEN_PRIVILEGES
PrivilegeCount As Long
TheLuid As LUID
Attributes As Long
End Type

Private Declare Function GetCurrentProcess Lib "kernel32" () As Long

Private Declare Function OpenProcessToken Lib "advapi32" _
(ByVal ProcessHandle As Long, _
ByVal DesiredAccess As Long, _
TokenHandle As Long) As Long


Private Declare Function LookupPrivilegeValue Lib "advapi32" _
Alias "LookupPrivilegeValueA" _
(ByVal lpSystemName As String, _
ByVal lpName As String, _
lpLuid As LUID) As Long

Private Declare Function AdjustTokenPrivileges Lib "advapi32" _
(ByVal TokenHandle As Long, _
ByVal DisableAllPrivileges As Long, _
NewState As TOKEN_PRIVILEGES, _
ByVal BufferLength As Long, _
PreviousState As TOKEN_PRIVILEGES, _
ReturnLength As Long) As Long

Private Declare Sub SetLastError Lib "kernel32" _
(ByVal dwErrCode As Long)

Private Sub AdjustToken()

Const TOKEN_ADJUST_PRIVILEGES = &H20
Const TOKEN_QUERY = &H8
Const SE_PRIVILEGE_ENABLED = &H2

Dim hdlProcessHandle As Long
Dim hdlTokenHandle As Long
Dim tmpLuid As LUID
Dim tkp As TOKEN_PRIVILEGES
Dim tkpNewButIgnored As TOKEN_PRIVILEGES
Dim lBufferNeeded As Long

SetLastError 0

hdlProcessHandle = GetCurrentProcess()

OpenProcessToken hdlProcessHandle, _
(TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY), hdlTokenHandle

LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid

tkp.PrivilegeCount = 1
tkp.TheLuid = tmpLuid
tkp.Attributes = SE_PRIVILEGE_ENABLED


AdjustTokenPrivileges hdlTokenHandle, _
False, _
tkp, _
Len(tkpNewButIgnored), _
tkpNewButIgnored, _
lBufferNeeded
End Sub

Private Sub cmdForceShutdown_Click()
AdjustToken
ExitWindowsEx (EWX_SHUTDOWN Or EWX_FORCE), &HFFFF
End Sub

Private Sub cmdLogoff_Click()
ExitWindowsEx (EWX_LogOff), &HFFFF
End Sub

Private Sub cmdForceLogoff_Click()
ExitWindowsEx (EWX_LogOff Or EWX_FORCE), &HFFFF
End Sub

Private Sub cmdRestart_Click()
AdjustToken
ExitWindowsEx (EWX_REBOOT), &HFFFF
End Sub

Private Sub cmdShutdown_Click()
AdjustToken
ExitWindowsEx (EWX_SHUTDOWN), &HFFFF
End Sub

Private Sub Form_Load()

End Sub]
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 5
Reputation: jhaymayclow is an unknown quantity at this point 
Solved Threads: 0
jhaymayclow jhaymayclow is offline Offline
Newbie Poster

Re: Code for restart/shut down PC

 
0
  #7
Jun 27th, 2008
Originally Posted by Jx_Man View Post
This code Using 'Shell':
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Call Shell("Shutdown /s") 'to shutdown
  2.  
  3. Call Shell("Shutdwon /r") 'to restart
  4.  
  5. Call Shell("Shutdown /l") 'to logoff
  6.  
  7. Call Shell("Shutdown /a") 'to Abort

This Code Using 'Managed Code in .NET':
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. System.Diagnostics.Process.Start (Shutdown", "/s") 'to shutdown
  2.  
  3. System.Diagnostics.Process.Start("Shutdown", "/r") 'to restart
  4.  
  5. System.Diagnostics.Process.Start("Shutdown", "/l") 'to logoff
  6.  
  7. System.Diagnostics.Process.Start("Shutdown", "/a") 'to abort
  8.  

Choose the one as u like..
The code in my post its a standard command...
You can add the function with more argument like described below:
to shutdown remote machine, add the argument ' /m MyRemoteMachineName' or
to make process delay, add the argument ' /t nn' with 'nn' is number of second eg: Call Shell("Shutdown /s /m upstaircomputer /t 30") 'it will shutdown the upstair computer in 30 second
if you want to know another argument, type shutdown /? in command prompt window

by - risky k (owner)
(shell("shutdown -m \\PC04 -r"))

I type this code in VB2008 but nothing happen it just open a command promt look alike.
PC04 has not been shutted down .pls help me i wanna try this program.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC