.BAT file help (uninstall 2 paths silently) - vbscript

I have looked around and can't seem to make it work with the research I've done.
I'm going to create a GPO to apply to workstations that will uninstall Malwarebytes 2.0 and 3.0 from a given system. This will allow us to roll out the enterprise version.
What I have in my .bat file is this:
#echo off
cd "C:\Program Files (x86)\Malwarebytes Anti-malware\"
unins000.exe /verysilent /suppressmsgboxes /norestart
cd "C:\Program Files\Malwarebytes\Anti-Malware\"
unins000.exe /verysilent /suppressmsgboxes /norestart
However, I noticed that if one of the paths above doesn't exits (1 will always not exist) than it will pop up a command prompt with an error. I'd like no boxes to pop up at all if possible. I then tried to accomplish this with vbs with the error:
compilation error: Invalid character
This is that script:
Dim objShell
Set objShell = WScript.CreateObject( WScript.Shell )
Sub MalwareBytes()
On Error Resume Next
objShell.Run(%ProgramFiles%Malwarebytes Anti-malwareunins000.exe verysilent
suppressmsgboxes norestart)
objShell.Run(%ProgramFiles(x86)%MalwarebytesAnti-Malwareunins000.exe
verysilent suppressmsgboxes norestart)
End Sub
Set objShell = Nothing

How about, y'know, checking if a path actually exists before trying to go there?
if exist "C:\Program Files (x86)\Malwarebytes Anti-malware" (
cd "C:\Program Files (x86)\Malwarebytes Anti-malware"
unins000.exe /verysilent /suppressmsgboxes /norestart
)
The reason why your VBScript doesn't work is because your syntax is invalid. You need double quotes around the argument to CreateObject() as well as the command strings. With nested double quotes in case of the latter, because you have paths with spaces in them. Not to mention that it would be cleaner to check if a path actually exists in VBScript too.

Related

Move command in VBScript with a space in destination directory [duplicate]

This question already has an answer here:
VBScript pass commandline argument in paths with spaces
(1 answer)
Closed 5 years ago.
Set oShell = WScript.CreateObject("WSCript.shell")
oShell.run "cmd /K cd \ & cd C:\Users\me & cscript /nologo Setup.vbs > newfile & del example.ini & ren newfile example.ini & move example.ini C:\Program Files (x86)\Setup Folder"
Above is my code in which I'm trying to run a script and replace a file in the destination directory. My other script works fine and isn't causing any issues, but in this script I cannot seem to move the file to the destination (C:\Program Files (x86)\Setup Folder) because of the spaces in the directories.
I have tried using /, "'s (this one will not work I realize as it will read the script and believe it to be the end of it), and single quotes ('), before each space of the directory but none of them work.
How would one be able to move a file from one place to the other while still in the script if the directories have spaces in them?
I found the answer to my own question through a bit more research.
The reason it was not working is because I didn't add a set of double quotes before my destination directory. By doing
""C:\Program Files (x86)\Setup Folder"
It worked. I'll leave this here for anybody who encounters this issue in the future.

the installation package could not be open batch file

I've been working on a batch file all day, that I can't get to work open through GPO (another day, another question). So I decided to do it manually with every computer. I have two exe's and one MSI. The exe's work perfectly fine. They get installed, and it all works out. The MSI, however, doesn't. It gives me the error: the installation package could not be opened. Verify that the package exists and that you can access it, or contact the application vendor to verify that this is a valid Windows Installer package.
Now when I go to the network share and use it from there, it works perfectly fine. So there must be an issue with my code.
Here's the code:
#echo off
IF NOT EXIST "C:\Program Files (x86)\Citrix\ICA Client\" (
pushd "\\KOPI-DC01\ACCURO Cloudwerx\ACCURO\1\"
.\CitrixReceiver-4.4.1000.exe /silent
)
IF NOT EXIST "C:\Program Files (x86)\triCerat\Simplify Printing\ScrewDrivers Client v4\" (
pushd "\\KOPI-DC01\ACCURO Cloudwerx\ACCURO\2\"
msiexec.exe /i ".\Screwdriver.msi"
)
IF NOT EXIST "C:\Program Files\Cloudwerx\CloudwerxPlugin\" (
pushd "\\KOPI-DC01\ACCURO Cloudwerx\ACCURO\3\"
.\cloudwerx-setup.exe /silent
)
pause
Any help would be greatly appreciated, thanks.
I am guessing that your problem is the distinction in powershell between the current location (set by the pushd command) and the working directory (unaffected by the pushd command). You can see the working directory of the powershell process using the [Environment]::CurrentDirectory property:
# C:\> [Environment]::CurrentDirectory = "c:\"
# C:\> [Environment]::CurrentDirectory
c:\
# C:\> pushd C:\Temp
# C:\Temp> [Environment]::CurrentDirectory
c:\
# C:\Temp> Get-Location
Path
----
C:\Temp
WHat is probably happening is that msiexec.exe is using the working directory (i.e. [Environment]::CurrentDirectory) and not the current powershell location at invocation. I would just specify the full path to msiexec:
msiexec.exe /i "\\KOPI-DC01\ACCURO Cloudwerx\ACCURO\2\\Screwdriver.msi"
MSI installation packages build with an older WIX utility would throw the error whenever installation was attempted from a batch script that was accessed on a shared drive using UNC path instead of a mapped drive letter. On the other hand whenever the batch file was executed with a mapped drive letter the installation would work normally.
I'm not blaming WIX here because I'm not certain whether they are responsible. I'm just describing symptoms here. It might just be the result of invoking plain vanilla Windows batch script that in turn executes msiexec with a bunch of command line parameters.

Cannot run vb6/make command in vbscript

My script contains the following code.
Set objShell=CreateObject("WScript.Shell")
ObjShell.Run "vb6/make Project1.vbp Project1.exe"
But my script doesn't make my project compile into exe.
I have the visual basic project Project1.vbp in the same folder which contains the script and the path for vb6 is also set in the Environment variable.
However when I tried to compile the project manually into exe it worked fine, by the command given below
vb6/make Project1.vbp Project1.exe
Kindly suggest some way to resolve my script's problem.
Always use full paths in sutch cases, I presume the error is there.
You can catch the error produced in the following way.
Here with a Ruby script I want to run but deliberatly made a mistake in the path.
Set objShell = CreateObject("WScript.Shell")
command = "cmd.exe /S /C ruby ""C:\Users\Gebruiker\ruby\excel\ru.rb"""
Set objWshScriptExec = objShell.Exec(command)
Set objStdOut = objWshScriptExec.StdOut
Set objStdErr = objWshScriptExec.StdErr
While Not objStdOut.AtEndOfStream
WScript.echo objStdOut.ReadLine
Wend
While Not objStdErr.AtEndOfStream
WScript.echo objStdErr.ReadLine
Wend
' ruby: No such file or directory -- C:/Users/Gebruiker/ruby/excel/ru.rb (LoadError)
I made the following changes
Set objWshScriptExec=objShell.Exec("cmd.exe /S /C vb6/make ""Project1.vbp""")
And it worked.
Since I am a beginner in vbscript, I don't know the function of
/S /C
so please let me know.

How to use the start command in a batch file?

I have a batch file that starts an app with a lot of command-line parameters:
"C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\11.0\WebDev.WebServer40.exe" /port:1672 /path:"C:\Code.Net\My App\Iteration 6\REL_6.8.806_PerfEnhanceV\Fusion\Code\CC.Fusion\CC.Fusion.Services" /vpath:"/FusionServices"
The problem is that when I run the batch file, the DOS window stays up until the command completes and I would like it to go away. So I tried using the start command, but placing it in front, like this:
start "C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\11.0\WebDev.WebServer40.exe" /port:1672 /path:"C:\Code.Net\My App\Iteration 6\REL_6.8.806_PerfEnhanceV\Fusion\Code\CC.Fusion\CC.Fusion.Services" /vpath:"/FusionServices"
But I get an error stating that Invalid switch - "/port:1672"
I have also tried escaping the double quotes, but I was not successful.
How do I fix that?
An extra pair of rabbits' ears should do the trick.
start "" "C:\Program...
START regards the first quoted parameter as the window-title, unless it's the only parameter - and any switches up until the executable name are regarded as START switches.
I think this other Stack Overflow answer would solve your problem: How do I run a bat file in the background from another bat file?
Basically, you use the /B and /C options:
START /B CMD /C CALL "foo.bat" [args [...]] >NUL 2>&1

Copy a .bat off a USB and copy it to the Startup folder script - WinXP

I'm a Mac/iPhone dev so I don't know very much about Windows scripting...
The point is I have to install a startup app on many computers, so I'd like to have a USB stick with two .bat files:
would be the actual "app"
would be the script that would copy the 1st.bat off my USB to the Windows startup folder...
How can I do that?
the name of my usb is "USB" and the name of my startup app is "startup.bat".
How I already said, I'm extremely lame in Windows programing, and I need it acutely ;)
Thanks A LOT!
Try the following script. This will cause the application to run whenever the current user logs in. Without administrative privilages, you won't be able to do it for all users in one go.
#Echo Off
CD /D %~dp0
Set StartupFolder=%AppData%\Microsoft\Windows\Start Menu\Programs\Startup
If Exist "%StartupFolder%" Goto :FoundStartup
Set StartupFolder=%UserProfile%\Start Menu\Programs\Startup
If Exist "%StartupFolder%" Goto :FoundStartup
Echo Cannot find Startup folder.
Exit /B
:FoundStartup
Copy "MyApp" "%StartupFolder%"
Each line does the following:
Turn off command echoing, making the script look cleaner to the end user.
Set the current directory to wherever this script is located.
Set the Startup folder's path as expected in Windows Vista or later.
If this folder exists, jump to the copying stage.
Set the Startup folder's path as expected in Windows 2000 or later.
If this folder exists, jump to the copying stage.
Report that the Startup folder can't be found.
Exit the batch script.
A label that can be jumped to.
Copy "MyApp" from the current folder (USB) to the Startup folder.
I don't want to take credit for Hand-E-Food's answer, but I figured out why his code didn't work and I can't reply to his answer, so here it is. Instead of using quotes around the %StartupFolder% variable in the Copy line, use them around the path for Set StartupFolder. Therefore, the code would be as follows.
#Echo Off
CD /D %~dp0
Set StartupFolder="%AppData%\Microsoft\Windows\Start Menu\Programs\Startup"
If Exist %StartupFolder% Goto :FoundStartup
Set StartupFolder="%UserProfile%\Start Menu\Programs\Startup"
If Exist %StartupFolder% Goto :FoundStartup
Echo Cannot find Startup folder.
Exit /B
:FoundStartup
Copy "MyApp" %StartupFolder%
The only reason I figured this out is because it wasn't doing anything for me either, so I tried removing the quotes around %StartupFolder% and that resulted in an error message that it couldn't find the folder, but at least I knew it was doing something at the end. Once I figured out that it was looking for the wrong folder because it thought the folder name stopped at the first space in its name, I simply added in the quotes and voila!
Try this (replace app.bat with whatever your actual app is called). This should work on Windows 2000 and up.
IF EXIST "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\*.*" COPY APP.BAT "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\"
IF EXIST "C:\Documents and Settings\All Users\Start Menu\Programs\Startup\*.*" COPY APP.BAT "C:\Documents and Settings\All Users\Start Menu\Programs\Startup\"

Resources