0

I have a windows network in which many files are shared across many users with full control. I have a folder shared for everyone in my system, so whenever I try to access it using the machine name (run->\Servername) from another system, I can see the shared folder and open/write files in it.

But my requirement is to close any open files(in my system) in network. So I used NetFileEnum to list all opened file ids so that I can close those files using NetFileClose API.

But the problem is NetFileEnum returns invalid junk ids like 111092900, -1100100090 etc so that I can't close it from another machine. So I listed the network opened files using net file command and by noting the id, say it be 43 I hard coded the id in my function call NetFileClose("Servername", 43); But when I executed, I got ACCESS_DENIED_ERROR. But if the same code is run on the server, it is successfully closing the files. I had given full permission in share for all users.

But why ACCESS_DENIED_ERROR and why NetFileEnum returning invalid ids? Is there anything to be done for this API to work? How can I use these APIs properly to close network opened files?

ScarCode
  • 3,074
  • 3
  • 19
  • 32
  • The documentation says *Only members of the Administrators or Server Operators local group can successfully execute the NetFileClose function.* So it would be fair to say the code you are running is being run as Administrator on the server or a member of the Server Operators local group on the server? You are not running it as yourself, but with a limited token (i.e. UAC)? – ta.speot.is Nov 10 '12 at 08:44
  • No I am not running it as a member of server operators. How can I add a PC into Server Operators local group on server? – ScarCode Nov 10 '12 at 17:51
  • You can add a computer account to a local group in the same way you'd add a user account, by using the Local Users and Groups tool (in Server Manager under Configuration). When the dialog box to select the account appears, press the "Object Types" button and select Computers. Of course, this only applies if the code is running in the local system or network service account on the client in question. – Harry Johnston Nov 11 '12 at 23:15

0 Answers0