Problem with visual studio setup project

S

sunil

Hi,
I have created a setup project which installs a Network service. In the
installer, I had to set some security permissions so that Network
service can access my installation folder. Since, only administrators
can change the access list, I need to specify that admin privileges are
required to run the installer.

Is there a way to ask for admin password(if he is not an admin), find
out whether the account is valid, and exit if it is invalid, else
continue the installation.
Is there a way to do all this from the project installer.

Thanks in advance.
 
W

Willy Denoyette [MVP]

sunil said:
Hi,
I have created a setup project which installs a Network service. In the
installer, I had to set some security permissions so that Network
service can access my installation folder. Since, only administrators
can change the access list, I need to specify that admin privileges are
required to run the installer.

Is there a way to ask for admin password(if he is not an admin), find
out whether the account is valid, and exit if it is invalid, else
continue the installation.
Is there a way to do all this from the project installer.

Thanks in advance.



WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent());
if(!wp.IsInRole("BUILTIN\\" + "Administrators")))
// not an admin, tell user to logon as admin and restart install
...
else
// current user is an admin, continue install...

Willy.
 
W

Willy Denoyette [MVP]

Willy Denoyette said:
WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent());
if(!wp.IsInRole("BUILTIN\\" + "Administrators")))
// not an admin, tell user to logon as admin and restart install
...
else
// current user is an admin, continue install...

Willy.


Actually one should prefer the locale friendly version of IsInRole....

if(!wp.IsInRole(WindowsBuiltInRole.Administrator))
.....

Willy.
 
S

sunil

Actually one should prefer the locale friendly version of IsInRole....

if(!wp.IsInRole(WindowsBuiltInRole.Administrator))
.....

Willy.

Dear Willy,
Thanks for the response. Where should I add this code? Should I add in
the InitializeComponent() method of the ProjectInstaller.cs.How exactly should I tell user to logon as admin(can I use a dialog box
that takes admin account name and the password and check its validity)

I want to ask for the administrator password(if he is not) as soon as
the user starts the installer(before asking for the installation folder)
 
W

Willy Denoyette [MVP]

sunil said:
Dear Willy,
Thanks for the response. Where should I add this code? Should I add in
the InitializeComponent() method of the ProjectInstaller.cs.
How exactly should I tell user to logon as admin(can I use a dialog box
that takes admin account name and the password and check its validity)

I want to ask for the administrator password(if he is not) as soon as
the user starts the installer(before asking for the installation folder)


You should ask the user to 1) logoff form it's current logon session and 2) to logon as an
admin , asking a user for an admin password doesn't make him run as an admin. You should do
this as soon as you can in your code and yes you can use a Messagebox for this.

Willy.
 
S

sunil

You should ask the user to 1) logoff form it's current logon session and 2) to logon as an
admin , asking a user for an admin password doesn't make him run as an admin. You should do
this as soon as you can in your code and yes you can use a Messagebox for this.

Willy.

Dear Willy,
i had tried out what you have suggested, but I had lot of problems. The
code that I added is:

public override void Install(System.Collections.IDictionary stateSaver)
{
WindowsPrincipal wp = new
WindowsPrincipal(WindowsIdentity.GetCurrent());
if (!wp.IsInRole(WindowsBuiltInRole.Administrator))
{
MessageBox.Show("Please login with administrator privileges to
install this product");
throw new InstallException("Error in the installation....login with
administrator privileges");
}
else
{
base.Install(stateSaver);
}
}

After the custom messages by me using InstallException are shown, there
is one more exception thrown
The exception message is :
"The savedState dictionary does not contain
the expected values and might have been corrupted".

Is there a better way to cancel the installation.Please help me with
this problem!!!!

One more question:
Is there a better way to stop the installation if the currently logged
in user is not an admin. Also, I
want to cancel the installation, even before the choice for the
installation folder is asked
Is this possible?
 
S

sunil

You should ask the user to 1) logoff form it's current logon session and 2) to logon as an
admin , asking a user for an admin password doesn't make him run as an admin. You should do
this as soon as you can in your code and yes you can use a Messagebox for this.

Willy.

Dear Willy,
i had tried out what you have suggested, but I had lot of problems. The
code that I added is:

public override void Install(System.Collections.IDictionary stateSaver)
{
WindowsPrincipal wp = new
WindowsPrincipal(WindowsIdentity.GetCurrent());
if (!wp.IsInRole(WindowsBuiltInRole.Administrator))
{
MessageBox.Show("Please login with administrator privileges to
install this product");
throw new InstallException("Error in the installation....login with
administrator privileges");
}
else
{
base.Install(stateSaver);
}
}


After the custom messages by me using InstallException are shown, there
is one more exception thrown
The exception message is :
"The savedState dictionary does not contain
the expected values and might have been corrupted".

Is there a better way to rollback the installation without other
exceptions being thrown. Please help me with this problem!!!!

One more question:
Is there a better way to stop the installation if the currently logged
in user is not an admin. Also, I
want to cancel the installation, even before the choice for the
installation folder is asked
Is this possible?
 
W

Willy Denoyette [MVP]

sunil said:
Dear Willy,
i had tried out what you have suggested, but I had lot of problems. The
code that I added is:

public override void Install(System.Collections.IDictionary stateSaver)
{
WindowsPrincipal wp = new
WindowsPrincipal(WindowsIdentity.GetCurrent());
if (!wp.IsInRole(WindowsBuiltInRole.Administrator))
{
MessageBox.Show("Please login with administrator privileges to
install this product");
throw new InstallException("Error in the installation....login with
administrator privileges");
}
else
{
base.Install(stateSaver);
}
}


After the custom messages by me using InstallException are shown, there
is one more exception thrown
The exception message is :
"The savedState dictionary does not contain
the expected values and might have been corrupted".

Is there a better way to rollback the installation without other
exceptions being thrown. Please help me with this problem!!!!

One more question:
Is there a better way to stop the installation if the currently logged
in user is not an admin. Also, I
want to cancel the installation, even before the choice for the
installation folder is asked
Is this possible?



As I told you, you should check this before you even start the installation, I don't know
how your setup looks like, but before you ask for the install folder (who creates this
folder btw?), you should check whether you are running as an admin.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top