Permission elevation from VBScript

前端 未结 2 963
时光说笑
时光说笑 2020-12-17 02:00

We run Dynamics GP. Because of the way it stores forms/reports, I need to have some install scripts that copy a .SET file into the program directory. This can be done manual

2条回答
  •  暖寄归人
    2020-12-17 02:34

    Seems like this is the simplest way to do it.

    1. Check OS version.
    2. If it's not XP or 2003 (I don't anticipate this running on anything older), re-execute with elevation.

    Here's the code block I added to the beginning of the script:

    Dim OSList, OS, UAC
    UAC = False
    If WScript.Arguments.Count >= 1 Then
        If WScript.Arguments.Item(0) = "elevated" Then UAC = True
    End If
    
    If Not(UAC) Then
        Set OSList = GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem")
        For Each OS In OSList
            If InStr(1, OS.Caption, "XP") = 0 And InStr(1, OS.Caption, "Server 2003") = 0 Then
                CreateObject("Shell.Application").ShellExecute "wscript.exe", """" & WScript.ScriptFullName & """ elevated" , "", "runas", 1
                WScript.Quit
            End If
        Next
    End If
    

提交回复
热议问题