Extract archive with password that contain double quote - windows

i want to extract an archive called test.rar with 7zip but nothing worked for me
Archive: test.rar
Password(with quote):"."
I tried
& "C:\Program Files (x86)\7-Zip\7z.exe" t -p'"".""' test.rar
& "C:\Program Files (x86)\7-Zip\7z.exe" t -p""."" test.rar
& "C:\Program Files (x86)\7-Zip\7z.exe" t "-p"."" test.rar
& "C:\Program Files (x86)\7-Zip\7z.exe" t -p'"."' test.rar
& "C:\Program Files (x86)\7-Zip\7z.exe" t -'p"."' test.rar
& "C:\Program Files (x86)\7-Zip\7z.exe" t -p'"".""' test.rar

Up to at least PowerShell 7.1, passing arguments with embedded " characters to external programs such as 7z.exe is fundamentally broken, unfortunately.
While there are workarounds, the simpler solution is to provide the password via stdin.
The post that Mark Tolonen links to shows this technique for cmd.exe, via <, its input-redirection operator, which PowerShell does not support, however.
Instead, use PowerShell's pipeline to supply data that an external program receives via stdin.
Assuming that the verbatim password is ".":
'"."' | & "C:\Program Files (x86)\7-Zip\7z.exe" t test.rar

Related

how to change directory before running command in windows command prompt

# run.bat
cmd /k python.exe "C:\Program Files (x86)\XXX\test.py"
cmd /k cd "C:\Program Files (x86)\XXX\" & python.exe "C:\Program Files (x86)\XXX\test.py"
cmd /k "cd "C:\Program Files (x86)\XXX\" & python.exe "C:\Program Files (x86)\XXX\test.py""
Question> I need to change the working directory to C:\Program Files (x86)\XXX\ then run the command python.exe "C:\Program Files (x86)\XXX\test.py". Several methods have been tested and none of them give me the desired result. They all end up run the command without changing the working directory.
For example,
If I run c:\temp\run.bat, I expect the script first to change to directory of C:\Program Files (x86)\XXX\ then run the python script.
Step 1: Find the short names for the directory with space
dir /X
PROGRA~2 Program Files (x86)
Step 2: Quote all commands
cmd /k "cd C:\PROGRA~2\XXX\ & python.exe C:\PROGRA~2\XXX\test.py"

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.

How to execute commands with variables as path in vbscript

I can compile my visual basic project Project1.vbp into exe through this command
Set objWshScriptExec=objShell.Exec("cmd.exe /S /C cd ""C:\Program Files (x86)\Microsoft Visual Studio\VB98"" & vb6/make ""C:\Users\Ankit\Desktop\New folder (5)\Project1.vbp"" ""C:\Users\Ankit\Desktop\New folder (5)\Project1.exe""")
But when I take
p="C:\Program Files (x86)\Microsoft Visual Studio\VB98"
m="C:\Users\Ankit\Desktop\New folder (5)\"
And try to execute this command
Set objWshScriptExec=objShell.Exec("cmd.exe /S /C cd "p" & vb6/make "m"Project1.vbp"" "m"Project1.exe""")
It results in error.
kindly provide me some solution to correct this command to compile the project to exe.
You have to concatenate strings using & and also enclose your paths in " quotes. (Inside a string, quotes are escaped as "".)
Set d = objShell.Exec("cmd.exe /S /C cd """ & p & """ & vb6/make """ _
& m & "Project1.vbp"" """ & m & "Project1.exe""")

How to run multiple commands in cmd

I am trying to write a batch file to run several WORD and POWERPOINT file as below:
"C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" "D:\Files\Literature\Literature Review\Literature-Review.docx" & "C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" "D:\Files\Literature\Literature Review\outline.docx" & "C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" "D:\Files\Literature\Questions to be asked\Questions to be asked.docx" & "C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" "D:\Files\Presaentationen\1. Gruppemeeting\ToDo.docx" & "C:\Program Files (x86)\Microsoft Office\Office14\POWERPNT.exe" "D:\Files\Presaentationen\1. Gruppemeeting\Presentation_Englisch.pptx"
The problem is that only the first file opens. If I close it the next one opens and so on. But I want to open them all at the same time. What should I do? (OS is Windows 7)
Thank you very much.
"C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" "filename1" "filename2" ...
should open each file in winword.
If you wish to open powerpoint as well, you'd need to start each executable
start "windowtitle" "C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" "filename1" "filename2" ...
start "windowtitle" "C:\Program Files (x86)\Microsoft Office\Office14\POWERPNT.exe "filename3"
but you would need to add the /w switch to the last executable you start this way, otherwise the commands following will be excuted (which you may not want)
Furthermore, the batch would then proceed when the waited application terminates, so
start "windowtitle" "C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE" "filename1" "filename2" ...
start /w "windowtitle" "C:\Program Files (x86)\Microsoft Office\Office14\POWERPNT.exe "filename3"
would wait until powerpoint exits and then proceed, regardless of whether winword is still open.
windowtitle may be empty, but should not be omitted (ie. use "" if you want, but don't leave out this element)
When cmd runs a GUI application it does not wait for it to complete. (Whether an application is windowed (GUI) or console is determined by a flag in its exe file.)
But you can use
start /wait SomeGuiApp
to force cmd to wait.
However you appear to have the oposite problem: it could be that &. It is designed for conditionally performing one action dependent on the return value from the previous. But return values are not really meaningful for GUI apps.
Why not run them as separate commands: on different lines of the cmd script or separated (IIRC) by a semicolon.
Remember, with command extensions on you can use parentheses to have multiple lines under the control of if etc.

execute 2 commands in File shortcut

I am using Windows 7 professional.
I have auto generated file shortcut for the program.
I need to delete one folder before starting the program every time.
Can I automatize it without creating .bat file? e.g. using this command del \directory\path\* /g "C:\Program Files (x86)\program.exe" in the shortcut properties.
Yes you can do this:
C:\Windows\System32\cmd.exe /C "del \directory\path\* /Q & "C:\Program Files (x86)\program.exe"
The & sign tells the shell to run several commands in sequence.

Resources