I am able to create .pfx file from my script but unable to add it to local store (under Certificates/Personal).
Although, I am able to double click on .pfx and install it manually.
But when using this script, it shows up in certmanager with Name X and under a different folder.
Script (batch file):
#ECHO OFF
ECHO.
echo %*
cd C:\Program Files (x86)\Windows Kits\8.1\bin\x64
makecert -sv SimulatorCertificate.pvk -n "CN=X" SimulatorCertificate.cer -r
pvk2pfx -pvk SimulatorCertificate.pvk -spc SimulatorCertificate.cer -pfx SimulatorCertificate.pfx -pi password
//THIS IS THE LINE RESPONSIBLE FOR ADDING IT TO STORE
CERTUTIL -f -p password -importpfx "SimulatorCertificate.pfx"
echo "done"
ECHO.
PAUSE
CLS
EXIT
Command prompt says:
When I check in certmgr (here):
There is no certificate added inside personal. Instead, the new certificate gets added in other folder as shown, with name X.
Why is this happening? Where am I going wrong?
Related
I have multiple .sql script files and want to execute them one by one in batch file with proper logging mechanism.
I wrote below batch command to solve the problem
#ECHO OFF
SET SQLCMD="C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\SQLCMD.EXE"
SET PATH="C:\Users\sql_scripts\"
SET SERVER="server_name"
SET DB="database"
SET LOGIN="user_name"
SET PASSWORD="password"
SET OUTPUT="C:\Users\sql_scripts\output\OutputLog.txt"
CD %PATH%
ECHO %date% %time% > %OUTPUT%
for %%f in (*.sql) do (
%SQLCMD% -S %SERVER% -d %DB% -U %LOGIN% -P %PASSWORD% -i %%~f -b >> %OUTPUT%
)
But it has few problems that I want to solve as listed below :
I want to create dynamic out put file names based on input file name. Example if input sql file
name is "test.sql" then I want to create output file in "output" folder with name "test.sql".
Currently It writes all the log to one file i.e. OutputLog.txt
I want to show output log with script of execution to identify which script produced what
output. Let's say in one script file 5 scripts present then in output file I want to show the
script and its output log.
I am trying to use .bat file (Windows) to automate a registration process.
Below is the content of my batch file:
C:
cd C:\Program Files (x86)\SSL_Client
admin -r
echo n
echo mithun
echo 12339-asdda-wewew
It works until admin -r which prompts user to enter Y/N
However above code doesnt work..
I am a newbie and sorry for such a basic question
Your script runs admin -r, and when finished, continues with the next line, which echoes n to the console (where you don't need it).
There is a trick to give inputs to an executable (which may or may not work - depends on the executable): pipe the information to it:
cd /d "C:\Program Files (x86)\SSL_Client"
(
echo n
echo mithun
echo 12339-asdda-wewew
)|admin -r
ftp
open ftp.drivehq.com
username
password
cd \wwwhome\Logs\
put "C:\Users\Cody\Desktop\ISO's\mini.iso"
bye
exit
How do you use %USERNAME% instead of hard-coding Cody, when used with ftp?
Here is another batch file solution with code similar to code written by Martin Prikryl with three enhancements.
%USERPROFILE% is used instead of C:\Users\%username% which makes this batch file solution work also on Windows XP and on machines on which the user's profile directory is not on drive C: or in a different directory than C:\Users which is of course possible too.
%SystemRoot%\System32\ftp.exe is used in the batch file instead of just ftp to make this batch file work also if by chance there is an ftp.* file with a file extension listed in environment variable PATHEXT in current directory or any other directory in environment variable PATH and not being the ftp executable in Windows system directory.
The ISO file name is renamed before upload with including a random decimal number between 0 and 32767 as asked for with a comment.
The command lines of enhanced batch file:
:RandomIsoName
set "RandomName=mini_%RANDOM%.iso"
if exist "%USERPROFILE%\Desktop\ISO's\%RandomName%" goto RandomIsoName
ren "%USERPROFILE%\Desktop\ISO's\mini.iso" "%RandomName%"
(
echo open hostname
echo username
echo password
echo cd \wwwhome\Logs\
echo put "%USERPROFILE%\Desktop\ISO's\%RandomName%"
echo bye
)>ftp.txt
%SystemRoot%\System32\ftp.exe -s:ftp.txt
You have to generate the ftp script using that variable:
echo open hostname>ftp.txt
echo username>>ftp.txt
echo password>>ftp.txt
echo cd \wwwhome\Logs\>>ftp.txt
echo put "C:\Users\%username%\Desktop\ISO's\mini.iso">>ftp.txt
echo bye>>ftp.txt
ftp -s:ftp.txt
I have a batch file for moving file from my local PC to server through SFTP. I have PuTTY installed in my system and the batch file code follows.
cd C:\Program Files (x86)\PuTTY
psftp
open <IP>
<user>
<PW>
cd /home/irisuser/iris/integration/dls_dlsblr_dlschnn_in_msg/in
lcd d:\
put log.sh
bye
The above code perfectly works when I type it in command prompt. But when I double click the .bat file and run it, it's not running and asking for username and password to be entered. My aim was to automate the whole thing and I need to run it by simply clicking the .bat file. But am not able to achieve it. Any ideas or snippets will help me.
You need to store the psftp script (lines from open to bye) into a separate file and pass that to psftp using -b switch:
cd "C:\Program Files (x86)\PuTTY"
psftp -b "C:\path\to\script\script.txt"
Reference:
https://the.earth.li/~sgtatham/putty/latest/htmldoc/Chapter6.html#psftp-option-b
EDIT: For username+password: As you cannot use psftp commands in a batch file, for the same reason, you cannot specify the username and the password as psftp commands. These are inputs to the open command. While you can specify the username with the open command (open <user>#<IP>), you cannot specify the password this way. This can be done on a psftp command line only. Then it's probably cleaner to do all on the command-line:
cd "C:\Program Files (x86)\PuTTY"
psftp -b script.txt <user>#<IP> -pw <PW>
And remove the open, <user> and <PW> lines from your script.txt.
Reference:
https://the.earth.li/~sgtatham/putty/latest/htmldoc/Chapter6.html#psftp-starting
https://the.earth.li/~sgtatham/putty/latest/htmldoc/Chapter3.html#using-cmdline-pw
What you are doing atm is that you run psftp without any parameter or commands. Once you exit it (like by typing bye), your batch file continues trying to run open command (and others), what Windows shell obviously does not understand.
If you really want to keep everything in one file (the batch file), you can write commands to psftp standard input, like:
(
echo cd ...
echo lcd ...
echo put log.sh
) | psftp <user>#<IP> -pw <PW>
Though this has side effects. For example, if the host is not known to plink (like if you run it first time on a new machine or under another local account, for example under Task Scheduler), the first line of input will be taken as a response to the host key prompt. Anything except for y/i/Enter is interpreted as as n (connect just once, without adding the key to the cache), so even the cd command. And the rest of the script will fail as the cd does not happen.
set DSKTOPDIR="D:\test"
set IPADDRESS="23.23.3.23"
>%DSKTOPDIR%\script.ftp ECHO cd %PAY_REP%
>>%DSKTOPDIR%\script.ftp ECHO mget *.report
>>%DSKTOPDIR%\script.ftp ECHO bye
:: run PSFTP Commands
psftp <domain>#%IPADDRESS% -b %DSKTOPDIR%\script.ftp
Set values using set commands before above lines.
I believe this helps you.
Referre psfpt setup for below link https://www.ssh.com/ssh/putty/putty-manuals/0.68/Chapter6.html
I am trying to download a file using wget in batch file,I don't want to download the file if the file all ready exist and it didn't change so I am using -N
also I am downloading the file from my personal FTP server so I want to hide my username and password details so I decided to hide output using >nul 2>&1
so my batch file is:
#echo off
blah blah
.....
echo please wait...
wget -N ftp://XXXXXXXXXX#YYYYYYY.com/file.jpg >nul 2>&1
now there are 2 problems:
The window title will still show my username & password , how I can hide the title or change the title ?
the user wont know if the operation was successful (download was done) or fail (no Internet or no file exist) or it didn't download because the file already exist , I wonder if I can make 3 IF STATEMENTS
IF file was downloaded then echo file download
IF file wasn't downloaded then echo error
IF file wasn't downloaded because was the same then echo file didnt change
Wget has built in switches that will prevent a download if the file already exists. It has switches to do most of what you want so you won't have to put the "if" statements in the batch file at all.
wget has an extensive list of switches. Really it's dev has thought of just about everything. Read those docs, if I remember they are about 150-200 pages long.
I agree with PA that if the file is sensitive then hiding the password in the console output won't do much in terms of security. However, to answer the OP's question:
1.
The title command is capable of changing the current window's title.
title My CMD Window
If the problem you're encountering is that a popup window for the wget command is coming up and displaying the username and password there, you can use the following. I apologize, I am not familiar with wget so I'm not sure on its behavior, hopefully this helps.
start "My WGET Window" wget -N ftp://XXXXXXXXXX#YYYYYYY.com/file.jpg >nul 2>&1
2.
A couple of checks before and after will be beneficial. First, check if the file exists and don't even bother with the wget if it does already exists (assuming from the wording of your post that you do not want to overwrite the file).
if exist file.jpg echo File already exists!&pause&goto :EOF
:: run wget here
if exist file.jpg (echo File download successful.) else (echo File download UNSUCCESSFUL.)
We don't need to check for all three conditions as the file either exists before hand (in which case the batch exits) or it does not in which case we test for a successful download. Note that it will be difficult to check for a partial file.
So, putting it all together:
#echo off
blah blah
.....
title My CMD Window
if exist file.jpg echo File already exists!&pause&goto :EOF
echo please wait...
start "My WGET Window" wget -N ftp://XXXXXXXXXX#YYYYYYY.com/file.jpg >nul 2>&1
if exist file.jpg (echo File download successful.) else (echo File download UNSUCCESSFUL.)