Run Vbs File From Cmd En

Posted on by  admin

I have batch script the I need to run as an administrator, I created a VBscript wrapper that calls a runas and runs my batch file, however the batch file is not being elevated high enough on Windows 7 and Vista, it works fine on XP. The batch scriptneeds to create a folder in Program files, and copy the necessary files, install several programs, as well as make several registry key changes.

If I am logged in as a user with admin rights, right click on the batch file and select 'Run as Administrator'the batch works fine. Using the VBscript to elevate the rights, it installs the programs, but when it comes to creating the folder in Program filesProgram data and Registry edits, it fails. Is there any way to script so I can elevate the batchfile to the same level as selecting 'Run as Administrator?Set objShell = WScript.CreateObject('WScript.Shell')objShell.Run('runas /user:domainuser unclocationInstall.bat'), 1, TrueWScript.Sleep 100oShell.Sendkeys 'password'Another issue, I am having with the script is that it will not send the password, I have to type it manually to test.The idea is to have the end user be able to click on a link from a webpage and install the program itself, as opposed for our Helpdesk be required to install the program. So psexec is no doable as it is not on any of the PCs and user login scriptsis not an option either, as we don't want the program install on every PC.

How to run vbs file

We're fine with UAC prompting, the end user for permission. The main thing is that despite selecting yes on the prompt when the script tries to merge several registry keys, and create a folder and copy files in C:Program Files and C:Program data.My batch file still reports that access is denied. When I run the script manually, as an administrator user UAC still prompts, but the script runs fine.I also tried manually creating a schedule task to test the batch file, running with an domain account running with Admin rights, selecting Run regardless of end user being logged in, the batch file does not run.Also for some reason, it does not like when I try to select run with Highest Privileges.Here is a script that forces UAC elevation:'-'Elevate this script before invoking it.'

Hi Mark,Remember to use the right tools for the right job.Windows 7 is designed to prevent you from doing the exact things you are trying to do.Creating folders uner program filesCreating keys outsode HKCUPiping commands past windows password boxesThis is called privilage isolation. It is to prevent malicious code from penetrating your systems. It we were able to get your script working, it would be flagged to microsoft as a security vulnerability.As you are trying to distribute software, I suggest you forget about scripting it but create a software distrubtion package.You can create an msi package very easy to distribute your soffware. Try here:Or you could use AutoIT as it has it's own scripting language similar to VB. It can be compiled into an exe.There is loads of help for software distrubtion at.Good luck. Hi,In Windows Vista and later with UAC enabled, running programs that require elevation is what is supposed to happen, and it it supposed to be hard to bypass this: The system is designed that way.

Questions like this one (I want to bypass administrator rights,I want to bypass elevation prompts) need to be thought of in terms of malware: If this was easy to do, wouldn't malware do it? Why have administrator permissions and UAC prompts if you can just bypass them?

Aaron Margosis wrote a good blog entry about thissubject:HTH,Bill. I can't really answer your first question, other than in the way you have attempted to do it - with RunAs.The problem with your attempt is that the value of TRUE for the third argument in the Run statement is halting script execution until the RunAs part finishes - which is obviously useless. Change that argument to FALSE. Then to have any real hopeof directing the keystrokes to the right window and at the right time use an AppActivate statement to control the flow of the script, something like this.sPassword = InputBox('Password')with CreateObject('WScript.Shell').Run 'runas /user:domainuser unclocationInstall.bat', 1, FalseDo Until.AppActivate('runas.exe'): WSH.Sleep 100: Loop.Sendkeys sPassword& 'end withI added the InputBox because it's a security hole to hard code a password into a script that anyone can read.Tom Lavedas. I think you need to be aware of a couple of things:.

Runas.exe is designed not to accept a password that you might pipe into it or supply as a switch. Wrapping it into a VB Script file will not change this behaviour. You would need to use some third-party tool to get around this restriction. Attempting to create a subfolder in a System Folder under Windows 7 will almost always get you a UAC challenge, which prevents you from fully automating your installation process.I said 'almost' because there is a method to avoid it.

Since it is complex, it is not really suitable for software distribution. It relies on you creating a scheduled task under an admin account on the target machine. When you launch this task with schtasks.exe,again under an admin account, then no UAC challenge will result.I suggest you review your approach to your installation process with the above restrictions in mind. Only after you have mapped out a workable approach should you start your coding effort. OK, I tested with XP (which does not have the same permissions requirements) and you are working in Win 7.

