我已经写了一个VB .NET前端到Office SQL Server。我想扩展此信息,以便用户可以通过VPN访问服务器。在测试过程时,如果我在每个客户端PC上还启用了“文件和打印机共享”,我只能通过VPN查看SQL Server,因此我希望一些代码在尝试之前是否启用了VPN和共享访问服务器。我有以下三行检查VPN正在运行:
Dim myInterfaceList As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces
Dim myVPNRunning As Boolean = myInterfaceList.AsEnumerable().Any(Function(x) x.Name = "MyTestVPN")
If myVPNRunning Then chkProgress3.Checked = True
但是我找不到(在VB .NET中)检查客户端PC是否启用了“文件和打印机共享”。我发现了这篇文章 1 讨论使用PowerShell进行检查,但我没有知道如何将其转换为VB .NET代码(或这是正确 /最佳方法)。 Office网络不是一个域,因此我无法通过小组策略启用共享。
还有其他人解决这个问题吗?
谢谢,
蒂姆
I have written a VB .Net front-end to the office SQL server. I want to expand this so users can access the server via a VPN. When testing the process, I can only see the SQL server via the VPN if I also have 'File and Printer Sharing' enabled on each client PC, so I want some code to check that both the VPN and the sharing are enabled before trying to access the server. I have the following three lines which checks that the VPN is running:
Dim myInterfaceList As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces
Dim myVPNRunning As Boolean = myInterfaceList.AsEnumerable().Any(Function(x) x.Name = "MyTestVPN")
If myVPNRunning Then chkProgress3.Checked = True
but I can't find a way (in VB .NET) to check if the client PC has 'File and Printer Sharing' enabled. I have found this article 1 which discusses using Powershell to check, but I don't know how to translate this into VB .Net code (or even if this is the correct / best way). The office network is not a Domain, so I can't enable sharing through Group Policy.
Has anyone else tackled this?
Thanks,
Tim
发布评论
评论(1)
以下显示了如何使用vb.net中的powershell启用文件和打印机共享。
下载/安装powerShell的nuget软件包
microsoft.powershell.5.1.ReferenceAssemblies
(.net Framework)microsoft.powershell.powershell.sdk
(.NET 6)(.NET 6)请参阅此 post 有关更多信息。
添加以下导入语句:
imports system.Management.Management.Automation
isfileandprintersharingEnabled :
resources :
其他资源
The following shows how to check if File and Printer sharing is enabled using PowerShell in VB.NET.
Download/install NuGet package for PowerShell
Microsoft.PowerShell.5.1.ReferenceAssemblies
(.NET Framework)Microsoft.PowerShell.SDK
(.NET 6)See this post for more information.
Add the following Imports statements:
Imports System.Management.Automation
IsFileAndPrinterSharingEnabled:
Resources:
Other Resources