修改 默认操作系统

来源:互联网 发布:淘宝网男士卫衣 编辑:程序博客网 时间:2024/05/16 01:00
OptionExplicit

'切换默认操作系统(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
    
    ForEach SystemDrive InGetObject("winmgmts:").InstancesOf("Win32_OperatingSystem")
        SystemDrive = SystemDrive.SystemDrive
        ExitFor
    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
    DoWhileTrue
        IfNot fso.FolderExists(temp_hxy) Then
            fso.CreateFolder(temp_hxy)
        ElseIf fso.FileExists(temp_hxy_bcdedittxt) Then
            fso.DeleteFile(temp_hxy_bcdedittxt)
        EndIf
    
        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
        LoopUntilInStr(temp, "displayorder            {")
        
        j = 0
        k = 0
        Do
            If j < i Then
                temp = file.ReadLine
                j = j + 1
            ElseIfInStr("{" & 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
                ExitDo
            EndIf
        LoopUntilInStr(temp, "toolsdisplayorder       {")
        file.Close
        Set file = Nothing
        
        If k = 0ThenExitDo
        i = i + 1
        WScript.Sleep 5000
    Loop
    
    
    Set WshNetwork = Nothing
    Set fso = Nothing
    Set WshShell = Nothing
EndSub


'获取管理员权限
Dim objOS
ForEach objOS inGetObject("winmgmts:").InstancesOf("Win32_OperatingSystem")
    IfInStr(objOS.Caption, "XP") = 0Then
        If WScript.Arguments.length = 0Then
            Dim objShell : Set objShell = CreateObject("Shell.Application")
            objShell.ShellExecute "wscript.exe", Chr(34) & WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
        Else
            RunScript
        EndIf
    Else
        RunScript
    EndIf
Next

WScript.Quit
0 0
原创粉丝点击