您的位置:首页 > 其它

修改 默认操作系统

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: