943,816 Members | Top Members by Rank

Ad:
Jan 3rd, 2008
0

Code for restart/shut down PC

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
arasten is offline Offline
17 posts
since Jan 2008
Jan 3rd, 2008
0

Re: Code for restart/shut down PC

What OS are u using? XP, Vista or before?
Reputation Points: 329
Solved Threads: 347
Senior Poster
AndreRet is offline Offline
3,700 posts
since Jan 2008
Jan 3rd, 2008
0

Re: Code for restart/shut down PC

I'm using XP
Reputation Points: 10
Solved Threads: 1
Newbie Poster
arasten is offline Offline
17 posts
since Jan 2008
Jan 4th, 2008
3

Re: Code for restart/shut down PC

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)
Reputation Points: 1182
Solved Threads: 392
Posting Sensei
Jx_Man is offline Offline
3,140 posts
since Nov 2007
Jan 4th, 2008
5

Re: Code for restart/shut down PC

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
Reputation Points: 1182
Solved Threads: 392
Posting Sensei
Jx_Man is offline Offline
3,140 posts
since Nov 2007
Jan 4th, 2008
1

Re: Code for restart/shut down PC

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]
Reputation Points: 329
Solved Threads: 347
Senior Poster
AndreRet is offline Offline
3,700 posts
since Jan 2008
Jun 27th, 2008
0

Re: Code for restart/shut down PC

Click to Expand / Collapse  Quote originally posted by Jx_Man ...
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jhaymayclow is offline Offline
5 posts
since Jun 2008
Oct 7th, 2010
0
Re: Code for restart/shut down PC
In Timer Event Make Time Interval just 1 and call any big .EXE file with shell it made user to restart his pc
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jin100 is offline Offline
1 posts
since Oct 2010
Aug 9th, 2011
0
Re: Code for restart/shut down PC
Is there code to cancel it once it starts? maybe by using cmd?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jbobby87 is offline Offline
1 posts
since Aug 2011

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Search as you type
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Password





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC