Board logo

标题: [系统相关] 添加用户到power users组或network configuration operators组 [打印本页]

作者: dennylsg    时间: 2009-11-14 20:58     标题: 添加用户到power users组或network configuration operators组

Hi,我们公司想实现这样一个需求:首先公司的计算机命名方法是:laptop:CNGZ01LXXX,desktop:CNGZ01DXXX,现在公司里面所有的域帐号都加入到计算机本地的administrators组,现
在需要减少用户的权限,把用desktop的用户加入到power users组,用laptop的加入到network configuration operators,想通过域登录脚本的批处理来实现,现在本人只能加组的批
处理,不能根据条件来加入组:
  1. net localgroup administrators %userdomain%\%username% /del
  2. net localgroup "power users" %userdomain%\%username% /add
复制代码
请问用批处理怎么利用计算机名中的L和D来分别加到各自的组,谢谢.
作者: Seter    时间: 2009-11-14 21:20

具体怎么我不懂,但我还是写了个,具体就是用%username:~,1%和if来实现
  1. if "%username:~,1%"=="l" (
  2. net localgroup "network configuration operators" %userdomain%\%username% /add
  3. ) else (
  4. net localgroup "power users" %userdomain%\%username% /add
  5. )
复制代码

作者: Batcher    时间: 2009-11-15 10:36

test-1.bat
根据 ChassisTypes 判断
https://devblogs.microsoft.com/scripting/how-can-i-determine-if-a-computer-is-a-laptop-or-a-desktop-machine
  1. @echo off
  2. for /f "tokens=2 delims={}" %%i in ('wmic Path Win32_SystemEnclosure get ChassisTypes /value') do (
  3.     set "CompType=%%i"
  4. )
  5. if "%CompType%" equ "3" (
  6.     echo 台式机
  7. ) else if "%CompType%" equ "10" (
  8.     echo 笔记本
  9. ) else (
  10.     echo 未知
  11. )
  12. pause
复制代码
test-2.bat
根据 PCSystemType 判断
https://learn.microsoft.com/en-us/dotnet/api/microsoft.powershell.commands.pcsystemtype?view=powershellsdk-1.1.0
  1. @echo off
  2. for /f "tokens=2 delims==" %%i in ('wmic ComputerSystem get PCSystemType /value') do (
  3.     for %%a in ("%%i") do (
  4.         set "CompType=%%~a"
  5.     )
  6. )
  7. if "%CompType%" equ "1" (
  8.     echo 台式机
  9. ) else if "%CompType%" equ "2" (
  10.     echo 笔记本
  11. ) else (
  12.     echo 未知
  13. )
  14. pause
复制代码
test-3.bat
根据 PCSystemType 判断
https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-battery
  1. @echo off
  2. for /f "tokens=2 delims==" %%i in ('wmic Path Win32_Battery Get BatteryStatus 2^>nul') do (
  3.     for %%a in ("%%i") do (
  4.         set "BatteryValue=%%~a"
  5.     )
  6. )
  7. if "%BatteryValue%" equ "1" (
  8.     echo 笔记本
  9. ) else if "%BatteryValue%" equ "2" (
  10.     echo 笔记本
  11. ) else (
  12.     echo 台式机
  13. )
  14. pause
复制代码
test-4.bat
综合多个条件进行判断
  1. @echo off
  2. set "DesktopVote=0"
  3. set "LaptopVote=0"
  4. for /f "tokens=2 delims={}" %%i in ('wmic Path Win32_SystemEnclosure get ChassisTypes /value') do (
  5.     set "CompType=%%i"
  6. )
  7. if "%CompType%" equ "3" (
  8.     set /a DesktopVote+=1
  9. ) else if "%CompType%" equ "10" (
  10.     set /a LaptopVote+=1
  11. )
  12. for /f "tokens=2 delims==" %%i in ('wmic ComputerSystem get PCSystemType /value') do (
  13.     for %%a in ("%%i") do (
  14.         set "CompType=%%~a"
  15.     )
  16. )
  17. if "%CompType%" equ "1" (
  18.     set /a DesktopVote+=1
  19. ) else if "%CompType%" equ "2" (
  20.     set /a LaptopVote+=1
  21. )
  22. for /f "tokens=2 delims==" %%i in ('wmic Path Win32_Battery Get BatteryStatus /value 2^>nul') do (
  23.     for %%a in ("%%i") do (
  24.         set "BatteryValue=%%~a"
  25.     )
  26. )
  27. if "%BatteryValue%" equ "1" (
  28.     set /a LaptopVote+=1
  29. ) else if "%BatteryValue%" equ "2" (
  30.     set /a LaptopVote+=1
  31. ) else (
  32.     set /a DesktopVote+=1
  33. )
  34. if %LaptopVote% gtr %DesktopVote% (
  35.     echo 笔记本
  36. ) else if %LaptopVote% lss %DesktopVote% (
  37.     echo 台式机
  38. ) else (
  39.     echo 未知
  40. )
  41. pause
复制代码

作者: dennylsg    时间: 2009-11-15 13:25

thank you,终于写出来了.
  1. if /i "%computername:~6,1%"=="d" (
  2. net localgroup administrators %userdomain%\%username% /del net localgroup "power users" %userdomain%\%username% /add
  3. ) else (
  4. net localgroup administrators %userdomain%\%username% /del net localgroup "network configuration operators" %userdomain%\%username% /add
  5. )
复制代码





欢迎光临 批处理之家 (http://bathome.net./) Powered by Discuz! 7.2