Skip to content

Instantly share code, notes, and snippets.

@lukeawyatt
Last active June 30, 2022 06:44
Show Gist options
  • Save lukeawyatt/255aa251019879d0a72cd43f22c0494e to your computer and use it in GitHub Desktop.
Save lukeawyatt/255aa251019879d0a72cd43f22c0494e to your computer and use it in GitHub Desktop.
System: Windows Service Installer
C:\Test Services\Service Controller\Vendors.ServiceController.exe
Option Explicit
Dim oShell, WshShell, Title, strInputIU, strInputPATH, executeString, objShell, strCurrentDir, result, filesys
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objShell = CreateObject("WScript.shell")
Set filesys = CreateObject("Scripting.FileSystemObject")
strCurrentDir = objShell.CurrentDirectory
If WScript.Arguments.Named.Exists("elevated") = False Then
CreateObject("Shell.Application").ShellExecute "wscript.exe", """" & WScript.ScriptFullName & """ /elevated", "", "runas", 1
WScript.Quit
Else
Set oShell = CreateObject("WScript.Shell")
oShell.CurrentDirectory = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)
End If
Title = "Windows Service Installer by Luke Wyatt"
executeString = "@echo off & cd \ & cd C:\Windows\Microsoft.NET\Framework\v2.0.50727"
strInputIU = InputBox( "If you would like to install a service, type I. If you are trying to uninstall a service, type U.", Title )
result = MsgBox("Would you like to load the path from the save file?", VBYesNo, Title)
If (result = VBYes) Then
Set objShell = CreateObject("WScript.shell")
strCurrentDir = objShell.CurrentDirectory
strInputPATH = readFile(strCurrentDir & "\path.txt")
Else
strInputPATH = InputBox( "Enter the file location of the Windows Service Executable that you are trying to install or uninstall:", Title )
End If
If filesys.FileExists(strInputPATH) Then
'DO NOTHING
Else
WScript.echo "The file path given does not exist or cannot be reached: Application closing."
WScript.quit
End if
If (strInputIU = "i") or (strInputIU = "I") Then
executeString = executeString & " & InstallUtil " & chr(34) & strInputPATH & chr(34)
WshShell.Run("cmd /k" + executeString)
ElseIf (strInputIU = "u") or (strInputIU = "U") Then
executeString = executeString & " & InstallUtil -u " & chr(34) & strInputPATH & chr(34)
WshShell.Run("cmd /k" + executeString)
Else
WScript.Echo "Selection was cancelled or inputted incorrectly: Application closing."
WScript.quit
End If
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function readFile(sPath)
const forReading = 1
dim objFSO, objFile, sData
set objFSO = createobject("Scripting.FileSystemObject")
set objFile = objFSO.openTextFile(sPath, ForReading)
sData = ""
do until objFile.atEndOfStream
sData = sData & objFile.readLine & vbCrLf
loop
objFile.close
set objFile = nothing
set objFSO = nothing
readFile = sData
end function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment