简体   繁体   English

如何在vb.net中使用凭据访问远程文件夹?

[英]how can i access a remote folder with credentials in vb.net?

I have a windows service and I'm using a remote connection to access a folder and this folder has a password and a user that it is already specified down here in the code but it doesn't seem to access anyway I've already tried to do this locally and it works but when I do it remotely just doesn't work. 我有Windows服务,并且正在使用远程连接访问文件夹,并且该文件夹具有密码,并且用户已经在代码中此处指定了该用户,但是无论如何我似乎都无法访问它在本地执行此操作,它可以工作,但是当我远程执行此操作时,它不起作用。 any help would be great thank you! 任何帮助将是巨大的谢谢!

Public Class Service1
    Dim cred As New NetworkCredential("Administrator", "*P4ssW0rD")


 Private Sub SchedularCallback(e As Object)
        'Metodo Procesa Archivos tipo boleano 

        Dim di As DirectoryInfo = New DirectoryInfo("\\132.147.161.83\SisInt\courts\agreement\J92016SEM2")

        For Each fi In di.GetFiles()

            'seleccionamos los archivos con las extensiones de Word
            If fi.Extension.ToUpper = ".DOC" Or fi.Extension.ToUpper = ".DOCX" Then
                ListaArchivos.Add(fi.FullName)
                ListaNombres.Add((fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length)))

            End If

        Next

Windows Services operate in the security context of the account that's specified in the Services Control Panel, so you would need to change it there. Windows服务在“服务控制面板”中指定的帐户的安全上下文中运行,因此您需要在此进行更改。

By default, the service only has access to local resources which is why you can't access anything outside the local machine. 默认情况下,该服务只能访问本地资源,这就是为什么您不能访问本地计算机以外的任何内容的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM