Acessing new Vista/Win7 FIle Properties from .NET code?

J

Joe Cool

I see in Vista and Windows 7, there is new Privilege Level property
called "Run this program as an administrator" for EXE files. Is there
a way to set this property in code? I have a copy of VS2010 Beta 2
running in a VM and checked the documentation for the FileInfo class
but I didn't see anything.
 
J

Jesse Houwing

* Joe Cool wrote, On 19-1-2010 16:21:
I see in Vista and Windows 7, there is new Privilege Level property
called "Run this program as an administrator" for EXE files. Is there
a way to set this property in code? I have a copy of VS2010 Beta 2
running in a VM and checked the documentation for the FileInfo class
but I didn't see anything.

It is basically handled by adding a manifest for that application as far
as I know.

There's also the Windows 7 Code Pack, which allows a developer to access
most of the new features from code, you might find something useful in
there:

http://code.msdn.microsoft.com/WindowsAPICodePack
 
A

Andy O'Neill

Joe Cool said:
I see in Vista and Windows 7, there is new Privilege Level property
called "Run this program as an administrator" for EXE files. Is there
a way to set this property in code? I have a copy of VS2010 Beta 2
running in a VM and checked the documentation for the FileInfo class
but I didn't see anything.

Checking my vs2010 WPF project.....

Under project properties edit app.manifest
Read the commented out part.
Change requestedExecutionLevel

But read up on it first. and think twice.
eg what happens if the user doesn't have admin privileges?

Or

Right click the shortcut.
Select run as administrator.

If they aren't admin and don't know the admin user and password then you
have a problem.

Cheers,
Andy O'Neill
 
Z

zsessions

Checking my vs2010 WPF project.....

Under project properties edit app.manifest
Read the commented out part.
Change requestedExecutionLevel

But read up on it first. and think twice.
eg what happens if the user doesn't have admin privileges?

Or

Right click the shortcut.
Select run as administrator.

If they aren't admin and don't know the admin user and password then you
have a problem.

It appears that this is also supported in VS2008 and in a standard
Windows Forms app as well as a WPF app in VS2010.

But I noticed that the app.manifest file didn't exist until I opened
the project Properties Security tab and clicked "Enable ClickOnce
security settings" and saved the project. There may be other actions
that create the app.manifest for the first time, but this did it for
me.

I am only asking this because I would like to include a special XML
file in the application's startup path that the app looks at on
startup and if necessary performs the app's database upgrades that are
defined in the XML file. This works fine on XP but Vista and Win7
impose stronger restrictions on the Program Files folder than XP did,
and the app does not have access to the file when located there.

Is there a simple, SAFE way to accomplish this goal?
 
A

Andy O'Neill

I am only asking this because I would like to include a special XML
file in the application's startup path that the app looks at on
startup and if necessary performs the app's database upgrades that are
defined in the XML file. This works fine on XP but Vista and Win7
impose stronger restrictions on the Program Files folder than XP did,
and the app does not have access to the file when located there.
Is there a simple, SAFE way to accomplish this goal?

Try putting it in App_Data.
 
Z

zsessions

file in the application's startup path that the app looks at on
startup and if necessary performs the app's database upgrades that are
defined in the XML file. This works fine on XP but Vista and Win7
impose stronger restrictions on the Program Files folder than XP did,
and the app does not have access to the file when located there.


Try putting it in App_Data.

I know it will work in AppData, but I was trying to avoid it. I don't
want the user stumbling onto the file.
 
A

Andy O'Neill

I know it will work in AppData, but I was trying to avoid it. I don't
want the user stumbling onto the file.

Can you not do the update as part of the install process?
Then the file could be deleted after the install.

You can include an xml file as an embedded resource,
Preferably in the install project or some other separate project doesn't get
loaded every time you run the app.
Can't really see it being a good idea if you can't do the update on install.

I think my preferred method would be to deliver the xml via web service.
Then when you realise you need another change a couple of weeks later it's
easy.
This is a fairly standard sort of approach people ought to be used to.
 

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