Unable to remove folder with GIT repo via command in VBScript - windows

I am using Quality Center to execute tests in Windows 8.
The VBScript file creates a temporary (timestamped) workspace/folder to clone the git repository and execute the test.
When I try to remove the folder in the end of the test, it doesn't work and gives an error: Invalid field type definition.
This code works fine if I work with a non git repository and a static project. If I delete manually the .git folder, the script is able to remove the remaining of the folders/files.
'''workspace = "C:\tests\20170613224942"
Dim objFSO, objFolder
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CreateFolder(workspace)
'git clone
'Test Execution
Dim objFSO, objFolder
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFolder(workspace)
I already tried (unsuccessfully) something like that:
objShell.Run "rmdir /S /Q " & workspace
I don't know if its problem with hidden folder so I tried this:
del /s /a *.git
But this only works for files and in this case only the folder is hidden. Not the sub-folders/sub-files.
Can someone help me to resolve this problem? How can I force the folder removal automatically via script?
Thank you.

Can you try :
git rm -r gitDirectoryToRemove
and then your code to remove the parent if required

Found a temporary solution. Maybe not an elegant one, but solves the problem.
I created a .bat file only for removing the folder passed by argument and I call it in VBS.
Bat File:
#echo off
#echo Try to removing %1
rmdir "%1" /s/q
VBS Call:
Set objShell = CreateObject("Wscript.Shell")
objShell.Run "C:\tests\rm_workspace.bat " & workspace
Removing indirectly, it works like a charm.
The reason: still don't know why.

Related

Cmd file to run executable in a folder of an archived zip file

I have two files which I want to archive. I.e a zip file. Files contained in the archive would be a cmd file and a folder containing the file to run.
I want a cmd script to use to run the file in the folder when the archive file is opened and the cmd file is runned. Would prefer cmd to run silently with no pop up screen.
Can anyone help with the cmd script here?
Assuming that two (2) files are extracted into a directory.
RUNME.CMD
DOIT.EXE
The RUNME.CMD, if it is run, can refer to the directory where it is located.
#ECHO OFF
ECHO My directory is "%~dp0"
IF EXIST "%~dp0DOIT.EXE" ("%~dp0DOIT.EXE")
EXIT /B
Assuming that two (2) files are extracted into a directory.
RUNME.CMD
FOLDER with DOIT.EXE
The RUNME.CMD, if it is run, can refer to the directory where it is located.
#ECHO OFF
ECHO My directory is "%~dp0FOLDER"
IF EXIST "%~dp0FOLDER\DOIT.EXE" ("%~dp0FOLDER\DOIT.EXE")
EXIT /B
This is the Vbs script to use in running this file.
Run.vbs
file.exe
Run.vbs script should be like this.
dim shell
set shell=createobject("wscript.shell")
shell.run "file.exe"
set wshNetwork = CreateObject( "WScript.Network" )`enter code here`
strUserName = wshNetwork.UserName
WScript.Sleep (10000)
X=MSGBOX("File runs successfully" ,0, "Alert For: " & strUserName)
WScript.Interactive = true
Line 4 - 7 ain't compulsory for this task. Its just to locate the Computer Username and display on screen.

.BAT file help (uninstall 2 paths silently)

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.

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.

Deleting Winzip Command Line Add On 2.2 vbs

I'm trying to delete a file like winzip command line using this code
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile("C:\Program Files\WinZip\wzuninst.exe wzcline C:\Program Files\WinZip\wzclun.dll")
When I run it on cmd it says Bad name or number. Can someone clarify it for me?
That's not a valid command line.
If you want to run a program you use wshshell.run.
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd /k dir c:\windows\*.*"

How to Create Folders and Subfolders in %AppData%

First of all thank you very much for all the help I’ve found over 3 Vbscript that has save my life during this last six months.
I’m new to Vbscripting and I’m currently working on getting a Vbscript that create folders and copy a file at the same time overwrite that folder and file if they already exist
Folder and subfolders to be created (Avaya) C:\Users\My Username\AppData\Roaming\Avaya\ Avaya\one-X Agent\2.5\
File from (Myfile.txt) C:\Myfile.txt to C:\Users\My Username\AppData\Roaming\Avaya\one-X Agent\2.5\
I get “Path not found” error, but If I leave the path till (Avaya) it creates Avaya Folder but not it’s subfolders C:\Users\My Username\AppData\Roaming\Avaya\
Here’s what I have and thank you in advance
Dim fso, vFolder
Set objFso = WScript.CreateObject("Scripting.FileSystemObject")
set objWShell = wScript.createObject("WScript.Shell")
usrName = objWShell.expandEnvironmentStrings("%USERNAME%")
Set fso = CreateObject("Scripting.FileSystemObject")
Set vFolder = fso.CreateFolder("C:\Users\" & usrName & "\AppData\Roaming\Avaya\one-X Agent\2.5\")
CreateFolderDemo = vFolder.Path
The problem is that CreateFolder does not create intermediate folders. The FSO doesn't have a method that does that. It might be easier to use mkdir like this:
Option Explicit
Dim shl
Set shl = CreateObject("WScript.Shell")
Call shl.Run("%COMSPEC% /c mkdir ""%APPDATA%\Avaya\one-X Agent\2.5""",0,true)
Some errors:
You declare fso, but you use objFso
You use %USERNAME% but you should consider %APPDATA% instead
You should use OPTION EXPLICIT to detect typos and undefined variables
You should make your code easier to read by dimming one variable at a time
CreateFolder doesn't create the entire tree, so you need to use FolderExists
For example:
Option Explicit
Dim objWShell
Set objWShell = WScript.CreateObject("WScript.Shell")
Dim appData
appData = objWShell.expandEnvironmentStrings("%APPDATA%")
Dim objFso
Set objFso = WScript.CreateObject("Scripting.FileSystemObject")
If Not objFso.FolderExists(appData + "\Avaya") Then
objFso.CreateFolder appData + "\Avaya"
End If
If Not objFso.FolderExists(appData + "\Avaya\one-X Agent") Then
objFso.CreateFolder appData + "\Avaya\one-X Agent"
End If
If Not objFso.FolderExists(appData + "\Avaya\one-X Agent\2.5") Then
objFso.CreateFolder appData + "\Avaya\one-X Agent\2.5"
End If
Lastly, it's not clear why your solution needs to be in VBScript. It appears that your requirements are creating folders and copying files, which means, batch files would probably be a far more simpler.

Resources