none
Encountered Privillege not held exception when rebooting the server in .net4.0 framewrk RRS feed

  • Question

  • Hi All,

    I tried WMI method to reboot the server in .net 4.0 framework.But it is giving me system.management exception "Privillege not held".In .net 3.5 it worked as expected ,i was able to reboot the server with the same code with no exceptions.

    ---------

    server not rebootedSystem.Management.ManagementException: Privilege not held.

       at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
       at System.Management.ManagementObject.InvokeMethod(String methodName, ManagementBaseObject inParameters, InvokeMethodOptions options)  

    ---------

    below is the code which i tried in visual studio 2010in .net 4.0 version.

    ManagementBaseObject mboShutdown = null;
                    ManagementClass mcWin32 = new ManagementClass("Win32_OperatingSystem");
                    mcWin32.Get();
                    // You can't shutdown without security
                    mcWin32.Scope.Options.EnablePrivileges = true;
    
                    ManagementBaseObject mboShutdownParams = mcWin32.GetMethodParameters("Win32Shutdown");
                    // Flag 1 means we want to shut down the system
                    mboShutdownParams["Flags"] = "2";
                    mboShutdownParams["Reserved"] = "0";
                    foreach (ManagementObject manObj in mcWin32.GetInstances())
                    {
                        mboShutdown = manObj.InvokeMethod("Win32Shutdown", mboShutdownParams, null);
                   

    I tried even adding the user  to shutdown,force shutdown options in user rights assignment in local policies.Even then its giving the same exception.

    Could anyone figure this out!!!!!

    Thanks......

    Ravi.

    Thursday, January 24, 2013 10:27 AM

All replies

  • Hi Ravi,

    Welcome to the MSDN Forum.

    >>In .net 3.5 it worked as expected

    Do you try the 4.0 on the same environment of 3.5, and just compile the same code again with the .net framework 4.0?

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, January 25, 2013 3:08 AM
    Moderator
  • Yes,Mike.I tried the same environment for .NET Framework 4.0 also.

    In fact I also tested in my Local machine which is having VS 2008 and VS 2010.

    The same code worked well in VS 2008 and its giving the exception Privilege not held when I did the sample in VS 2010.

    In server also same thing is happening.

    Thanks,

    Ravi

    Friday, January 25, 2013 1:39 PM
  • Hi Ravi,

    I am trying to involve some other one into this case, it will take some time, wait it patiently, please.

    Thank you.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, January 28, 2013 5:17 AM
    Moderator