i am using the following code to read the details from a network folder which is restricted for only one user
shell("net use q: \\serveryname\foldername /user:admin pwrd", AppWinStyle.Hide, True, 10000)
Process.Start(path)
shell("net use q: /delete")
when i run this to open any pdf or jpg or any other files except word/excel/powerpoint, everything is working fine. but the problem comes only when i access a word file.
in the step one, i am giving permission to access the word file. in the step two, word file is open. in the third, i am deleting the q drive.
the problem is the word file is still open. so i am getting a dos window, saying that "some connections of still connected or searching some folders, do you want to force disconnect" please help.... how to access a word file (editable files) providing user name and p开发者_如何学Goassword from the code and at the same time he shoud not have access to any other folders directly.
Why not just copy the word file to the local drive, then close the share and then open the file.
Though I'd suggest that it might be worth looking at some other kind of access control. This seems fairly unsafe (for example, what if your process crashes after the first command but before the second, then the share would be left open for anyone to use).
This seems like a really bad way to do it. There are a number of problems with it:
- As you discovered, Word keeps the file open for as long as you're using the file, so you can't just pull the share out from under it.
- You cannot reliably know when Word has finished with the file (for example, you can't just wait for the process to exit, because it might just be a wrapper that starts up for a second, notify the "original" word process to open the file and exits)
- Even if you could reliably detect when word had finished using the file, the fact that you had the share open the whole time seems to contradict your requirement to lock it down in the first place
- I assume you don't have the password hard-coded like that, but if you do then it's trivial for someone to just open up your executable and find out the password.
Perhaps if you tell us why you're trying to do this, we can suggest a better way, but if all you want to do is provide read-only access to the file (which seems to be the case) then you can just grant read-only access on the share itself: no need for this complicated process at all!
精彩评论