Jump to content
xisto Community
Sign in to follow this  
darkool

Windows XP Restart File? Restart Programmatically

Recommended Posts

Anyone knows where i can find the file or files that windows use to shutdown ? i'm buiding a software to shutdown my pc where ever i'm from, its a version beta , but my main problem isn't fixed . I hope you can help me .https://s" />

Notice from microscopic^earthling:
Wrong forum. Moved to Programming.
Edited by microscopic^earthling (see edit history)

Share this post


Link to post
Share on other sites

I don't think Windows2000 calls any special Shutdown file - instead is passes some arguements to files like svchost, dllhost etc - causing all these processes to shut down one by one and then finally shut windows down. If you'd stated which language you're using to code, it'd have been a lot easier to reply to your query. On the other hand, Windows XP provides you with a file called Shutdown.exe which enables you to shut your system down. Read this Article: http://forums.xisto.com/topic/82716-topic/?findpost=1064295030

 

But you mentioned that you want this action to happen through a software which you're writing - it's extremely unwise to call or depend on external processes to perform important system tasks like this. Your program should be able to handle this itself. Here are a few links that'd help you with the coding:

 

1. VB.NET Source Code & Application Demonstrating Windows Shutdown Process

2. Shutdown - an alternative to Windows Shutdown dialog

3. A tool to perform automatic shutdown, log off or restart action

4. Remote Shutdown or Reboot with Telnet and C#

 

I've checked all the source codes on these links and they all work fine. There are samples in both VB.NET and C#.NET - and should solve your shutdown problems rightaway. :rolleyes:

 

Happy Coding !

Share this post


Link to post
Share on other sites

In short, you have to call several windows APIs.

[COLOR=green]' Constants[/COLOR]Const SE_PRIVILEGE_ENABLED As Integer = &H2Const TOKEN_QUERY As Integer = &H8Const TOKEN_ADJUST_PRIVILEGES As Integer = &H20Const SE_SHUTDOWN_NAME As String = "SeShutdownPrivilege"

[COLOR=green]' Exit Windows Constants[/COLOR]Const EWX_LOGOFF As Integer = &H0Const EWX_SHUTDOWN As Integer = &H1Const EWX_REBOOT As Integer = &H2Const EWX_FORCE As Integer = &H4Const EWX_POWEROFF As Integer = &H8Const EWX_FORCEIFHUNG As Integer = &H10

[COLOR=green]'Structure<StructLayout(LayoutKind.Sequential, Pack:=1)> _Friend Structure Luid   Public Count As Integer   Public Luid As Long   Public Attr As IntegerEnd Structure 'TokPriv1Luid

[COLOR=green]' Get Current Processes.<DllImport("kernel32.dll", ExactSpelling:=True)> _Function GetCurrentProcess() As IntPtrEnd Function

[CODE][COLOR=green]' Open Process Token.<DllImport("advapi32.dll", SetLastError:=True)> _Function OpenProcessToken(ByVal h As IntPtr, ByVal acc As Integer, ByRef phtok As IntPtr) As BooleanEnd Function

[COLOR=green]' Look up Priviledge Value. <DllImport("advapi32.dll", SetLastError:=True)> _Friend Function LookupPrivilegeValue(ByVal host As String, ByVal name As String, ByRef pluid As Long) As BooleanEnd Function

[COLOR=green]' Adjust Token Priviledges.[/COLOR]<DllImport("advapi32.dll", ExactSpelling:=True, SetLastError:=True)> _Friend Function AdjustTokenPrivileges(ByVal htok As IntPtr, ByVal disall As Boolean, ByRef newst As Luid, ByVal len As Integer, ByVal prev As IntPtr, ByVal relen As IntPtr) As BooleanEnd Function

[COLOR=green]' Exit Windows[/COLOR]<DllImport("user32.dll", ExactSpelling:=True, SetLastError:=True)> _Friend Function ExitWindowsEx(ByVal flg As Integer, ByVal rea As Integer) As BooleanEnd Function

[COLOR=green]' Exit Windows Sub[/COLOR]Private Sub DoExitWindows(ByVal flg As Integer)  Dim tp As Luid  Dim hproc As IntPtr = GetCurrentProcess()  Dim htok As IntPtr = IntPtr.Zero

[COLOR=green]  'Get a token for this process. [/COLOR]  OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, htok)  tp.Count = 1  tp.Luid = 0  tp.Attr = SE_PRIVILEGE_ENABLED

[COLOR=green]  'Get the LUID for the shutdown privilege.[/COLOR]   LookupPrivilegeValue(Nothing, SE_SHUTDOWN_NAME, tp.Luid)

[COLOR=green]   'Get the shutdown privilege for this process.[/COLOR]   AdjustTokenPrivileges(htok, False, tp, 0, IntPtr.Zero, IntPtr.Zero)

[COLOR=green]  'Exit Windows[/COLOR]  ExitWindowsEx(flg, 0)End Sub

[COLOR=green]' Shutdown[/COLOR]DoExitWindows(EWX_SHUTDOWN)[COLOR=green]' Restart[/COLOR]DoExitWindows(EWX_REBOOT Or EWX_FORCE)[COLOR=green]' Log off[/COLOR]DoExitWindows(EWX_LOGOFF)
[/code]


A site that really describes this process is https://blogs.msdn.microsoft.com/

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.