6

DynamicsGPを実行します。フォーム/レポートの保存方法のため、.SETファイルをプログラムディレクトリにコピーするインストールスクリプトが必要です。これは手動で行うことができますが、ユーザーに適切なファイルをインストールするインストーラースクリプトを実行させる方がはるかに高速です。

必要なファイルをコピーするVBScriptインストーラーを構築してきました。トリッキーな部分は、一部のクライアントがWindows XPを実行しており、一部のクライアントがWindows 7(または8)を実行していることです。UACが有効になっているため、アクセス許可が有効になります。

私が試みた方法は、やみくもにファイルをコピーしようとすることであり、アクセス許可エラーが検出された場合は、管理者アクセス許可でスクリプトを再起動します。問題が発生したのは、一部の(すべて?)Windows 7マシンで仮想化されたファイル/レジストリの書き込みが有効になっているため、スクリプトがファイルをC:\ Program Files \ Microsoft Dynamics \ GP2010にコピーしようとすると、サイレントに失敗してコピーします。ユーザーのAppData\Local\VirtualStoreディレクトリに移動します。これはGPでは正しく機能しません。

したがって、スクリプトでファイルをC:\ Program Files(VirtualStoreディレクトリではなく)にコピーし、必要な場合にのみアクセス許可を昇格させる必要があります。全面的に昇格させると、Windows XPマシンは、スクリプトの起動時に不可解な[実行]ダイアログボックスを表示するだけです。

これが私がこれまでに持っているものです:

Dim WSHShell, FSO, Desktop, DesktopPath
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WSHShell = CreateObject("WScript.Shell")
Desktop = WSHShell.SpecialFolders("Desktop")
DesktopPath = FSO.GetAbsolutePathName(Desktop)

'Set working directory to directory the script is in.
'This ends up being C:\Windows\System32 if the script is
'started from ShellExecute, or a link in an email, thus breaking
'relative paths.
WSHShell.CurrentDirectory = FSO.GetFile(WScript.ScriptFullName).ParentFolder

On Error Resume Next

If FSO.FolderExists("C:\Program Files (x86)") Then
    WScript.Echo "Installing 64-bit."
    FSO.CopyFile "64-bit\*.set", "C:\Program Files (x86)\Microsoft Dynamics\GP2010\", True
    FSO.CopyFile "64-bit\*.lnk", DesktopPath, True
ElseIf FSO.FolderExists("C:\Program Files\Microsoft Dynamics\GP2010\Mekorma MICR") Then
    WScript.Echo "Installing 32-bit (with MICR)."
    FSO.CopyFile "32-bit MICR\*.set", "C:\Program Files\Microsoft Dynamics\GP2010\", True
    FSO.CopyFile "32-bit MICR\*.lnk", DesktopPath, True 
Else
    WScript.Echo "Installing 32-bit."
    FSO.CopyFile "32-bit\*.SET", "C:\Program Files\Microsoft Dynamics\GP2010\", True
    FSO.CopyFile "32-bit\*.lnk", DesktopPath, True
End If

If Err.Number = 70 Then
    CreateObject("Shell.Application").ShellExecute "wscript.exe", """" & WScript.ScriptFullName & """" , "", "runas", 1
    WScript.Quit
ElseIf Err.Number <> 0 Then
    MsgBox "Error " & Err.Number & vbCrLf & Err.Source & vbCrLf & Err.Description
Else
    MsgBox "Installed successfully."
End If

要約: 「実行」ダイアログボックスでXPを停止させず、代わりにWindows7でファイルをAppData\ Local \ VirtualStoreにコピーせに、VBScriptでアクセス許可を昇格させるにはどうすればよいですか?

4

2 に答える 2

5

@ db2の回答を改善しました:

  • 渡された引数に依存せずに、実際の標高テスト
  • すべての元の引数を昇格されたスクリプトに渡します
  • 最初のスクリプトと同じホストを使用します:wscript.exe、、cscript.exe何でも

コード:

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
        With CreateObject("WScript.Shell")
            IsElevated = .Run("cmd.exe /c ""whoami /groups|findstr S-1-16-12288""", 0, true) = 0
            If Not IsElevated Then
                Dim AllArgs
                For Each Arg In WScript.Arguments
                    If InStr( Arg, " " ) Then Arg = """" & Arg & """"
                    AllArgs = AllArgs & " " & Arg
                Next
                Command = """" & WScript.ScriptFullName & """" & AllArgs
                With CreateObject("Shell.Application")
                    .ShellExecute WScript.FullName, " //nologo " & Command, "", "runas", 1
                    WScript.Echo WScript.FullName & " //nologo " & Command
                End With
                WScript.Quit
            End If
        End With
    End If
Next

' Place code to run elevated here
于 2016-01-07T02:07:29.060 に答える
4

これが最も簡単な方法のようです。

  1. OSのバージョンを確認してください。
  2. XPまたは2003でない場合(これが古いもので実行されるとは思わない)、昇格して再実行します。

スクリプトの先頭に追加したコードブロックは次のとおりです。

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
于 2012-11-09T13:26:46.093 に答える