Administrative Powers

lothos12345

Junior Contributor
Joined
May 2, 2002
Messages
294
Location
Texas
I have written a visual basic.net class who's sole purpose is it get the user name and process id of a person that is running the particuliar application in which has this class and use that information to create a unique directory with a particularily name text file. This application works great if I am logged in as administrator into the machine but if I log in as someone else I cannot get the process information nor can I get the right to create the unique directory. Ideally the solution would be to increase the permissions of the Logon, unforunately this is not an option. I need the ability to do perform all the required actions as with administrator powers though I am logged in as the lesser user. This needs to be done in code. Any examples or help would be greatly appreciated.
 
The app opens and I can read the registry but I cannot read any process information to include the username and id. I am trying to create a directory in the Startup path of the application. I have thought of something but I am not sure how to accomplish it. Is there a way I can run the app as administrator and program this from the application?
 
You can't force your program to run as an Admin. If you need to safely create a folder on the user's hard drive, it's recommended to use either the temporary folder or the folder under My Documents (I think). I can't recall how to reference either of those (maybe through the Environment class?), but it's a start. You can always ask again, if this seems to fit with what you need.

-ner
 
directories

I have no clue if you can get to these (due to permissions) but since Nerseus mentioned them, here's how to get to MyDocs, AllUsers\AppData and username\LocalSettings\AppData
Visual Basic:
'with sb as a stringbuilder:
'
'
'User's Desktop    
sb.Append(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory))
'
'User's MyDocs
sb.Append(Environment.GetFolderPath(Environment.SpecialFolder.Personal))
'
'user specific: ...\\docs & stgs\\username\\local settings\\app data\\... note "localsettings"
sb.Append(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData))
'
'all users: ...\\docs & stgs\\all users\\app data\\... note no "localsettings"
sb.Append(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData))
 
Last edited:
Back
Top