Run Vbs File From Cmd Prompt
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 script needs 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 files Program data and Registry edits, it fails. Is there any way to script so I can elevate the batch file to the same level as selecting 'Run as Administrator?
Set objShell = WScript.CreateObject('WScript.Shell') objShell.Run('runas /user:domain user unc location Install.bat'), 1, True WScript.Sleep 100 oShell.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 scripts is not an option either, as we don't want the program install on every PC. 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 files Creating keys outsode HKCU Piping commands past windows password boxes This 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.
How to Run a Program on Command Prompt. This wikiHow teaches you how to start a program on your Windows computer from. Use Windows Command Prompt to Run a Python File.
There is loads of help for software distrubtion. 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 this subject: 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 hope of 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:domain user unc location Install.bat', 1, False Do Until.AppActivate('runas.exe'): WSH.Sleep 100: Loop.Sendkeys sPassword& '~' end with I added the InputBox because it's a security hole to hard code a password into a script that anyone can read.
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. Gas compressor performance curves.