You can use start /min cscript yourfile.vbs to run it minimized, thought that's not 'silent'. Otherwise, you could setup your batchfile to run it via task scheduler under the system account (if there's no network communication needed). Aside from that, you could create an on-the-fly script to run your other script. Aaron copland the tender land.
'your batch code '. Echo Dim objShell: Set objShell = CreateObject('Wscript.Shel l') c: script.vbs echo objShell.Run 'C: otherscript.vbs', 0 c: script.vbs echo Set objShell = Nothing c: script.vbs cscript c: script.vbs though that's not entirely 'silent' either.it'll probably still produce a pop-up, but only for a second.
So the only other thing I could think is to start with a vbscript, then you can control subsequent scripts or batch files and display them or not as your preference ( details the 'hide' parameter for shell.run method).
I am a beginner in VBScript. I googled it & got to know that we can run VBScript from command line by executing below command: For Example my vbscript name is Converter.vbs & it's present in folder D: VBS. I can run it through following methods: CScript 'D: VBS Converter.vbs' OR WScript 'D: VBS Converter.vbs' Now I would like to execute above VBScript without Cscript or Wscript command by simply typing the name of VBscript name i.e.
I DON'T WANT TO SPECIFY THE FULL PATH OF VBSCRIPT EVERYTIME. Can anyone please guide me on how to do that? Add your script to AppPaths in the registry. You MUST register as if it's an exe file if you don't want to type the.vbs. So Add HKEYLOCALMACHINE SOFTWARE Microsoft Windows CurrentVersion App Paths Converter.exe and set it's default value to cscript //nologo 'C: Users David Candy Documents Assorted Scripts converter.vbs' or use Doskey and autorun it to load your macros. Add an regsz autorun value to HKEYCURRENTUSER Software Microsoft Command Processor of doskey /macrofile=c: mydoskeymacros.txt – Apr 15 '14 at 20:08.
When entering the script's full file spec or its filename on the command line, the shell will use information accessibly by assoc grep -i vbs.vbs=VBSFile ftype grep -i vbs VBSFile=%SystemRoot% System32 CScript.exe '%1'%. to decide which program to run for the script. In my case it's cscript.exe, in yours it will be wscript.exe - that explains why your WScript.Echos result in MsgBoxes. As cscript /? I'll break this down in to several distinct parts, as each part can be done individually. (I see the similar answer, but I'm going to give a more detailed explanation here.) First part, in order to avoid typing 'CScript' (or 'WScript'), you need to tell Windows how to launch a.vbs script file. In My Windows 8 (I cannot be sure all these commands work exactly as shown here in older Windows, but the process is the same, even if you have to change the commands slightly), launch a console window (aka 'command prompt', or aka incorrectly 'dos prompt') and type ' assoc.vbs'.
That should result in a response such as: C: Windows System32assoc.vbs.vbs=VBSFile Using that, you then type ' ftype VBSFile', which should result in a response of: C: Windows System32ftype VBSFile vbsfile='%SystemRoot% System32 WScript.exe' '%1'%.OR- C: Windows System32ftype VBSFile vbsfile='%SystemRoot% System32 CScript.exe' '%1'%. If these two are already defined as above, your Windows' is already set up to know how to launch a.vbs file. (BTW, WScript and CScript are the same program, using different names. WScript launches the script as if it were a GUI program, and CScript launches it as if it were a command line program. Why don't you just stash the vbscript in a batch/vbscript file hybrid. Name the batch hybrid Converter.bat and you can execute it directly as Converter from the cmd line. Sure you can default ALL scripts to run from Cscript or Wscript, but if you want to execute your vbs as a windows script rather than a console script, this could cause some confusion later on.
So just set your code to a batch file and run it directly. Check the answer - And here is an example: Converter.bat::' VBS/Batch Hybrid::' - Batch portion - rem^ &@echo off rem^ &call:'sub rem^ &exit /b:'sub rem^ &echo begin batch rem^ &cscript //nologo //e:vbscript '%f0' rem^ &echo end batch rem^ &exit /b '- VBS portion - Dim tester tester = 'Convert data here' Msgbox tester.
Treadmills manual. 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.
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. 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 the difference 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 that the 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 correct and 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. 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. 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.
How To Run Vbs File From Cmd
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. 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.
Run Vbs File From Command Line
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. 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, objFSO suser = '[email protected]' 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 UNCServerName ShareFolder YourScript.vbs' '- 'This will be the path were the scripted you want called will be. 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, objFSO suser = '[email protected]' 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 UNCServerName ShareFolder YourScript.vbs' '- 'This will be the path were the scripted you want called will be.
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |