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 !

What OS are u using? XP, Vista or before?

I'm using XP

This code Using 'Shell':

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':

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)

commented: Wonderful:) +1
commented: Great Code :) +1

hi arasten...
sorry for my post before...its code for vb.net but for vb its not different
this is the code :

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

commented: Great Code +1
commented: works... +1
commented: nice code +1
commented: Good +1
commented: Worked :) +1

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
commented: Nice Post +1

This code Using 'Shell':

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':

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)

(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.

In Timer Event Make Time Interval just 1 and call any big .EXE file with shell it made user to restart his pc

Is there code to cancel it once it starts? maybe by using cmd?

Hi there , Just about to finish the app but i was wondering if you could help me with this please
I'm using the managed Codes and what i want to do is , i want to make a window or an alarm appear for example 15 seconds before let's say it will shutdown
could you help me please ?
thanks

how to force shut down??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.