修改 默认操作系统
2016-01-20 09:55
309 查看
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
相关文章推荐
- Android20_自定义ContentProvider
- Android 漂亮的UI控件
- [Winform][C#]获取系统颜色预定义颜色和现有字体集
- 主席树K-th Number
- 自动化运维的三阶段理论
- java多线程之生产者消费者经典问题
- Android19_ContentProvider之ContentResolver
- Poj 2023 Choose Your Own Adventure
- Python脚本后台运行的几种方式
- erlang shell表格数据对齐
- SDRAM 学习笔记(一)
- Delegate委托相关
- leetcode169---Majority Element(数组中出现次数超过一半的数)
- 关于MAC环境下ADT模拟器无法连接网络的解决方法
- Reactor Pattern Explained - Part 1, 2 and 3
- C++模板(二)
- Android18_WebView
- 广告创意设计类型
- PLSQL工具导入Excel数据用户连接时报错
- 浅析Java中的native关键字