找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 15379|回复: 5

[问题求助] 【已解决】怎样将获取注册表SID的bat文件vbs文件?

[复制链接]
发表于 2021-8-30 09:47:41 | 显示全部楼层 |阅读模式
本帖最后由 yyz219 于 2021-12-25 08:51 编辑

完美解决了

复制【sid】(默静}。vbs


'【获取“注册表sid,并生成“注册表数字串.txt”文件】
set path=wscript.createobject("wscript.shell")
name=path.ExpandEnvironmentStrings("%username%")
strComputer = "."
Set wbemServices = Getobject("winmgmts:\\" & strComputer)
Set wbemObjectSet=wbemServices.execquery("select sid from win32_userAccount where name='"&name&"'")
For Each mo In wbemObjectSet
  sSID = mo.sid
Next
If(sSID = "")Then
Else
  set fso = CreateObject("Scripting.FileSystemObject")
  currentpath = createobject("Scripting.FileSystemObject").GetFolder(".").Path
  set f = fso.CreateTextFile(currentpath&"\"&"注册表数字串.txt", true)
  f.Write sSID
  f.Close()
  set f = nothing
  set fso = nothing
End If

'【复制“注册表数字串.txt”里面内容到剪切板】
set ws=createobject("wscript.shell")
set fso=createobject("scripting.filesystemobject")
set f=fso.opentextfile("注册表数字串.txt",1)
ws.run "mshta vbscript:ClipBoardData.setData(""Text"","""&f.readall&""")(window.close)", 0, true
createobject("wscript.shell").run "cmd /c del 注册表数字串.txt",0    '【删除:注册表数字串.txt】

CreateObject("WScript.Shell").Run "cmd /c  D:\1绿色软件\bat批处理\已经复制.bat",1   '【 行末尾的 ,0表示隐藏窗口】
 楼主| 发表于 2021-8-30 13:52:29 | 显示全部楼层
我自己写成下面,请大侠看看能不能简化?谢谢!

'【获取注册表sid并生存文本:“注册表数字串.txt”】
set fso=CreateObject("Scripting.FileSystemObject")
set fw=fso.createtextfile("获取sid.bat",2)
fw.writeline("@echo off" )
fw.writeline("for /f ""delims="" %%a in ('wmic userAccount where ""Name='%userName%'"" get SID /value') do call set %%a>nul")
fw.writeline("echo %sid%>注册表数字串.txt  %【本行和上一行:获取注册表数字串( sid),并且写入“注册表数字串.txt”】%")
fw.writeline("exit")
CreateObject("WScript.Shell").Run "cmd /c  获取sid.bat",0   '【 行末尾的 ,0表示隐藏窗口】
发表于 2021-8-31 06:49:13 | 显示全部楼层
不是要生成注册表里没有的吗?你这是要把所有的取出来?
 楼主| 发表于 2021-8-31 07:19:57 | 显示全部楼层
不是要生成注册表里没有的吗?你这是要把所有的取出来?
窄口牛 发表于 2021-8-31 06:49



    不容易取出来
发表于 2021-8-31 19:56:55 | 显示全部楼层
本帖最后由 aries215 于 2021-8-31 20:14 编辑

查询注册表获取SID是最简便的,环境依赖最少,不用生成中间文件。
  1. @echo off
  2. for /f "delims=\ tokens=2" %%a in ('reg query "HKU" /k /f "S-1-5-21-" 2^>nul') do (set "usid=%%~a" && goto end)
  3. :end
  4. echo %UserName%:%usid%
  5. pause
复制代码
还有键值:HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI
 楼主| 发表于 2021-8-31 20:08:01 | 显示全部楼层
回复 5# aries215

我还希望能够复制到剪切板,粘贴的时候不换行

我的最终解决方案是:复制【sid】(默静}.vbs


'【获取“注册表sid,并生成“注册表数字串.txt”文件】
set path=wscript.createobject("wscript.shell")
name=path.ExpandEnvironmentStrings("%username%")
strComputer = "."
Set wbemServices = Getobject("winmgmts:\\" & strComputer)
Set wbemObjectSet=wbemServices.execquery("select sid from win32_userAccount where name='"&name&"'")
For Each mo In wbemObjectSet
  sSID = mo.sid
Next
If(sSID = "")Then
Else
  set fso = CreateObject("Scripting.FileSystemObject")
  currentpath = createobject("Scripting.FileSystemObject").GetFolder(".").Path
  set f = fso.CreateTextFile(currentpath&"\"&"注册表数字串.txt", true)
  f.Write sSID
  f.Close()
  set f = nothing
  set fso = nothing
End If

'【复制“注册表数字串.txt”里面内容到剪切板】
set ws=createobject("wscript.shell")
set fso=createobject("scripting.filesystemobject")
set f=fso.opentextfile("注册表数字串.txt",1)
ws.run "mshta vbscript:ClipBoardData.setData(""Text"","""&f.readall&""")(window.close)", 0, true
createobject("wscript.shell").run "cmd /c del 注册表数字串.txt",0    '【删除:注册表数字串.txt】
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-16 22:03 , Processed in 0.018022 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表