As Pegasus has said, RunAs is designed to frustrate automation - which only makes sense. However, I am wondering if it is really thedifference between XP and Win7 or if there is something else in the way. On my XP machine, the routine I posted worked as advertised - at least it issued the password into the RunAs password request. One other thing that could be a problem is thatthe AppActivate must find the command window title it expected to find or it will hang.

Does the window that opens end in 'runas.exe' if not, that could be the problem with what I posted. If it does match, then Pegasus is absolutely correctand this approach cannot be made to work. In any case, his advice is clearly good and some other approach to installing necessary registry setting, etc. Should be found.Tom Lavedas.

Hi,In Windows Vista and later with UAC enabled, running programs that require elevation is what is supposed to happen, and it it supposed to be hard to bypass this: The system is designed that way. Questions like this one (I want to bypass administrator rights,I want to bypass elevation prompts) need to be thought of in terms of malware: If this was easy to do, wouldn't malware do it? Why have administrator permissions and UAC prompts if you can just bypass them? Aaron Margosis wrote a good blog entry about thissubject:HTH,Bill. We're fine with UAC prompting, the end user for permission. The main thing is that despite selecting yes on the prompt when the script tries to merge several registry keys, and create a folder and copy files in C:Program Files and C:Program data.My batch file still reports that access is denied.

When I run the script manually, as an administrator user UAC still prompts, but the script runs fine.I also tried manually creating a schedule task to test the batch file, running with an domain account running with Admin rights, selecting Run regardless of end user being logged in, the batch file does not run.Also for some reason, it does not like when I try to select run with Highest Privileges. We're fine with UAC prompting, the end user for permission.

File

The main thing is that despite selecting yes on the prompt when the script tries to merge several registry keys, and create a folder and copy files in C:Program Files and C:Program data.My batch file still reports that access is denied. When I run the script manually, as an administrator user UAC still prompts, but the script runs fine.I also tried manually creating a schedule task to test the batch file, running with an domain account running with Admin rights, selecting Run regardless of end user being logged in, the batch file does not run.Also for some reason, it does not like when I try to select run with Highest Privileges.Here is a script that forces UAC elevation:'-'Elevate this script before invoking it.' Hi Mark,Remember to use the right tools for the right job.Windows 7 is designed to prevent you from doing the exact things you are trying to do.Creating folders uner program filesCreating keys outsode HKCUPiping commands past windows password boxesThis is called privilage isolation. It is to prevent malicious code from penetrating your systems.

Call

It we were able to get your script working, it would be flagged to microsoft as a security vulnerability.As you are trying to distribute software, I suggest you forget about scripting it but create a software distrubtion package.You can create an msi package very easy to distribute your soffware. Try here:Or you could use AutoIT as it has it's own scripting language similar to VB.

How To Run Vbscript In Windows 10

It can be compiled into an exe.There is loads of help for software distrubtion at.Good luck. EversMark,Here is a VB Script Vall Script that will get around the Password Prompt when 'RunAs' is called.' Start'-' To Run other VB Scripts or even Batch Files with Admin Priviliges'-Dim WshShell, objFSOsuser = 'YourAdminAccount@YourDomain.com'sPass = 'YourPassWord'-'Put your Domain Account and Password in between the qoutes, REMEMBER!

The Password will be clear text. If this is a standalone just take off the @YourDomain.com'-sCommand = 'wscript UNCServerNameShareFolderYourScript.vbs'-'This will be the path were the scripted you want called will be at. EversMark,Here is a VB Script Vall Script that will get around the Password Prompt when 'RunAs' is called.' Start'-' To Run other VB Scripts or even Batch Files with Admin Priviliges'-Dim WshShell, objFSOsuser = 'YourAdminAccount@YourDomain.com'sPass = 'YourPassWord'-'Put your Domain Account and Password in between the qoutes, REMEMBER!

Run Vbs File From Command Line

The Password will be clear text. If this is a standalone just take off the @YourDomain.com'-sCommand = 'wscript UNCServerNameShareFolderYourScript.vbs'-'This will be the path were the scripted you want called will be at.

Comments are closed.