Click here to Skip to main content
15,894,460 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a error that occur everytime I run my program and it states that an unhandledexception occured. Is there anything wrong with my codes?

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;
namespace EnvironmentVariableAddDel
{
    class Program
    {
        static void Main(string[] args)
        {
            string envPath = "Win32_Environment.Name='LM_LICENSE_FILE'" + ",UserName='<SYSTEM>'";
            ManagementObject envObject = new ManagementObject(envPath);
            envObject["27010@license.esiee.fr"] = "27000@license.esiee.fr";
            envObject.Put();                   // Save the change to the system
        }
    }
}
Posted
Updated 3-Jun-10 1:47am
v2
Comments
Henry Minute 3-Jun-10 8:05am    
In response to your comment to CPallini: That is just the title for the error box and should be highlighted. Immediately underneath that there should be a further message (not highlighted) with further details. It would also help if you told us which line in your code is throwing the error. Once again, most people could probably guess, but there is no guarantee we'd be right.

Why don't you report the details of the occurred exception?
(I can only guess it is a security issue...)
:)
 
Share this answer
 
v2
Comments
CoderChia 3-Jun-10 7:53am    
it just states ManagementException was unhandled.
CPallini 3-Jun-10 8:06am    
Use the debugger to get full details of the exception.
CoderChia 3-Jun-10 8:44am    
In detail it states:System.Management.ManagementException

Error code:System.Management.ManagementStatus.NotFound

Source:System.Management
First of all, put a try-catch around your code.

You need to paste the error here before someone can help you.
 
Share this answer
 
Comments
CoderChia 3-Jun-10 8:47am    
envObject["27000@license.esiee.fr"] = "27010@license.esiee.fr";


this is the line of the error wghich states System.Management.ManagementException
IF YOU ARE SHORE THERE'S NO THING WRONG YOU CAN SAVE IT AND CLOSE THE PAGE AND OPEN IT AGAIN AND CLICK "RUN"


THANK YOU AND GOOD LUCK
 
Share this answer
 
Comments
Toli Cuturicu 8-Jun-10 16:19pm    
Reason for my vote of 1
Is your CAPS LOCK key really stuck? Try using the Shift key to get lowercase then!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900