What am i doing wrong in this code? 
Author Message
 What am i doing wrong in this code?

I am trying to restart my computer using CSharp
----------------------------------------------------------------------

using System;
using System.Runtime.InteropServices;

class Test
{
 [DllImport("User32.dll")]
 public static extern bool ExitWindowsEx(uint uFlag, long lReason);

 public static void Main()
 {
  ExitWindowsEx(2,    // 2 for EWX_REBOOT
              0);

 }

Quote:
}

----------------------------------------------------------------------------
----

But it doesnt seem to work, it compiles ok/. I am on WinXp Pro.

Thanks in Advance.

Gavi



Sun, 14 Nov 2004 01:34:34 GMT  
 What am i doing wrong in this code?
I just read MSDN documentation for ExitWindowsEx function

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysi...
tdown_3ago.asp

It says the calling process must use the AdjustTokenPrivileges function to
enable the SE_SHUTDOWN_NAME privilege. Is there a way do this in C#??

Thanks,

Gavi


Quote:
> I am trying to restart my computer using CSharp
> ----------------------------------------------------------------------

> using System;
> using System.Runtime.InteropServices;

> class Test
> {
>  [DllImport("User32.dll")]
>  public static extern bool ExitWindowsEx(uint uFlag, long lReason);

>  public static void Main()
>  {
>   ExitWindowsEx(2,    // 2 for EWX_REBOOT
>               0);

>  }

> }
> --------------------------------------------------------------------------
--
> ----

> But it doesnt seem to work, it compiles ok/. I am on WinXp Pro.

> Thanks in Advance.

> Gavi



Sun, 14 Nov 2004 01:57:26 GMT  
 What am i doing wrong in this code?
long in C# is 64 bits; use int instead.

--
Visit the C# product team at http://www.gotdotnet.com/team/csharp

This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> I am trying to restart my computer using CSharp
> ----------------------------------------------------------------------

> using System;
> using System.Runtime.InteropServices;

> class Test
> {
>  [DllImport("User32.dll")]
>  public static extern bool ExitWindowsEx(uint uFlag, long lReason);

>  public static void Main()
>  {
>   ExitWindowsEx(2,    // 2 for EWX_REBOOT
>               0);

>  }

> }
> --------------------------------------------------------------------------
--
> ----

> But it doesnt seem to work, it compiles ok/. I am on WinXp Pro.

> Thanks in Advance.

> Gavi



Sun, 14 Nov 2004 02:08:19 GMT  
 What am i doing wrong in this code?
Nope,

Still Does not work. I changed it to int. I think it has something to do
with Permissions.
Any ideas??

Thanks,

Gavi



Quote:
> long in C# is 64 bits; use int instead.

> --
> Visit the C# product team at http://www.gotdotnet.com/team/csharp

> This posting is provided "AS IS" with no warranties, and confers no
rights.



> > I am trying to restart my computer using CSharp
> > ----------------------------------------------------------------------

> > using System;
> > using System.Runtime.InteropServices;

> > class Test
> > {
> >  [DllImport("User32.dll")]
> >  public static extern bool ExitWindowsEx(uint uFlag, long lReason);

> >  public static void Main()
> >  {
> >   ExitWindowsEx(2,    // 2 for EWX_REBOOT
> >               0);

> >  }

> > }

> --------------------------------------------------------------------------
> --
> > ----

> > But it doesnt seem to work, it compiles ok/. I am on WinXp Pro.

> > Thanks in Advance.

> > Gavi



Sun, 14 Nov 2004 02:29:22 GMT  
 What am i doing wrong in this code?
You'll have to DllImport the API's needed to change the process token. Look
at the sampl in the doc's (the C++ sample) and see if you can translate it
into C#. It's the only way I can think of.

Arild


Quote:
> I just read MSDN documentation for ExitWindowsEx function

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysi...
Quote:
> tdown_3ago.asp

> It says the calling process must use the AdjustTokenPrivileges function to
> enable the SE_SHUTDOWN_NAME privilege. Is there a way do this in C#??

> Thanks,

> Gavi



> > I am trying to restart my computer using CSharp
> > ----------------------------------------------------------------------

> > using System;
> > using System.Runtime.InteropServices;

> > class Test
> > {
> >  [DllImport("User32.dll")]
> >  public static extern bool ExitWindowsEx(uint uFlag, long lReason);

> >  public static void Main()
> >  {
> >   ExitWindowsEx(2,    // 2 for EWX_REBOOT
> >               0);

> >  }

> > }

> --------------------------------------------------------------------------
> --
> > ----

> > But it doesnt seem to work, it compiles ok/. I am on WinXp Pro.

> > Thanks in Advance.

> > Gavi



Sun, 14 Nov 2004 02:46:47 GMT  
 What am i doing wrong in this code?
Or you have to call AdjustTokenPrivileges to enable SeShutdownPrivilege....
Or you can use the System.Management classes and WMI...
Here is a sample using the Management classes:

using System.Management;
....
....
try
   {
    SelectQuery query = new SelectQuery("select name from Win32_OperatingSystem where primary=true");
    ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
    foreach(ManagementObject os in searcher.Get())
    {
     // Enable SeShutdownPrivilege, the calling process must have SeShutdownPrivilege !!!!
     os.Scope.Options.EnablePrivileges = true;
     ManagementBaseObject outParams = os.InvokeMethod("Reboot", null, null);
    }
   }
   catch (Exception e)
   {
    Console.WriteLine(e.ToString());
   }
  }
....

Willy.

Quote:

> Nope,

> Still Does not work. I changed it to int. I think it has something to do
> with Permissions.
> Any ideas??

> Thanks,

> Gavi



> > long in C# is 64 bits; use int instead.

> > --
> > Visit the C# product team at http://www.gotdotnet.com/team/csharp

> > This posting is provided "AS IS" with no warranties, and confers no
> rights.



> > > I am trying to restart my computer using CSharp
> > > ----------------------------------------------------------------------

> > > using System;
> > > using System.Runtime.InteropServices;

> > > class Test
> > > {
> > >  [DllImport("User32.dll")]
> > >  public static extern bool ExitWindowsEx(uint uFlag, long lReason);

> > >  public static void Main()
> > >  {
> > >   ExitWindowsEx(2,    // 2 for EWX_REBOOT
> > >               0);

> > >  }

> > > }

> > --------------------------------------------------------------------------
> > --
> > > ----

> > > But it doesnt seem to work, it compiles ok/. I am on WinXp Pro.

> > > Thanks in Advance.

> > > Gavi



Sun, 14 Nov 2004 03:01:08 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Code: What am I doing wrong?

2. what am i doing wrong?

3. what am I doing wrong here?

4. What am I doing wrong?

5. What am I doing wrong?

6. WHAT AM I DOING WRONG?

7. what am i doing wrong!

8. What am I doing wrong (part 2)

9. What am i doing wrong?

10. What am I doing wrong here

11. Help I cant C what I am doing wrong

12. What am I doing Wrong?

 

 
Powered by phpBB® Forum Software