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...
Related
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
I've been trying to make a website which is able to display all the folders and files which is placed on a remote computer, and here afterwards but is there a good way to do this?
I've been looking on RDP and RDC and here you have to use a remote desktop application in order du do this.
i'm working with asp.net, C# and javaScript
But is there a way to display the folder system on a website
like :
C: drive (freesspace)
(then comes all the folders on c drive)
folder 1
(and in each folder comes all the files)
file 1
file 2
file 3
folder 2
folder 3
i've been looking alittle on ConnectionOptions and it looks like it would do the trick, but does it work? and/or is there another way.
found this link http://social.msdn.microsoft.com/Forums/vstudio/en-US/27ea1e6d-dc11-4ed0-a3d8-1d1462231848/remotely-access-the-computer-c but not sure if it would work.
Need your help!
Regards Kasper
If you are looking for a file manager, see this question:
Best free file manager for ASP.Net
The best option is this guy:
http://www.izwebfilemanager.com/
With that said, it is a little dubious of a security proposition to expose the entire hard drive of a remote machine in a web app.
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.
Background:
I have a main application that needs to be able to go to the web and download DLL files associated with it (ones that we write, located on our server). It really needs to be able to download these DLL files to the application folder in "C:\Program Files\". In the past I have used System.Net.WebClient to download whatever files I wanted from the web.
The Issue
I have had a lot of trouble downloading data in the past and saving to files on a user's hard drive. I get many reports of users saying that this does not work and it is generally because of user rights issues in the program.
In the cases where it was an issue with program user rights every user could go to the exact file location on the web, download it, and then save it to the right place manually.
I want this to work like all the other programs I have seen download/install in this fassion (i.e. Firefox Pluign Updates, Flash Player, JAVA, Adobe Reader, etc). All of these work without a hitch.
The Question
Is there some code I need to use to give my downloader program special rights to the Program Files folder? Can I even do this? Is there a better class or library that I should use? Is there a different approach to downloading files I should take, such as using threads or something else to download data?
Any help here is appreciated. I want to try to stay away from third-party apps/libraries if at all possible, other than Microsoft of course, due to licensing issues, but still send any suggestions my way.
Again, other programs seem to have the rights issues and download capability figured out. I want this same capability.
The usual way to do this goes like this:
Your application detects that an update is needed.
Your application starts another (updater) application, that will download the required files and install them into Program Files. This updater application must run with administrative rights (i.e., prompt for UAC elevation in Vista/Win7). The easiest way to ensure this is to add an application manifest to that updater application.
If the user is an administrator with UAC enabled, point 2 will cause a UAC prompt to appear which must be accepted (note that the same is true for Firefox/Acrobat/etc. updaters). If the user is not an administrator, he will be asked for administrator credentials. (Note that this is a good thing: Only an administrator should be allowed to upgrade applications installed for all users.)
Your updater application does not need to be written in a special way: It can use System.Net.WebClient just like before. The application manifest will ensure that it requests the required premissions for writing to Program Files.
Note that this issue (Program Files not being writable by administrators without UAC elevation) is an operating system feature and not a programing language limitation, so you won't solve this issue just by "using a different library". If you want your application to run on Vista/Win7 and write to Program Files, you will need UAC elevation.
Check out the BITS service:
http://msdn.microsoft.com/en-us/magazine/cc188766.aspx
Writing to the Program Files directory requires UAC elevation (if the user has that enabled) on Vista/Win7. See this code sample on how to prompt users for permission: http://msdn.microsoft.com/en-us/library/aa970890.aspx
Really though, please think about designing your app so that it writes to a more appropriate place where this is no risk of accidentally overwritting a critical program file.
How about trying http://netsparkle.codeplex.com/. A port of the very successful Mac Sparkle framework http://sparkle.andymatuschak.org/.
Does it really need to be in Program Files? I had a similar problem in an application, and we've written a class to resolve non-installed assemblies by first trying to load them from a subfolder of the %usersprofile%, then by going trying to download. This can be seamless if you add you resolve method to the current app domain's AssemblyResolve event.
AppDomain.CurrentDomain.AssemblyResolve+= AssemblyResolve;
public Assembly AssemblyResolve(object sender, ResolveEventArgs args)
{
//try to get locally
//try to download
return assembly;
}
Don't do it.
Theoretically it can be done easily. you just lunch another app, that runs with administrative privileges - you can request these in configuration. In the updater app, you just connect to a secure(ssl) web site, download everything you need, the files you download must be cryptographically signed.
This can also be easily solved using ClickOnce or some other web installer, capable of updates.
What you shouldn't do is just download insecure DLL's from an unverified source and execute them.
I've got a webserver where people upload files. What I need to do is take those files and write them to a file share on the Active Directory domain. The problem -- the webserver is not on the domain.
So, how is the best way to do this? I would have thought this would be easy, something along the lines of create a connection with some credentials and do it. But apparently not. The closest I've found is Impersonation with WindowsIdentity.Impersonate, but everything I've read says that is a bad idea in a production environment.
Any ideas? I'm working on a solution that FTPs the files, but that's unsatisfying too, and a fallback plan.
I'm using c# and .net 4.0 in (obviously) a windows environment.
Edit: I should point out that I can't run servers (or services) that access the outside on that domain. The FTPing is a temporary workaround.
I would have another program probably a Windows service pick the files from the web service file location and move them to the active directory directory. I would probably have this process execute from the location where they are being copied to. Make them available in a share on the web server visible only to the process's user and admins.
I think that an FTP solution is better than using a Windows Share; however, I would think a web service of some type would be the best option for an inter-domain file exchange. That said, if you've got it working with WindowsIdentity.Impersonate -- why not use it? What context did you read that it was a bad idea?
Is there any way that you can map this file share as Network Driver. If you can do that, you don't need to manager Security and will be super easy to access these files as if they are local.