This probably has less to do with IIS than with account permissions. When you run it from the command line it is run under your account which has permission to that network resource. By default IIS runs under a special account called "Local System". The Local System account has access to almost all resources on the local machine not specifically denied to it, and no resources on any other machines on the network.
MS KB article 158229 has more info about security and IIS applications.
Do you really need to walk that directory?
Perhaps there is another method you could use?