标题: [代码合集] 批处理怎么在非管理员账户号运行,并且每次运行不用输管理员密码? [打印本页]
作者: csbcsb1990 时间: 2019-7-11 09:32 标题: 批处理怎么在非管理员账户号运行,并且每次运行不用输管理员密码?
- @echo off & setlocal enabledelayedexpansion
- for /f "delims=g" %%a in ('cmd /u /cEcho,有') do set "Tab=%%a"
- set w=wmic diskdrive where "MediaType like 'fixed%%'"
- (for /f "delims=" %%a in ('%w% get model^,size/value^|find "="') do (
- for /f "tokens=1,2delims==" %%b in ("%%a") do (
- if /i "%%b" == "model" (
- set "model=%%~nxc" & set /a i+=1
- set /p=硬盘!i!:%Tab%<nul
- ) else (
- call :GetSize %%~nxc000 size
- if !size! gtr 102400 (
- set /a size/=1024 & set "G=GB"
- ) else set "G=MB"
- set /p=大小: !size:~,-2!.!size:~-2!!G!%Tab%<nul
- set /p=型号: !model!<nul
- echo,
- )
- )
- ))>DiskInfo.txt
-
- set w=wmic logicaldisk where "DriveType='3'"
- for /f "tokens=1-3" %%a in ('%w% get freespace^,name^,size^|find ":"')do (
- set /p=分区%%b%Tab%<nul
- call :GetSize %%a000 free
- call :GetSize %%c000 size
- set /a used=size-free
- if !size! gtr 102400 (
- set "G=GB" & set /a size/=1024,used/=1024
- ) else set "G=MB"
- set /a used=1000*used/size
- if "!used:~,-1!" == "" set "used=0!used!"
- set /p=大小: !size:~,-2!.!size:~-2!!G!%Tab%<nul
- if !free! gtr 102400 (set /a free/=1024 & set "G=GB") else set "G=MB"
- set /p=剩余: !free:~,-2!.!free:~-2!!G!%Tab%<nul
- set /p=使用率: !used:~,-1!.!used:~-1!%%<nul
- echo,
- )>>DiskInfo.txt
- start "" NotePad DiskInfo.txt
- exit/b
-
- :GetSize
- set "num=%1" & set "n=" & set "%2="
- for %%a in (16 8 4 2 1) do (
- if not "!num:~%%a!"=="" set /a n+=%%a & set "num=!num:~%%a!"
- )
- set "num=%1" & set /a n-=6
- for /l %%a in (!n! -1 1) do (
- set "s=!num:~,-%%a!"
- if "!s:~,1!" == "0" set "s=!s:~1!"
- set /a m=s%%1048576,s/=1048576
- set "%2=!%2!!s!"
- set "num=!m!!num:~-%%a!"
- )
- if not defined %2 (
- set "%2=!num:~,-1!"
- ) else if "!%2:~,1!" == "0" set "%2=!%2:~1!"
复制代码
作者: kingshui 时间: 2019-7-11 17:00
本帖最后由 kingshui 于 2019-7-11 17:04 编辑
runas 保存一下凭据,再用runas来运行就可以了。- runas /user:"USERNAME" /savecred "Full path of file"
复制代码
作者: csbcsb1990 时间: 2019-7-12 17:13
回复 2# kingshui
我的意思是在上面的代码中怎么添加命令呢?添加代码后直接运行更改过的批处理直接就以管理员权限运行了。不知如何在以上代码中添加代码来实现。
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |