none
Unhandal Exception RRS feed

  • Question

  • I have make a Project and make a setup file. This File work properly in my pc but when setup another pc it does not Work.I have make it Visual Studio 2010.

    Give a error message

    Unhandaled Exception has occurred in you application. If you click Continue the application will ignore this error and attempt to continue. if you cliclk Quit thwe application will close immediatly.
    Attempt to perform an unauthorized Operation.
     

    Project Code is=====

    Project code is
     

    using System;
    using System.IO;
    using System.Windows.Forms;
    using System.Security.AccessControl;
    using System.Management;
     
    namespace FolderPermisition
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    GetUsers();
    }
     
    private void Form1_Load(object sender, EventArgs e)
    {
     
    }
     
    public void GetUsers()
    {
    SelectQuery sQuery = new SelectQuery("Win32_UserAccount", "Domain='"+ System.Environment.UserDomainName.ToString() + "'");
    try
    {
    ManagementObjectSearcher mSearcher = new ManagementObjectSearcher(sQuery);
    foreach (ManagementObject mObject in mSearcher.Get())
    {
     
    comboBox1.Items.Add(mObject["Name"]);
    }
    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.ToString());
    }
    }
     
    private void button1_Click(object sender, EventArgs e)
    {
    FolderBrowserDialog myFolderBrowserDialog = new FolderBrowserDialog();
    myFolderBrowserDialog.ShowDialog();
    textBox1.Text =myFolderBrowserDialog.SelectedPath.ToString();
    }
     
    private void button2_Click(object sender, EventArgs e)
    {
    DirectoryInfo myDirectoryInfo = new DirectoryInfo(textBox1.Text);
    DirectorySecurity myDirectorySecurity = myDirectoryInfo.GetAccessControl();
    string User = System.Environment.UserDomainName + "\\" + comboBox1.SelectedItem.ToString();
    myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(User,FileSystemRights.Read, AccessControlType.Deny));
    myDirectoryInfo.SetAccessControl(myDirectorySecurity);
    MessageBox.Show("Permissions Altered Successfully");

    }
     
    private void button3_Click(object sender, EventArgs e)
    {
    DirectoryInfo myDirectoryInfo = new DirectoryInfo(textBox1.Text);
    DirectorySecurity myDirectorySecurity = myDirectoryInfo.GetAccessControl();
    string User = System.Environment.UserDomainName + "\\" + comboBox1.SelectedItem.ToString();
    myDirectorySecurity.RemoveAccessRule(new FileSystemAccessRule(User, FileSystemRights.Read, AccessControlType.Deny));
    myDirectoryInfo.SetAccessControl(myDirectorySecurity);
    MessageBox.Show("Permissions Remove Successfully");

    }

    }
    }

    Please help anybody.

    Email--kmmuradbd@gmail.com


    Tuesday, December 3, 2013 1:42 PM

Answers

  • Hi Murad,

    Are you creating a standard MSI setup package for your application? As in the code you provided, you're performing some WMI and ACL related operations which require high privileges. Therefore, I'm wondering if the targe machine on which you run the program has UAC enabled. If UAC is enabled, make sure you run the program with elevated context.

    BTW, since this forum is mainly focus on WCF and web service programming questions, I'd recommend you post the question in the Windows forms specific forums so as to get more effecient assistance:

    #Windows Forms forums
    http://social.msdn.microsoft.com/Forums/windows/en-US/home?forum=winforms


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, December 4, 2013 3:33 AM
    Moderator