Can VBScript do what I want? [closed] - vbscript

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Having never used VBScript before, I just want to make sure I'm headed down the right path before I launch into it.
I need to create a process that will run via Windows Scheduler on a weekly basis.
I need the script to do the following:
Call PSFTP.exe and open a SSH session to a SFTP site, download a file and save it in a particular folder.
Unzip the files after download.
Open Truecrypt and mount encrypted volumes.
Activate a few other processes via the cmd line, in order.
All of this needs to be in order and each step needs to wait for the previous step to finish.
Can I achieve this using VBScript or a combination of VBScript and BAT files? Or should I be going down a different route?
Thanks in advance!
GPC

in its simplest form, what you want may be achieved with this short BAT file
::: C:\DEST\SO.BAT :::
pushd c:\dest
echo cd downloads > psftp.scr
echo get file.zip >> psftp.scr
echo quit >> psftp.scr
psftp user#domain.com -pw password -b psftp.scr
7z x -o file.zip
truecrypt /q /v myvolume
and schedule it to run every monday with this command
AT 09:00 /EVERY:MONDAY C:\DEST\SO.BAT
or (thanks, iesou!) in case you need specific user rights, want a task specific name... with
schtasks /create /SC Weekly /MO 1 /D Friday /TN "File Download and Extract" /TR "C:\DEST\SO.BAT" /ST 09:00 /RU PCNAME\USER /RP PASSWORD

Related

