none
Running a VBS script with no prompt and elevated permissions RRS feed

  • Question

  • Need to run a vbs that silently opens a batch file - which stops a service in this case, however need a line or two allowing it to runas (Windows 2012) 

    These are for training labs where the student should not see what the script is doing and cannot access the folder where the actual BAT file is. 

    Here is the basic vbs: 

    Set WshShell = CreateObject("WScript.Shell" ) 
    WshShell.Run chr(34) & "D:\TrainingScripts\Script01.bat" & Chr(34), 0
    Set WshShell = Nothing 

    Please can someone put me out of my misery where to add something like:  & """", , "runas", 1

    Thank you

    Wednesday, June 8, 2016 3:31 PM

Answers

All replies

  • You cannot elevate a script.  See the following from the top of this forum: https://social.technet.microsoft.com/Forums/en-US/21afa490-a74e-4052-8c34-e997cdc593b3/you-cannot-bypass-the-uac-prompt?forum=ITCG

    You cannot auto-elevate any script.  It will always be accessible if it is runnable and will always prompt for elevation. 

    You can run scripts elevated under the scheduler and have users run a batch that executes the scheduled task.


    \_(ツ)_/

    • Proposed as answer by Mike Laughlin Wednesday, June 8, 2016 5:44 PM
    Wednesday, June 8, 2016 3:50 PM
  • See the following post from right at the top of this forum:

    You cannot bypass the UAC prompt

    Think about it. If this were possible, it is exactly what malware would do.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, June 8, 2016 3:54 PM
    Moderator
  • Try this:

    Create a launcher script & within that script call the script to run (the launcher script must be in the same folder as the script to run) - e.g. the script to run is list.vbs

    set objShell=createobject("Shell.Application")
    strPath=Mid(wscript.scriptfullname,1,len(wscript.scriptfullname)-len(wscript.scriptname))

    objShell.ShellExecute "wscript.exe", chr(34) & strPath & "\list.vbs" & chr(34) & " dummy argument","","runas",1

    Thursday, June 25, 2020 7:26 AM
  • Try this:

    Create a launcher script & within that script call the script to run (the launcher script must be in the same folder as the script to run) - e.g. the script to run is list.vbs

    set objShell=createobject("Shell.Application")
    strPath=Mid(wscript.scriptfullname,1,len(wscript.scriptfullname)-len(wscript.scriptname))

    objShell.ShellExecute "wscript.exe", chr(34) & strPath & "\list.vbs" & chr(34) & " dummy argument","","runas",1

    Please carefully read any question before answering.  You cannot bypass the prompt.  The user wants to bypass the prompt. That is never possible with disabling a critical security control in Windows.

    Also do not add to questions that are marked as answered and are many years old.  It is not helpful.


    \_(ツ)_/

    Thursday, June 25, 2020 7:45 AM