Nov 22, 2009

Windows XP Restart File? Restart Programmatically

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Programming General > BASIC / Visual Basic (.NET)

Windows XP Restart File? Restart Programmatically

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

Notice from microscopic^earthling:
Wrong forum. Moved to Programming.

Comment/Reply (w/o sign-up)

miCRoSCoPiC^eaRthLinG
    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://www.astahost.com/Shut-Down-Restart-...File-t3715.html

    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. smile.gif

Happy Coding !

 

 

 


Comment/Reply (w/o sign-up)

tansqrx
In short, you have to call several windows APIs.

CODE
[COLOR=green]' Constants[/COLOR]
Const SE_PRIVILEGE_ENABLED As Integer = &H2
Const TOKEN_QUERY As Integer = &H8
Const TOKEN_ADJUST_PRIVILEGES As Integer = &H20
Const SE_SHUTDOWN_NAME As String = "SeShutdownPrivilege"


CODE
[COLOR=green]' Exit Windows Constants[/COLOR]
Const EWX_LOGOFF As Integer = &H0
Const EWX_SHUTDOWN As Integer = &H1
Const EWX_REBOOT As Integer = &H2
Const EWX_FORCE As Integer = &H4
Const EWX_POWEROFF As Integer = &H8
Const EWX_FORCEIFHUNG As Integer = &H10


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


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


CODE
[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 Boolean
End Function


CODE
[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 Boolean
End Function


CODE
[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 Boolean
End Function


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


CODE
[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


CODE
[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


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


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


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


CODE
[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 http://blogs.msdn.com/brad_mccabe/archive/.../02/383542.aspx

Comment/Reply (w/o sign-up)

ViRuaL
OR you could just SHELL Shutdown.exe... Heh... Heh... Heh.......

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : windows, xp, restart, file, restart, programmatically

  1. Vb.net And Windows Live Messenger Plugin
    (3)
  2. New Features In Visual Studio 2005 Windows Forms
    (1)
    i dunno if all of u are by now well versed with the new exciting features in visual studio 2005
    forms, but for me this article was enlightening. for the benifit of others who wre in the dark like
    me.... New Features in Visual Studio 2005 Windows Forms QUOTE The little voice in my head
    shouted "Don't do it! Don't do it!" as I contemplated using the worn out cliché "Good things
    come to those who wait" to describe the experience of designing Windows applications with Visual
    Studio 2005. However, that cliché accurately communicates the idea that building Wi....
  3. VB.NET: How To Edit & -90degree Rotate Text In Ms Word File ?
    Need reply urgently (3)
    How to open a word file from VB.net? also need to write data in this file with -90 degree rotation.
    just want to add some data in word file through VB.Net but data is needed to be written in -90
    degree rotation format....
  4. Visual Basic: Change Your Start Button Text! (XP)
    Windows XP ONLY (17)
    Personally, I love this program I made for myself. What the following code will allow you to do is
    change the text of your start button (Duh). You can make it whatever you want, your name, a hobby,
    or even do some extra programming and get it to randomly cycle through captions every 30 seconds or
    so /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />. Here is all
    the code you'll need: CODE Private Const WM_SETTEXT = &HC Private Const WM_GETTEXT = &HD
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpC....
  5. .NET XML Configuration File
    (4)
    Does anyone know an easy way to create an XML configuration file with Visual Basic.NET? I have a
    program that I have been working on and I would like to save certain data between sessions. I have
    heard from many people that XML is the way to go. Are there any good FAQ's....

    1. Looking for windows, xp, restart, file, restart, programmatically

See Also,

*SIMILAR VIDEOS*
Searching Video's for windows, xp, restart, file, restart, programmatically
advertisement



Windows XP Restart File? Restart Programmatically

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com