Replace special characters using Windows batch script [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 months ago.
Improve this question
I am trying to replace these special characters using Windows batch scripting.
Existing
To
My "name" is XXXX
My \"name\" is XXXX
My name is XXX\X
My name is XXX\\X
I tried to achieve this through Informatica Cloud. It is not working, so I am trying to create one single code for these scenarios.
Try drag and drop your input file over this batch script using regex in powershell to replace the special char :
#echo off
Title Replace Some Special Char
Set "InputFile=%1"
If [%InputFile%] EQU [] echo/ You should Drag and Drop an Inputfile over this batch script "%~nx0" & TimeOut /T 8 /NoBreak>nul & exit /b 1
Powershell -Command "(gc '%InputFile%' -raw) -replace '([\"\\])', '\$1' ^| Out-File output.txt"
Start "" output.txt

Trusted Publisher Certificate installation [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 11 months ago.
Improve this question
Is there any way we can add certificate using cmd/shell/bat silently without administrator rights in windows 10.
I have a command which silently add cert in "Trusted Publisher" :
certutil -addstore "TrustedPublisher" my_certificate.cer
But this command needs administrator command prompt to run.
According to comments below question, this batch should answer your needs:
#echo off
setlocal EnableExtensions EnableDelayedExpansion
REM Check admin mode, auto-elevate if required.
openfiles > NUL 2>&1 || (
REM Not elevated. Do it.
echo createObject^("Shell.Application"^).shellExecute "%~dpnx0", "%*", "", "runas">"%TEMP%\%~n0.vbs"
cscript /nologo "%TEMP%\%~n0.vbs"
goto :eof
)
del /s /q "%TEMP%\%~n0.vbs" > NUL 2>&1
REM Can't be here without elevation.
certutil -addstore "TrustedPublisher" my_certificate.cer
goto :eof
The batch will ask for elevation automatically and then execute your command, in an elevated cmd, and terminate.
How it works:
openfiles is a standard program shipped with Windows 10 (for Windows 7, for example, I used to do that with fsutils instead).
This program have a particularity: it requires elevation, does nothing harmful with no parameter, and returns a suitable error code without elevation.
So, when you launch it without elevation, it prints an error message and returns 1.
With elevation, it prints things and returns 0.
Because we don't care about what it displays, both its stdout and stderr are sent to NUL.
So, when we're NOT elevated, the || operator will execute the code within parentheses. Otherwise, it skips it and go to the del line just after - this line is designed to clean the temporary file used for elevation, I'll explain it below.
So, we're not elevated. The purpose is to create a very tiny VBS script, within %TEMP% folder. In order to not mess with multiple batchs launched simultaneously, we name this temporary file following the current batch filename (that's the "%TEMP%%~n0.vbs" part).
The VBS contains a single command: it will call "ShellExecute" on the batch file itself (NOT the VBS), with all seen parameters (they're expanded when creating the VBS file, they're not passed to VBS then to BAT again) using the runas keyword - and here is the magic.
This keyword does this (see Microsoft documentation):
runas Launches an application as Administrator. User Account Control (UAC) will prompt the user for consent to run the application elevated or enter the credentials of an administrator account used to run the application.
Unfortunately, we can't call this function directly from a batch (at least not without some ugly tricks), but it's very easy and understandable to do so from a VBS. And VBS is standard on Windows, too.
So, we now launch the VBS, and we terminate the non-elevated batch with goto :eof. The VBS starts, and relaunch the batch, but with elevation (and an UAC prompt). The batch starts again, has all its previous command line parameters, will detect that it's already elevated.
We just need now to clean the temporary VBS file with the del command, and we can continue our batch being sure that we are in an elevated process.

Request help for a batch script to kill a process after a program is closed [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
How do I modify the following batch script to kill a process instead of a task?
For example, if BBB.exe once executed runs as a process, how would I kill that process once AAA.exe is closed?
To clarify, if you open task manager, tasks are listed under the "applications" tab and a process is listed under the "processes" tab. The program represented as "BBB.exe" that I'm trying to kill immediately once AAA.exe is closed only opens to the system tray and not the task bar and therefore is not present in the "applications" tab but only the "processes" tab when open. The following batch file does not have any effect on ending program "BBB.exe" even when the machine is ran with admin privileges. I've seen the "Process.Kill()" command but I'm not sure how to properly utilize it.
Thanks in advance.
#Echo off
CD "C:\Users\XXX\XXX\XXX"
start AAA.exe
CD "C:\XXX\XXX"
start BBB.exe
:TEST
Tasklist /FI "IMAGENAME eq AAA.exe" 2>NUL | Find /I /N AAA.exe>NUL
If "%ERRORLEVEL%"=="0" goto ACTIVE
:DEAD
Taskkill /F /IM BBB.exe
Exit
:ACTIVE
Timeout /T 1
Goto TEST
I found out what the problem is.
The issue lies in that the "taskkill" command was never being deployed because command prompt remained in the directory of BBB.exe where the "taskkill" executable doesn't exist.
Simply changing the directoy to either "system32" or "syswow64" (depending on the OS installation) after executing both programs and before running the "taskkill" command in the batch file solved the issue.

How to use a variable to get the current directory path correctly? Trying to run a virus scanner to scan the current directory from context menu [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I can use the variable %CD% to run a command-line virus scanner to scan the current directory from command prompt like this.
C:\AVPTool\AVPTool.exe SCAN %CD% /R:KAVSCANLOG.txt
I'd like use it from context menu to easily scan the folder with just two clicks.
I modified the registry and created a key called Scan with AVPTool in HKEY_CLASSES_ROOT\Directory\shell and within that key I created another key called command and changed the value to
"cmd.exe /k cd %1 & C:\AVPTool\AVPTool.exe SCAN %CD% /R:KAVSCANLOG.txt"
But this doesn't work since %CD% doesn't get translated into the current working directory.
I'd try
"cmd.exe /k cd %1 & C:\AVPTool\AVPTool.exe SCAN "%1" /R:KAVSCANLOG.txt"
since the line would be processed by replacing the %-variables and THEN executed, %CD% would be replaced by whatever the current directory of the INVOKING process is, not the directory in which the process is RUN. The current directory is only changed AFTER the cd has been executed, and by that time, %CD% has already been installed into the command - as it stood when the cmd.exe was invoked.

Notepad++ NppExec run in cmd [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
How can I make my commands run in NppExec run in cmd, as opposed to the built in console, which doesn't work with things like: "Press any key to continue", which only works when you press enter?
You want to take a look at cmd /? output and http://ss64.com/nt/. Using start along with cmd /c will give an external window and using cmd /k will keep it in the nppexec console. One thing I don't like about the /k option is that it really isn't true as 'any key' doesn't do the trick and Enter needs to be used.
Test it out with cmd /k pause and start cmd /c pause.
Notice the start option has the window close, so any history will go away too. If that's important then substitute /k for the /c and use exit when done.

Resources