PC Review


Reply
Thread Tools Rate Thread

Problem with visual studio setup project

 
 
sunil
Guest
Posts: n/a
 
      16th Jan 2007
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.

 
Reply With Quote
 
 
 
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      16th Jan 2007
"sunil" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.




 
Reply With Quote
 
 
 
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      16th Jan 2007
"Willy Denoyette [MVP]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> "sunil" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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.
>
>
>
>



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

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

Willy.


 
Reply With Quote
 
sunil
Guest
Posts: n/a
 
      17th Jan 2007


> > 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.


Dear Willy,
Thanks for the response. Where should I add this code? Should I add in
the InitializeComponent() method of the ProjectInstaller.cs.
> > // not an admin, tell user to logon as admin and restart install

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)

 
Reply With Quote
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      17th Jan 2007
"sunil" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
>
>> > 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.

>
> Dear Willy,
> Thanks for the response. Where should I add this code? Should I add in
> the InitializeComponent() method of the ProjectInstaller.cs.
>> > // not an admin, tell user to logon as admin and restart install

> 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.




 
Reply With Quote
 
sunil
Guest
Posts: n/a
 
      18th Jan 2007

>
> 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?

 
Reply With Quote
 
sunil
Guest
Posts: n/a
 
      18th Jan 2007

>
> 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?

 
Reply With Quote
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      18th Jan 2007
"sunil" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
>>
>> 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?
>




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.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting VC Project from Visual Studio 2005 to Visual Studio 2003 Vadim Microsoft VC .NET 4 1st Jan 2008 01:16 AM
How to take an IE rendered screenshot of a website with visual studio .net 2002 or visual stuido .net 2003? I can't install visual studio .net 2005 on this computer. Daniel Microsoft Dot NET 4 17th May 2007 07:56 PM
How to take an IE rendered screenshot of a website with visual studio .net 2002 or visual stuido .net 2003? I can't install visual studio .net 2005 on this computer. Daniel Microsoft Dot NET Framework 1 14th May 2007 08:05 PM
How to take an IE rendered screenshot of a website with visual studio .net 2002 or visual stuido .net 2003? I can't install visual studio .net 2005 on this computer. Daniel Microsoft C# .NET 0 14th May 2007 07:45 PM
Visual Studio 2005 Beta 1 Refresh vs Visual Studio 2005 CTP vs Visual C++ 2005 Express Beta1 Peter Nimmo Microsoft VC .NET 1 16th Dec 2004 04:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:15 PM.