| | |
Code for restart/shut down PC
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
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 !
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.
This code Using 'Shell':
This Code Using 'Managed Code in .NET':
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)
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Call Shell("Shutdown /s") 'to shutdown Call Shell("Shutdwon /r") 'to restart Call Shell("Shutdown /l") 'to logoff Call Shell("Shutdown /a") 'to Abort
This Code Using 'Managed Code in .NET':
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
System.Diagnostics.Process.Start (Shutdown", "/s") 'to shutdown System.Diagnostics.Process.Start("Shutdown", "/r") 'to restart System.Diagnostics.Process.Start("Shutdown", "/l") 'to logoff System.Diagnostics.Process.Start("Shutdown", "/a") 'to abort
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 *
So, Please do something before post your thread.
* PM Asking will be ignored *
hi arasten...
sorry for my post before...its code for vb.net but for vb its not different
this is the code :
but its only work in xp os..
ok. all for the best
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)
Shell "shutdown -r -t 00" ' for restart Shell "shutdown -s -t 00" ' for Shutdown Shell "shutdown -l -t 00" ' for log off 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 *
So, Please do something before post your thread.
* PM Asking will be ignored *
•
•
Join Date: Jan 2008
Posts: 255
Reputation:
Solved Threads: 37
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]
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]
•
•
Join Date: Jun 2008
Posts: 5
Reputation:
Solved Threads: 0
•
•
•
•
This code Using 'Shell':
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Call Shell("Shutdown /s") 'to shutdown Call Shell("Shutdwon /r") 'to restart Call Shell("Shutdown /l") 'to logoff Call Shell("Shutdown /a") 'to Abort
This Code Using 'Managed Code in .NET':
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
System.Diagnostics.Process.Start (Shutdown", "/s") 'to shutdown System.Diagnostics.Process.Start("Shutdown", "/r") 'to restart System.Diagnostics.Process.Start("Shutdown", "/l") 'to logoff System.Diagnostics.Process.Start("Shutdown", "/a") 'to abort
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)
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.
![]() |
Similar Threads
- how do i auto-shut down windows XP? (Windows NT / 2000 / XP)
- Antivirus shut down, Cannot install other Antivirus/Antispyware (Viruses, Spyware and other Nasties)
- URGENT :: Odd Windows Booting Problem (Windows NT / 2000 / XP)
- Page cannot be displayed errors at random times.... (Web Browsers)
- Presario power supply dies when m/board plugged in:-0 (Troubleshooting Dead Machines)
- Error message, posting HijackThis log (Viruses, Spyware and other Nasties)
- Sudden shutdown and won't reboot (Windows NT / 2000 / XP)
- Authenticity Code- Same Problem - HELP (Windows 95 / 98 / Me)
- IE crippled by trojan and 'system restore'won't restore (Viruses, Spyware and other Nasties)
- Can anyone help me with a hijacked IE? (Viruses, Spyware and other Nasties)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: How to pass the text of one form to the command button's caption of another form?
- Next Thread: Adodc.recordset.update
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age append application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






