修改 默认操作系统
来源:互联网 发布:淘宝网男士卫衣 编辑:程序博客网 时间:2024/05/16 01:00
Option Explicit
'切换默认操作系统(XP系统除外)
Sub RunScript
Dim WshNetwork, fso, WshShell
Set WshNetwork = CreateObject("WScript.Network")
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
Dim SystemDrive, temp, temp_hxy, temp_hxy_bcdedittxt, file
For Each SystemDrive In GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem")
SystemDrive = SystemDrive.SystemDrive
Exit For
Next
temp = SystemDrive & "\Users\" & WshNetwork.UserName & "\AppData\Local\Temp"
temp_hxy = temp & "\hxy"
temp_hxy_bcdedittxt = temp_hxy & "\bcdedit.txt"
Dim i, j, k
i = 0
Do While True
If Not fso.FolderExists(temp_hxy) Then
fso.CreateFolder(temp_hxy)
ElseIf fso.FileExists(temp_hxy_bcdedittxt) Then
fso.DeleteFile(temp_hxy_bcdedittxt)
End If
WshShell.Run "cmd.exe /c bcdedit >> " & temp_hxy_bcdedittxt, 0
WScript.Sleep 1000
Set file = fso.OpenTextFile(temp_hxy_bcdedittxt, 1, False)
Do
temp = file.ReadLine
Loop Until InStr(temp, "displayorder {")
j = 0
k = 0
Do
If j < i Then
temp = file.ReadLine
j = j + 1
ElseIf InStr("{" & Split(temp, "{")(1), "{ntldr}") Then
temp = file.ReadLine
j = j + 1
k = 1
Else
WshShell.Run "cmd.exe /c bcdedit /default " & "{" & Split(temp, "{")(1), 0
k = 1
Exit Do
End If
Loop Until InStr(temp, "toolsdisplayorder {")
file.Close
Set file = Nothing
If k = 0 Then Exit Do
i = i + 1
WScript.Sleep 5000
Loop
Set WshNetwork = Nothing
Set fso = Nothing
Set WshShell = Nothing
End Sub
'获取管理员权限
Dim objOS
For Each objOS in GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem")
If InStr(objOS.Caption, "XP") = 0 Then
If WScript.Arguments.length = 0 Then
Dim objShell : Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "wscript.exe", Chr(34) & WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
Else
RunScript
End If
Else
RunScript
End If
Next
WScript.Quit
'切换默认操作系统(XP系统除外)
Sub RunScript
Dim WshNetwork, fso, WshShell
Set WshNetwork = CreateObject("WScript.Network")
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
Dim SystemDrive, temp, temp_hxy, temp_hxy_bcdedittxt, file
For Each SystemDrive In GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem")
SystemDrive = SystemDrive.SystemDrive
Exit For
Next
temp = SystemDrive & "\Users\" & WshNetwork.UserName & "\AppData\Local\Temp"
temp_hxy = temp & "\hxy"
temp_hxy_bcdedittxt = temp_hxy & "\bcdedit.txt"
Dim i, j, k
i = 0
Do While True
If Not fso.FolderExists(temp_hxy) Then
fso.CreateFolder(temp_hxy)
ElseIf fso.FileExists(temp_hxy_bcdedittxt) Then
fso.DeleteFile(temp_hxy_bcdedittxt)
End If
WshShell.Run "cmd.exe /c bcdedit >> " & temp_hxy_bcdedittxt, 0
WScript.Sleep 1000
Set file = fso.OpenTextFile(temp_hxy_bcdedittxt, 1, False)
Do
temp = file.ReadLine
Loop Until InStr(temp, "displayorder {")
j = 0
k = 0
Do
If j < i Then
temp = file.ReadLine
j = j + 1
ElseIf InStr("{" & Split(temp, "{")(1), "{ntldr}") Then
temp = file.ReadLine
j = j + 1
k = 1
Else
WshShell.Run "cmd.exe /c bcdedit /default " & "{" & Split(temp, "{")(1), 0
k = 1
Exit Do
End If
Loop Until InStr(temp, "toolsdisplayorder {")
file.Close
Set file = Nothing
If k = 0 Then Exit Do
i = i + 1
WScript.Sleep 5000
Loop
Set WshNetwork = Nothing
Set fso = Nothing
Set WshShell = Nothing
End Sub
'获取管理员权限
Dim objOS
For Each objOS in GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem")
If InStr(objOS.Caption, "XP") = 0 Then
If WScript.Arguments.length = 0 Then
Dim objShell : Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "wscript.exe", Chr(34) & WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
Else
RunScript
End If
Else
RunScript
End If
Next
WScript.Quit
0 0
- 修改 默认操作系统
- 修改unix操作系统默认语言
- 更改开机默认操作系统及等待时间修改
- 修改Ubuntu操作系统root默认密码
- CentOS 7 grub Linux 修改默认的启动操作系统
- 修改系统默认的TTL值-预防被探测操作系统
- 在GRUB中修改多操作系统的启动顺序和默认启动系统
- 如何查询和修改Linux操作系统生成core dump文件的默认路径
- 安装Ubuntu后,图形界面下修改Windows的为默认操作系统,并且更新Ubuntu后不变
- 在mac操作系统下,Intellij IDEA默认jdk版本的修改
- 在mac操作系统下,Intellij IDEA默认jdk版本的修改
- 在mac操作系统下,Intellij IDEA默认jdk版本的修改
- 如何查询和修改Linux操作系统生成core dump文件的默认路径
- 如何查询和修改Linux操作系统生成core dump文件的默认路径?
- Android操作系统默认图片
- 操作系统默认TTL值
- 各种操作系统Apache默认路径
- 【操作系统】修改linux字符集
- Android19_ContentProvider之ContentResolver
- java多线程之生产者消费者经典问题
- Poj 2023 Choose Your Own Adventure
- Android 漂亮的UI控件
- Python脚本后台运行的几种方式
- 修改 默认操作系统
- [Dataguard]ORA-16191: Primary log shipping client not logged on standby问题解决
- Linux常用命令
- 深入理解rem、px、em
- Android20_自定义ContentProvider
- justep工具使用(配置和简单例子)
- 如何用Maven创建web项目(具体步骤)
- 面试时绝对不能说的 10 句话
- python 使用thrift序列化与反序列化对象