Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. C# Code works under win2000 but not XP

C# Code works under win2000 but not XP

Scheduled Pinned Locked Moved C#
helpcsharpsysadminsecurity
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Loug52
    wrote on last edited by
    #1

    Hi, all. I am working on a C# code that can retrieve system log by using WMI. However, the code is working fine under windows 2000, but got error messages under Windows XP. The erro message is : Unhandled Exception: System.Management.ManagementException:Access denied. at System.Management.Management.Exception.ThrowWithExtendedInfo(ManagementStatus errorCode) at System.Management.ManagementEventWatcher.Start() Part of my code is like following and I believe this is where the problem at: ---------------------------------------------------------------- public static ManagementEventWatcher getWatcher(string comp, string LogName) { ConnectionOptions co; ManagementPath mp; ManagementScope ms; WqlEventQuery EventQuery; ManagementEventWatcher watcher; string wql; string wqlAnd; co = new ConnectionOptions(); co.Timeout = new TimeSpan(0, 0, 60); co.EnablePrivileges = true; mp = new ManagementPath(); mp.NamespacePath = @"\root\cimv2"; mp.Server = comp; // comp is the computer you are connecting to ms = new ManagementScope(mp, co); Console.WriteLine("host is" + comp +"Logname is "+LogName); switch(LogName.ToUpper()) { case "ALL": wqlAnd = ""; break; case "SECURITY": wqlAnd = " AND TargetInstance.Logfile ='Security'"; break; case "SYSTEM": wqlAnd = " AND TargetInstance.Logfile ='System'"; break; case "APPLICATION": wqlAnd = " AND TargetInstance.Logfile ='Application'"; break; default: wqlAnd = ""; break;

    S C C D 4 Replies Last reply
    0
    • L Loug52

      Hi, all. I am working on a C# code that can retrieve system log by using WMI. However, the code is working fine under windows 2000, but got error messages under Windows XP. The erro message is : Unhandled Exception: System.Management.ManagementException:Access denied. at System.Management.Management.Exception.ThrowWithExtendedInfo(ManagementStatus errorCode) at System.Management.ManagementEventWatcher.Start() Part of my code is like following and I believe this is where the problem at: ---------------------------------------------------------------- public static ManagementEventWatcher getWatcher(string comp, string LogName) { ConnectionOptions co; ManagementPath mp; ManagementScope ms; WqlEventQuery EventQuery; ManagementEventWatcher watcher; string wql; string wqlAnd; co = new ConnectionOptions(); co.Timeout = new TimeSpan(0, 0, 60); co.EnablePrivileges = true; mp = new ManagementPath(); mp.NamespacePath = @"\root\cimv2"; mp.Server = comp; // comp is the computer you are connecting to ms = new ManagementScope(mp, co); Console.WriteLine("host is" + comp +"Logname is "+LogName); switch(LogName.ToUpper()) { case "ALL": wqlAnd = ""; break; case "SECURITY": wqlAnd = " AND TargetInstance.Logfile ='Security'"; break; case "SYSTEM": wqlAnd = " AND TargetInstance.Logfile ='System'"; break; case "APPLICATION": wqlAnd = " AND TargetInstance.Logfile ='Application'"; break; default: wqlAnd = ""; break;

      S Offline
      S Offline
      sreejith ss nair
      wrote on last edited by
      #2

      You are privilaged under ?:doh: Sreejith Nair [ My Articles ]

      L 1 Reply Last reply
      0
      • S sreejith ss nair

        You are privilaged under ?:doh: Sreejith Nair [ My Articles ]

        L Offline
        L Offline
        Loug52
        wrote on last edited by
        #3

        Thanks for replying. the code is running under admin privileges.

        1 Reply Last reply
        0
        • L Loug52

          Hi, all. I am working on a C# code that can retrieve system log by using WMI. However, the code is working fine under windows 2000, but got error messages under Windows XP. The erro message is : Unhandled Exception: System.Management.ManagementException:Access denied. at System.Management.Management.Exception.ThrowWithExtendedInfo(ManagementStatus errorCode) at System.Management.ManagementEventWatcher.Start() Part of my code is like following and I believe this is where the problem at: ---------------------------------------------------------------- public static ManagementEventWatcher getWatcher(string comp, string LogName) { ConnectionOptions co; ManagementPath mp; ManagementScope ms; WqlEventQuery EventQuery; ManagementEventWatcher watcher; string wql; string wqlAnd; co = new ConnectionOptions(); co.Timeout = new TimeSpan(0, 0, 60); co.EnablePrivileges = true; mp = new ManagementPath(); mp.NamespacePath = @"\root\cimv2"; mp.Server = comp; // comp is the computer you are connecting to ms = new ManagementScope(mp, co); Console.WriteLine("host is" + comp +"Logname is "+LogName); switch(LogName.ToUpper()) { case "ALL": wqlAnd = ""; break; case "SECURITY": wqlAnd = " AND TargetInstance.Logfile ='Security'"; break; case "SYSTEM": wqlAnd = " AND TargetInstance.Logfile ='System'"; break; case "APPLICATION": wqlAnd = " AND TargetInstance.Logfile ='Application'"; break; default: wqlAnd = ""; break;

          C Offline
          C Offline
          Charlie Williams
          wrote on last edited by
          #4

          Is this code running with full trust on both machines? According to the docs, ManagementEventWatcher.Start requires full trust to run, so if you're running it across your network with the default code access security settings, it won't work. Charlie if(!curlies){ return; }

          1 Reply Last reply
          0
          • L Loug52

            Hi, all. I am working on a C# code that can retrieve system log by using WMI. However, the code is working fine under windows 2000, but got error messages under Windows XP. The erro message is : Unhandled Exception: System.Management.ManagementException:Access denied. at System.Management.Management.Exception.ThrowWithExtendedInfo(ManagementStatus errorCode) at System.Management.ManagementEventWatcher.Start() Part of my code is like following and I believe this is where the problem at: ---------------------------------------------------------------- public static ManagementEventWatcher getWatcher(string comp, string LogName) { ConnectionOptions co; ManagementPath mp; ManagementScope ms; WqlEventQuery EventQuery; ManagementEventWatcher watcher; string wql; string wqlAnd; co = new ConnectionOptions(); co.Timeout = new TimeSpan(0, 0, 60); co.EnablePrivileges = true; mp = new ManagementPath(); mp.NamespacePath = @"\root\cimv2"; mp.Server = comp; // comp is the computer you are connecting to ms = new ManagementScope(mp, co); Console.WriteLine("host is" + comp +"Logname is "+LogName); switch(LogName.ToUpper()) { case "ALL": wqlAnd = ""; break; case "SECURITY": wqlAnd = " AND TargetInstance.Logfile ='Security'"; break; case "SYSTEM": wqlAnd = " AND TargetInstance.Logfile ='System'"; break; case "APPLICATION": wqlAnd = " AND TargetInstance.Logfile ='Application'"; break; default: wqlAnd = ""; break;

            C Offline
            C Offline
            cdmlb hotmail com
            wrote on last edited by
            #5

            Ever hear to try/catch blocks Ex:

            public void Example()
            {
            try
            {
            //Your Executable code here
            }
            catch(Exceptopn){} //Catches all Excetions
            catch(Excetion e) //Catches all Exceptions also
            {
            //What do you want to do when an excetion has happend
            Console.WriteLine(e.ToString()); //Helps to Debug and find
            //the specific Excetion
            }
            /*
            finaly
            {
            //Code that will always Execute even with Excetion or not
            //The finaly block is optional and is not needed
            }
            */
            }

            One part of my progs #region Constructor private Game(Control cTarget) {   try   {     this.target = cTarget;     this.target.GotFocus += new System.EventHandler(this.Restore);     this.graphics = new GraphicsHandler(this.target);     this.sounds   = new SoundHandler(this.target);     this.keyboard = new InputHandler(this.target);     this.presentState    = new GameState();     this.previousState   = new GameState();     this.presentData     = new GameData();     this.presentDataTemp = this.presentData.DeSerialize();     this.physics = new GamePhysics();     this.InitGame();     Timer.Init();   }   catch(Exception e)   {     MessageBox.Show("ERROR WHILE INITIALIZING GAME " + e.ToString());     return;   }   this.presentState  = GameState.Initialized;   this.previousState = GameState.Initialized;   this.GameLoop(); } #endregion cdmlb

            1 Reply Last reply
            0
            • L Loug52

              Hi, all. I am working on a C# code that can retrieve system log by using WMI. However, the code is working fine under windows 2000, but got error messages under Windows XP. The erro message is : Unhandled Exception: System.Management.ManagementException:Access denied. at System.Management.Management.Exception.ThrowWithExtendedInfo(ManagementStatus errorCode) at System.Management.ManagementEventWatcher.Start() Part of my code is like following and I believe this is where the problem at: ---------------------------------------------------------------- public static ManagementEventWatcher getWatcher(string comp, string LogName) { ConnectionOptions co; ManagementPath mp; ManagementScope ms; WqlEventQuery EventQuery; ManagementEventWatcher watcher; string wql; string wqlAnd; co = new ConnectionOptions(); co.Timeout = new TimeSpan(0, 0, 60); co.EnablePrivileges = true; mp = new ManagementPath(); mp.NamespacePath = @"\root\cimv2"; mp.Server = comp; // comp is the computer you are connecting to ms = new ManagementScope(mp, co); Console.WriteLine("host is" + comp +"Logname is "+LogName); switch(LogName.ToUpper()) { case "ALL": wqlAnd = ""; break; case "SECURITY": wqlAnd = " AND TargetInstance.Logfile ='Security'"; break; case "SYSTEM": wqlAnd = " AND TargetInstance.Logfile ='System'"; break; case "APPLICATION": wqlAnd = " AND TargetInstance.Logfile ='Application'"; break; default: wqlAnd = ""; break;

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              To add to what Charlie said, and he's got the most likely answer to your problem, ... He, and I, are both assuming that your running your application from a network share. Even though your logged in under an admin account, the .NET Framework will not give your application Full Trust to run. Read up on Code Access Security here[^]. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups