finding user id accessing my system using C# - c#

I'm developing a small application using C# that
will run as a service
will monitor (uses FileSystemWatcher) and log the changes made to files under a certain directory say C:\
I'm able to achieve the above things, below are the things i'm looking for pointers/suggestions
if some one accesses (with or without admin previlege) my machine ( using Run command and passing input as \ \mysystemname\C$) and creates/deletes/modifies files under the directory, then how should i can get the user id of the account. For example if i use System.Environment.UserName then it gives my user name.
Is it possible to monitor the above scenario if so can any one provide me pointers.

If this is tracking remote file access to a shared drive, you might want to check out this open source project: http://www.codeproject.com/Articles/62357/Monitoring-Access-to-Your-Shared-Files-on-Network
Browsing through the code I don't see exactly how the username is retrieved, but the app looks to have the features you need.

Related

How to get the local desktop path of the users file when the application is hosted from server?

I am trying to run a macro-file that will be present in users desktop via my .net website, hence I would like to know how I can get the path of that macro file in my code and open it.
I am currently using following described code to get the path, and I think that this must be trying to take the path from server computer but I would like to get this from users computer, this particular macro file will open internet explorer and navigate to certain website and download a report to local computer hence I would like this to be run from users side.
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
Is it possible to get the path automatically or should i get that from user.
please provide suggestion.
You are hosting a website, which is using a web server like IIS and the user access the site using a browser like edge, chrome, now the file is in user desktop, so the main question remains,
Does the browser process have the access to the file system of the user
Mostly no, especially not via the call Environment.GetFolderPath(Environment.SpecialFolder.Desktop);, this will be good for running it on hosted sever, where w3p.exe process is accessing the file system with required permissions
For the end user desktop
You need to provide the file dialog box, let user select the file / directory and need to plan to serialize the file to the sever (upload) for doing any processing. You can binary serialize the file using a provider like protobuf, msgpack to achieve the necessary functionality
Code you have provided, is good for for the process where you have direct control, like Console, WPF, which runs on the system under certain permission and thus access the file system for processing

Make a file read/write accessible only from within my application

I'm creating a new database application using C# and MS-Access, I want to make the database file ONLY accessible for (read/write) operations from within my application so that the user haven't the ability to open the file from outside the application but the application has the full access to the database file, Or may be a better way is to make this permission for the root folder of the database.
Someone may ask "Why don't you just set a password for the database?"
My reply is that I want the root folder completely inaccessible and therefore the user won't know the database type I'm using because I will change the file extension for it.
As far as I know that the Windows OS uses the NTFS permissions -Groups- to make a folder accessible only for a set of groups like (Trusted Installer, System, Users,...)
Can I Achieve my goal using NTFS Permissions, or may be there is a better way to handle this?
I added fixed length encrypted bytes to the start of file using low level file read write operations and my app upon execution removed the bytes and had given me the actual file and I blocked the starup menu and short cuts keys and context menus using windows api so only my app had access to it plus I enabled windows stuff upon app termination and encrypted database again so it was unreadable for another access enabled app.

What are contradications or threats of running own application from C:\Windows

My colleagues are testing our new system (.Net 4) app and running it directly from C:\Windows.
App is executed in each user session within user context (so, with lower rights really).
I've noticed that there is a serious problem with this app. I can't read full filename path of app (from another application) by retrieving it using process class (MainModule.FileName) - Access Denied, nor by using WMI query - here I get empty string. UAC is turned off.
Both methods work fine in developing environment (different paths). Is there any way I can adjust security settings, or I just should give up and change the path to something more neutral?
You should just give up and change the path to "something more neutral". I.e. a proper installation directory in the Program Files or Program Files (x86) directory (as appropriate).
Also, it is not clear from your question why you want to retrieve the full file path of the process, but it's likely you're going about that wrong as well. There's really no reason that a program should be forced to run from any specific directory, so if you have a system that is somehow relying on a check of the full file path of the process's executable, that system is probably flawed and should be using some other mechanism for the purpose (e.g. using shared memory, a named pipe, a named mutex, or other similar inter-process communications mechanism).

Opening files locally from web application

I recently added a way for my web application (ASP.NET written in C#) to go to a folder which contains a bunch of spreadsheets and import them into SQL server tables. I set the folders and file names using an admin table so it knows how to handle each file and which table they should go to etc. It even keeps track of the file dates and times so it ignores anything that isn't new since the last time it imported them. Very cool but it only works on my development machine, most likely because the path is easily recognized there.
I'd like others to be able to do this but I can't seem get the web application to access a pre-arranged path on the users local machine. Now I'm assuming this is normal (we shouldn't be able to have a web application reach into someone's machine and grab files!) but is there some way to either do it using a known path or by having a user select the local folder? Is it possibly done more easily if I put the files in a folder within the site?
Dana
If I understand your question correctly, the approach is that you want a user to type in a local file path and you process it.
This will not work through a website. And from a security perspective this is very wise as you point out. So unless you install some client application on the local machine it is not possible.
You will need a file-upload dialog and have the user explicity locate the files for you, click upload and process them on the server.
Some other strategies here:
https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications
but it still requires the user to select them manually.

automating regular windows functions using c sharp

I am trying to build a windows application that will automate a regular routine steps that I have to do for taking a backup.
The flow goes like this...
1.open a folder
2.run an exe there
3.open jumpbox server at which point we have to enter a username and password
4.create a folder
5.then open a network folder using the ip such as //ip.ip.ip.ip/folder (i do this from run)
6.copy a file from this folder to the created folder and rename it
and some other stuff like this.
I handle some of the stuff like open a folder, creating a folder and stuff like that but how to connect to a network folder and give the username and password to it when its asking from within the application.
All these things that can be controlled with a .Net application.
You can use System.Diagnotics.Process to launch other executables in a process.
Both System.IO.Directory and System.IO.DirectoryInfo can be used to do all sorts of folder manipulation.
As for connecting to a network drive which, I think is the actual question, you'll have to excuse my ignorance on jumpboxes. If a user on your domain has access you will need to impersonate that user as suggested here, or if it is a seperate domain, as I suspect is the case, you can use the API as suggested here.
I see you run external commands, so you could use "NET USE...".
Run NET HELP USE to see syntax...

Categories

Resources