You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

系统用户运行批处理时,如何访问指定用户的%APPDATA%(SCCM场景)

Fixing Wireshark Preference Deployment via SCCM

I get it—deploying apps with SCCM can be tricky when user-specific folders are involved, especially since SCCM runs as the SYSTEM account by default. Let's break down why your script is failing and how to fix it.

Root Cause

When SCCM runs your batch script as SYSTEM, the %APPDATA% environment variable points to the system profile (C:\Windows\System32\config\systemprofile\AppData\Roaming\), not the individual user's profile. That's why your preferences file ends up in the wrong place when using PSEXEC to simulate SYSTEM context.

Solution 1: Modify Your Batch Script to Target All User Profiles

This approach will install Wireshark, copy the preferences to the default user profile (so new users inherit it automatically), and push the file to all existing user profiles. Here's the updated script:

@echo off
REM Install Wireshark silently
Wireshark-win64-2.4.6.exe /S

REM Copy preferences to Default User profile (for new users)
mkdir "C:\Users\Default\AppData\Roaming\Wireshark" 2>nul
xcopy /Y "preferences" "C:\Users\Default\AppData\Roaming\Wireshark\"

REM Copy preferences to all existing user profiles (excluding system accounts)
for /f "tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" /v ProfileImagePath ^| findstr /v "SystemProfile" ^| findstr /v "Public"') do (
    set "userProfile=%%b"
    mkdir "%userProfile%\AppData\Roaming\Wireshark" 2>nul
    xcopy /Y "preferences" "%userProfile%\AppData\Roaming\Wireshark\"
)

Key Details:

  • 2>nul suppresses error messages if the Wireshark folder already exists.
  • /Y in xcopy overwrites existing preferences files without prompting.
  • The reg query command pulls all user profile paths from the registry, then we filter out system accounts (SystemProfile and Public) to avoid unnecessary copies.
  • Make sure the preferences file is in the same directory as your batch script (or use a full path to where it's stored in your SCCM package source).

How to Test:

Use PSEXEC to run the script as SYSTEM to verify it works:

psexec -s cmd.exe /c "path\to\your\script.bat"

Check the Default User folder and existing user profiles to confirm the preferences file was copied correctly.

Solution 2: Deploy Preferences via User Context (SCCM User Package)

If you prefer to handle user-specific settings separately from the machine installation, create a second SCCM package that runs in user context:

  1. Create a new package with just your preferences file.
  2. Create a batch script for this package:
    mkdir %APPDATA%\Wireshark\ 2>nul
    xcopy /Y "\\your-sccm-server\package-source\preferences" "%APPDATA%\Wireshark\"
    
  3. Deploy this package as a required user deployment (not machine) to all relevant users. This ensures the file is copied to the user's %APPDATA% when they log in.

Why This Works:

When deployed in user context, %APPDATA% correctly points to the logged-in user's Roaming folder. This is great for ensuring even users who log in after the initial machine deployment get the preferences.

Recommendation

Combine both solutions for full coverage:

  1. Use the modified machine script to install Wireshark and set up preferences for existing users and new users via the Default profile.
  2. Deploy the user package as a fallback to catch any edge cases (like users who created profiles after the machine deployment).

内容的提问来源于stack exchange,提问作者Chris Higg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 06:16:36