Visual Studio Installer run script as administrator

31 Views Asked by At

I have a .NET solution, My primary project is WinForms. It starts a small web server on localhost as well. This server will be available only in local environment. Now I'm trying to create installation via Visual Studio Installer.

Right now I have problems to create firewall exception for my web server. I tried to add a custom action on install that runs a vbscript. My script follows:

Dim fso, logFile
Set fso = CreateObject("Scripting.FileSystemObject")

Dim logFileName
logFileName = "C:\Temp\InstallationLog.txt"

' Check if log file exists. If not, create it.
If fso.FileExists(logFileName) Then 
    Set logFile = fso.OpenTextFile(logFileName, 8) ' Open for appending
Else
    Set logFile = fso.OpenTextFile(logFileName, 2, True) ' Open for writing
End If

logFile.WriteLine(Date() & " " & Time() & ": Started running VBScript")

If WScript.Arguments.length =0 Then
    Set objShell = CreateObject("Shell.Application")
    'Pass a bogus argument with leading blank space
    objShell.ShellExecute "wscript.exe", Chr(34) & _
      WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
Else
     Dim objShell
     Set objShell = CreateObject("WScript.Shell")
     objShell.Run "cmd /c netsh advfirewall firewall add rule name=""DeviceException"" dir=in action=allow protocol=TCP localport=8001", 0, True
End If

logFile.WriteLine(Date() & " " & Time() & ": Finished running VBScript")
logFile.Close

This script executed on the console does everything correctly but trying to do the same via installer install i have the following error:

A script required for this install to complete could not be run.

I might be entirely on a wrong path and there might be a better ways to configure the firewall exception. But later I need to do something similar with installing a windows driver, which will bring me to the same problem.

0

There are 0 best solutions below