标题: [系统相关] 添加用户到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,想通过域登录脚本的批处理来实现,现在本人只能加组的批
处理,不能根据条件来加入组:- net localgroup administrators %userdomain%\%username% /del
- net localgroup "power users" %userdomain%\%username% /add
复制代码
请问用批处理怎么利用计算机名中的L和D来分别加到各自的组,谢谢.
作者: Seter 时间: 2009-11-14 21:20
具体怎么我不懂,但我还是写了个,具体就是用%username:~,1%和if来实现- if "%username:~,1%"=="l" (
- net localgroup "network configuration operators" %userdomain%\%username% /add
- ) else (
- net localgroup "power users" %userdomain%\%username% /add
- )
复制代码
作者: 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- @echo off
- for /f "tokens=2 delims={}" %%i in ('wmic Path Win32_SystemEnclosure get ChassisTypes /value') do (
- set "CompType=%%i"
- )
- if "%CompType%" equ "3" (
- echo 台式机
- ) else if "%CompType%" equ "10" (
- echo 笔记本
- ) else (
- echo 未知
- )
- pause
复制代码
test-2.bat
根据 PCSystemType 判断
https://learn.microsoft.com/en-us/dotnet/api/microsoft.powershell.commands.pcsystemtype?view=powershellsdk-1.1.0- @echo off
- for /f "tokens=2 delims==" %%i in ('wmic ComputerSystem get PCSystemType /value') do (
- for %%a in ("%%i") do (
- set "CompType=%%~a"
- )
- )
- if "%CompType%" equ "1" (
- echo 台式机
- ) else if "%CompType%" equ "2" (
- echo 笔记本
- ) else (
- echo 未知
- )
- pause
复制代码
test-3.bat
根据 PCSystemType 判断
https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-battery- @echo off
- for /f "tokens=2 delims==" %%i in ('wmic Path Win32_Battery Get BatteryStatus 2^>nul') do (
- for %%a in ("%%i") do (
- set "BatteryValue=%%~a"
- )
- )
- if "%BatteryValue%" equ "1" (
- echo 笔记本
- ) else if "%BatteryValue%" equ "2" (
- echo 笔记本
- ) else (
- echo 台式机
- )
- pause
复制代码
test-4.bat
综合多个条件进行判断- @echo off
- set "DesktopVote=0"
- set "LaptopVote=0"
-
- for /f "tokens=2 delims={}" %%i in ('wmic Path Win32_SystemEnclosure get ChassisTypes /value') do (
- set "CompType=%%i"
- )
- if "%CompType%" equ "3" (
- set /a DesktopVote+=1
- ) else if "%CompType%" equ "10" (
- set /a LaptopVote+=1
- )
-
- for /f "tokens=2 delims==" %%i in ('wmic ComputerSystem get PCSystemType /value') do (
- for %%a in ("%%i") do (
- set "CompType=%%~a"
- )
- )
- if "%CompType%" equ "1" (
- set /a DesktopVote+=1
- ) else if "%CompType%" equ "2" (
- set /a LaptopVote+=1
- )
-
- for /f "tokens=2 delims==" %%i in ('wmic Path Win32_Battery Get BatteryStatus /value 2^>nul') do (
- for %%a in ("%%i") do (
- set "BatteryValue=%%~a"
- )
- )
- if "%BatteryValue%" equ "1" (
- set /a LaptopVote+=1
- ) else if "%BatteryValue%" equ "2" (
- set /a LaptopVote+=1
- ) else (
- set /a DesktopVote+=1
- )
-
- if %LaptopVote% gtr %DesktopVote% (
- echo 笔记本
- ) else if %LaptopVote% lss %DesktopVote% (
- echo 台式机
- ) else (
- echo 未知
- )
- pause
复制代码
作者: dennylsg 时间: 2009-11-15 13:25
thank you,终于写出来了.- if /i "%computername:~6,1%"=="d" (
- net localgroup administrators %userdomain%\%username% /del net localgroup "power users" %userdomain%\%username% /add
- ) else (
- net localgroup administrators %userdomain%\%username% /del net localgroup "network configuration operators" %userdomain%\%username% /add
- )
复制代码
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |