gpt4 book ai didi

powershell - 通过脚本(批处理/powershell)将网络文件/文件夹设置为离线

转载 作者:行者123 更新时间:2023-12-03 00:11:18 24 4
gpt4 key购买 nike

我正在尝试自动执行右键单击文件夹或文件然后单击 Windows 7+ 中的“始终离线可用”的过程。

我一直无法找到任何命令或批处理方法来执行此操作。到目前为止,我发现了这个 powershell 脚本,它模拟了对上下文菜单项的右键单击操作(在我的情况下始终可以离线使用)。

$o = New-Object -ComObject Shell.Application
$o.Namespace("Z:\").Self.verbs() | `
Where-Object { $_.Name -eq 'Always &available offline' } | `
ForEach-Object { $_.DoIt() }

它不起作用。

如果我尝试传递文件夹或 UNC 路径而不是驱动器(比方说 Z:\foldertomakeavailableoffline),我得到的只是“您不能在 null-值表达式。” 就好像我指定的文件夹不存在一样。

感谢任何帮助。

谢谢。

最佳答案

如果您像这样发布您的 $o.Namespace("Z:\").Self.verbs() 结果将会很有帮助:

我的是:

Name                                     
----
&Open
Git &Add all files now
Git &Commit Tool
Git &History
Git &Gui

Git Ba&sh
Scan for Viruses...
Hg &Workbench

Restore previous &versions

Combine files in Acrobat...
Select &Left Folder for Compare

&Disconnect
&Copy
Create &shortcut
Rena&me
P&roperties

在我看来,这里的问题是您看不到它,这就是 id 不起作用的原因。 (它也是非典型的菜单项,因为值为 true/false)。

我会尝试按照以下“pinning”方式进行操作:

如果您需要为用户固定文件夹/文件,请尝试以下操作:

$path = “\\path_to\shared\folder”
$objWMI = [wmiclass]”\\.\root\cimv2:win32_offlinefilescache”
$objWMI.Pin($path, 0x00001221, $true)

它使用这些位:0x00001221

OfflineFilesPinControlFlagFill (0x00000001)

Fills the item in addition to pinning it. This results in the item being fully cached as part of the pin operation. If this flag is not set, the item is only pinned and must wait to be filled by some other means of synchronization. Note that the Offline Files service periodically fills files in the background. If immediate offline availability is not necessary, it may be better (performance-wise) to not set this flag and let the service fill the file in the background.

OfflineFilesPinControlFlagForUser (0x00000020)

Pins the items for the calling user. This is the flag typically set for a caller of this function. It is important to note that Offline Files does not support a true per-user notion of pinning. When an item is pinned for a user, it is pinned for all users of that machine. An item that is pinned with this flag can be unpinned by any user who has access to that file. The ability to access that pinned file depends on the user's access rights to that file computed while online.

OfflineFilesPinControlFlagLowPriority (0x00000200)

Reserved for future use. (I like to use this one for it is LowPriority not to clog the system)

OfflineFilesPinControlFlagConsole (0x00001000)

This flag is ignored if the OfflineFilesPinControlFlagInteractive flag is not set. If the OfflineFilesPinControlFlagInteractive flag is set, this flag indicates that any UI produced should be directed to the console window associated with the process invoking the operation.

关于powershell - 通过脚本(批处理/powershell)将网络文件/文件夹设置为离线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47757985/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com