This is a VBScript that I would like to improve. I would like four things :
1) Add a line that would rename the extension cleanup.dll to cleanup.exe, so as it can be called by the WshShell.run and executed (hidden).
2) The way it is written just below, the script opens two screens : the screen of the cleanup.exe and a blank screen, which should be hidden for the user and it is not what is happening ! How to hide the second screen ? I want to run it invisibly (the user cannot close or manipulate the second screen. It will be closed via code that is inside the cleanup.exe).**NOTE : The code below works perfectly in Windows XP, but not on Windows 7. How to make it work in all Windows platforms ?
VBSCRIPT "Second.vbs"
Set WshShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile "cleanup.dll" , "cleanup.exe"
WshShell.Run "c:\cleanup.exe", 0, TRUE
Set WshShell = Nothing
BATCH "Master.bat"
#echo off
wscript Second.vbs
exit /b
3) Is there a good and reliable software to convert from VBS to EXE ?
4) The other problem I am having is that the command line below does not yield results.Must I use the second pard of the code below instead ? Why ??
Suppose that my Batch file is in located in drive f:\
If I double click on it, my screen should be then populated with information extracted from the TXT file, which actually resides in drive c:\
#echo off
set DRV=C:\August\MyProgram
cd\
cd %DRV%
type test.txt & pause>nul
#echo off
set DRV=C:\August\MyProgram
cd\
c:
cd %DRV%
type test.txt & pause>nul
Thank you in advance for the explanations and solutions
Why run with batch, vbscript is more powerfull and offers more controll.
about the visible console window
WshShell.Run "c:\cleanup.exe", 0, TRUE should hide the console while running and waits before continuing
Make sure you start your script with wscript.exe, not cscript.exe and don't use any wscript.echo
Renaming a file
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile "cleanup.dll" , "cleanup.exe"
about the batch cd, practice this in a console window
cd never changes to a drive, only to another map, drive: changes the active drive
d: => d:\>
c: => c:\> (so now if you are on c:\)
cd d:\test =>c:\ (changes your active map on d: to d:\test but since your c: drive is still the active drive you see nothing happening)
d: => d:\test (change drive to d:, you do see that the active map on drive d: is d:\test (at least with the default prompt)
Related
Having a Windows program that does wipe files and folders from the context menu too even with no confirmation at all then I created a batch file with the following content
#ECHO OFF
CHOICE /M "Do you want to Wipe Files"
IF ERRORLEVEL 2 GOTO QUIT
IF ERRORLEVEL 1 GOTO RUN
:RUN
START "" "C:\Program Files\MyProgram\myexec.exe" /wipe "%~1"
EXIT
:QUIT
EXIT
and a registry key with the following entry
[HKEY_CLASSES_ROOT\*\shell\wipefiles\command]
#="\"C:\\Program Files\\MyProgram\\myexec-start.cmd\" \"%1\""
just to get a safety chance before to wipe the file or the folder and it does work.
However if multiple files are selected then it prompts you to answer Y or N for the times as far as the number of files is and furthermore the cmd window remains open until you hit Y or N the times as far as the number of selected files is.
Is there a way in order to answer a single time Y or N (closing the cmd screen) regardless of the number of selected files?
There seems to be no simple way to do what you request from the context menu, since a separate process is opened for each selected file.
But it can be done easily from the send to menu:
Create a shortcut in the SendTo folder for your script, and now you can send as many files or folders as you want.
The script reads as follows:
#ECHO OFF
CHOICE / M "Do you want to Wipe Files"
IF ERRORLEVEL 2 GOTO QUIT
:: If your software enables file processing in a chain, such as myexec.exe /wipe filename1 filename2 ..., use this syntax:
START "" "C:\Program Files\MyProgram\myexec.exe" /wipe %*
:: If not, use the for loop:
for %%f in (%*) do START "" "C:\Program Files\MyProgram\myexec.exe" /wipe %%f
: QUIT
Maybe it's a bit of a deviation from the theme, but you can do it in VBScript like this:
Set Shell = CreateObject("WScript.Shell")
if MsgBox("Do you want to Wipe Files?", vbQuestion + vbYesNo, "wipefiles") = vbYes then
for each Arg in WScript.Arguments
Shell.Run """C:\Program Files\MyProgram\myexec.exe"" /wipe " & """" & Arg & """",0,True
Next
end if
It will display a graphical message box asking the user to confirm the deletion, without any terminal window.
I would like to detect whether or not a folder is "in use" (I am defining that as if it or any sub folder is opened in Windows File Explorer). Is there a way to get the paths of all folders File Explorers opened? I did some reading and some people say that explorer.exe is the process as the task bar/start menu and you have to change an option to separate it? I am fine with doing this as this program is only going to be on one PC.
I know batch isn't the best way to go about doing this, but is this possible?
I don't think you can do that. Even if you enable Launch folder windows in a separate process then the new processes aren't called with the folder path in the command line
It may be possible if you attach a debugger to explorer.exe and read the path somewhere inside the process, but it's not a good way either, and will be very slow
Set objShell = CreateObject("Shell.Application")
Set AllWindows = objShell.Windows
For Each win in AllWindows
WScript.Echo win.LocationUrl
Next
To use in batch
For /f "delims=" %A in ('cscript //nologo "C:\Users\User\Desktop\Bat+Vbs\ListOpenShellWindows.vbs"') Do #Echo %A
I am having issues getting a simple batch file (opening command prompt) to run from a vbs macro, I know this question gets asked a lot and I have tried many different suggested solutions for this without success. I am using notepad ++ to run the scripts/VB code for testing.
I have verified that the .bat file will execute correctly by itself, any suggestion on how to get this to work correctly would be greatly appreciated.
Here is my code for each instance.
VB CODE:
Sub CallBATCH()
Dim argh As Double
argh = Shell.Run "C:\Temp\cmdPrompt.bat"
End Sub
BATCH FILE:
start cmd.exe /k
EDIT: The following is the .bat file that I actually intend on calling up:
#echo OFF
title AutoCAD DWG Duplicator
color 0a
:start
set /P TemplateName=Please enter the template name you wish to copy:
set /P NumberOfCopies=Please enter how many copies you wish to make:
set Pathname="<filepath>"
cd /d %Pathname%
:init
for /L %%f in (1,1,%NumberOfCopies%) do copy %TemplateName%.dwg C:\Temp\%%f%TemplateName%.dwg
You seem to be calling a .BAT file that in turn opens a command prompt with START. I'm unclear on why you need the .BAT at all.
Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "cmd.exe /K"
Set oShell = Nothing
The /K parameter will open the command prompt window and keep it open. You've supplied no parameters for START and no commands to execute when the command prompt opens so this should do what you are looking for. More at: Run Method (Windows Script Host)
#echo off
start /wait notepad.exe somefile.txt
if exist somefile.txt echo it exists.
this will display the normal console screen as well as notepad until notepad is closed. i don't want the console screen to appear; notepad must have focus; the 'if exist' line must not run until notepad is closed. the script is run from 'total commander' but running it from 'start/run' returns same results. the second line of code is irrelevant for this example.
cmd.exe /k does same thing.
internal batch commands only.
thanks!
win 7 64 bit
You can use Windows Script Host to run your batch file. For example, create the file "startmybatch.vbs" with the following content:
Set ws = WScript.CreateObject("WScript.Shell")
cmd = "c:\mypath\mybatch.bat"
ret = ws.Run(cmd, 0, True)
Set ws = Nothing
then run "startmybatch.vbs" directly, or using "wscript startmybatch.vbs". At least on XP this works (console window is not visible). I think this will work on all Windows versions >= Win98.
How Can I hide the console of a running batch file
the batch is running from a cmd or start>run
You can try a couple of things:
Schedule it with a user other than you.
or
CMD /C START /MIN your.CMD
or
This WSH/VBScript will run your batch file in a hidden window:
'MyCmd.vbs
Set WshShell = WScript.CreateObject("WScript.Shell")
cmd = "C:\bin\scripts\MyCmd.cmd"
Return = WshShell.Run(cmd, 0, True)
set WshShell = Nothing
At the start of your batch file add these lines.
#echo off
if not defined PIL (
set PIL=1
start /min "" %~0
exit /b
)
Replace the rest of your batch here
If PIL is not defined in your batch file then the batch file will restart itself minimized. If PIL is defined in your environment then change it to something else. This will restart the batch file with PIL defined as 1 and since PIL is defined it will skip the restarting section after the file has been restarted.
make a shortcut to the batch then right click and select properties
now under the general tab there will be a run option click the arrow beside it and select minimized now click apply and ok now start the program and it will run in the background.
hope i helped you this is pretty much guaranteed to work on any bat file.
I use this software to code .exe apps and it has a command that can do this. The name of the software is Advanced Bat to Exe Converter but it doesn't only convert, you can code and compile them too. Try this coding once you download the program from here, this should also work with other exe compilers, but I am not sure.
#echo off
:menu
cls
color 9e
rem ChangeColor 14 0
rem ChangeColor 14 9
rem PrintBoxAt 6 11 15 60 1
rem PrintBoxAt 11 21 5 40 1
rem printcenter Enter window title: 13 14 9
rem getinput
set w=%result%
rem hidewindow "%w%"
goto menu