Run Autocad exe and load script file error - windows

This is My first post in here
I need a help for your side I have made a batch file for run autocad exe and load a script file but give error when I run the batch file
#echo off
set KEY_NAME=HKCU\Software\Laxman Enterprises\Xpresslisp Tools
set VALUE_NAME=installpath
set FN=loadload
set FE=scr
FOR /F "tokens=2*" %%A IN ('REG.exe query "%KEY_NAME%" /v "%VALUE_NAME%"') DO (set pInstallDir=%%B)
set approot=%pInstallDir:~0,-1%
echo %approot%\%FN%.%FE%
"C:\Program Files (x86)\AutoCAD 2002\acad.exe" /b %approot%\%FN%.%FE%
pause
Error: while running batch file autocad opens and in commandline the script file not loading "Xpresslisp.scr": Can't find file."
and bellow one is working
script file loading without getting error
#echo off
set path=%USERPROFILE%
set fol=Documents
set NAME=1
set SUFFIX=scr
"C:\Program Files (x86)\AutoCAD 2002\acad.exe" /b %path%\%fol%\%NAME%.%SUFFIX%
pause

Regarding your second question in the comments...
Bellow command will create the text file and write the first line to it e.g. "some text" like in the command below.
Echo some text > full_path_to_txt_file
Command below will append new text to same file.
Echo some text >> full_path_to_txt_file
'>' char creates file and writes firs line
'>>' char append text

check that %path%\%fol%\%NAME%.%SUFFIX% returns the Full Path to the "Xpresslisp.scr" file !
if it does, inspect the Full Path and see if it contains any white spaces.
if it does, enclose the %path%\%fol%\%NAME%.%SUFFIX% with apostrophes
"%path%\%fol%\%NAME%.%SUFFIX%"

It may be something as simple as blindly removing the last character of the installpath without knowing for sure what it is, (doublequote or backslash?).
As there is unlikely to be multiple copies of any filename in the Xpresslisp Tools tree, I would suggest something like this:
#Echo Off
Set "KEY_NAME=HKCU\Software\Laxman Enterprises\Xpresslisp Tools"
Set "VALUE_NAME=installpath"
Set "FN=loadload"
Set "FE=scr"
(Echo=FILEDIA 0
Echo=(LOAD "C:\\loadmyfile.lsp"^)
Echo=FILEDIA 1)>%FN%.%FE%
For /F "Tokens=2*" %%A In ('Reg Query "%KEY_NAME%" /v "%VALUE_NAME%"') Do (
For /F "Delims=" %%C In ('Dir/B/S/A-D "%%~B"\"%FN%.%FE%" 2^>Nul') Do (
Start "" "%ProgramFiles(x86)%\AutoCAD 2002\acad.exe" /b "%%~C"))
This doesn't care if there is a trailing backslash or not and will only run the AutoCAD command if the file is there.

Related

Backup script - find file by pattern, read it's full name and pass to script

I'm trying to use 7-Zip for backup purposes.
I have already wrote script for full backup:
#echo off
set source="c:\Source"
set destination="C:\Dest"
set dd=%DATE:~0,2%
set mm=%DATE:~3,2%
set yyyy=%DATE:~6,4%
set curdate=%dd%-%mm%-%yyyy%
"C:\Program Files\7-Zip\7z.exe" a -tzip -ssw -mx6 -r0 %destination%\Full_%curdate%.zip %source%
The new script intended for incremental backup is started after the full backup is made. But I don't really get how to make my second script to read files from directory and look for the file staring like full_xx_xx_xxxx.zip and assign its filename to a variable and then pass it to the script for incremental backup.
I tried script below, but it's not working:
#echo off
set source="c:\Source"
set destination="c:\Dest"
set exten="Full_*.zip"
set passwd="NAS"
set dd=%DATE:~0,2%
set mm=%DATE:~3,2%
set yyyy=%DATE:~6,4%
set curdate=%dd%-%mm%-%yyyy%
for %%a in %exten do echo %%a
"C:\Program Files\7-Zip\7z.exe" u -tzip -ssw -r0 %destination%\%%a.zip -u- -up0q3x2z0!"%destination%\diff_%date%.zip" %source%
There are multiple mistakes in both scripts.
I recommend reading first How to set environment variables with spaces? and Why is no string output with 'echo %var%' after using 'set var = text' on command line?. The syntax set variable="value in quotes" is often not good because it assigns the string "value in quotes" with the double quotes and all trailing spaces/tabs which might exist also in batch file to the environment variable with name variable. This syntax is problematic on concatenating the string value of the environment variable with other strings as done in posted code with %destination% because of the " being now somewhere in middle of the final argument string instead of enclosing the entire argument string. Better is the syntax set "variable=value without or with spaces" with " left to variable name because of the double quotes are interpreted now as argument string separators and perhaps existing spaces/tabs on line after second " are ignored by Windows command processor.
The usage of dynamic environment variable DATE makes it possible to quickly get current locale date in a format usable for file/folder names. But it must be taken into account that the date format of value of DATE depends on region/country/locale set for the user account which is used on running the batch file. I suppose that echo %DATE% results in an output of a date in format DD.MM.YYYY and so the command lines using DATE are correct for you with your user account according to the configured country.
The FOR command line is completely wrong and results in an exit of batch file execution with an error message output by cmd.exe interpreting the batch file line by line. This error output can be seen on running the batch file from within a command prompt window instead of double clicking on the batch file. See debugging a batch file for details on how to debug a batch file to find syntax errors like this reported by Windows command processor during execution of a batch file.
So I suggest for the first batch file:
#echo off
set "Source=C:\Source"
set "Destination=C:\Dest"
set "CurrentDate=%DATE:~6,4%-%DATE:~3,2%-%DATE:~0,2%"
"%ProgramFiles%\7-Zip\7z.exe" a -tzip -ssw -mx6 -r0 "%Destination%\Full_%CurrentDate%.zip" "%Source%"
The current locale date is assigned to the environment variable CurrentDate in format YYYY-MM-DD instead of DD-MM-YYYY. The date format YYYY-MM-DD is the international date format according to ISO 8601. It has one big advantage in comparison to all locale date formats in file names: The file names with date in format YYYY-MM-DD sorted alphabetically as usual are at the same time sorted chronological. That makes it much easier for people and scripts finding a specific file in a list of file names with date in file name.
I am not really sure what you want to do with the second batch file. So I can only suppose what you want to do and suggest for the second batch file:
#echo off
set "Source=C:\Source"
set "Destination=C:\Dest"
set "CurrentDate=%DATE:~6,4%-%DATE:~3,2%-%DATE:~0,2%"
set "NamePattern=Full_*.zip"
for /F "skip=1 eol=| delims=" %%I in ('dir "%Destination%\%NamePattern%" /A-D /B /O-N 2^>nul') do (
"%ProgramFiles%\7-Zip\7z.exe" u -tzip -ssw -r0 "%Destination%\%%I" -u- -up0q3x2z0!"%Destination%\Diff_%CurrentDate%.zip" "%Source%"
goto Done
)
:Done
The FOR loop runs command DIR with using a separate command process started in background to get the list of Full_*.zip file names in destination directory sorted reverse by name which means the full backup ZIP file created today before with first batch file is at top on using date format YYYY-MM-DD and the previously created ZIP file from yesterday (or whenever the last but one full ZIP file was created) is output as second line.
FOR skips the first line with ZIP file name with current date and runs 7-Zip with previously created ZIP file (yesterday) to create the difference ZIP file. Then the FOR loop is exited without processing all other full ZIP files with a jump to the label below the FOR loop.
Both batch files together:
#echo off
setlocal EnableExtensions DisableDelayedExpansion
set "Source=C:\Source"
set "Destination=C:\Dest"
set "CurrentDate=%DATE:~6,4%-%DATE:~3,2%-%DATE:~0,2%"
set "NamePattern=Full_*.zip"
rem Create full ZIP backup.
"%ProgramFiles%\7-Zip\7z.exe" a -tzip -ssw -mx6 -r0 "%Destination%\Full_%CurrentDate%.zip" "%Source%"
rem Create difference ZIP backup with files added/changed in source directory
rem in comparison to the files compressed into last but on full ZIP backup.
for /F "skip=1 eol=| delims=" %%I in ('dir "%Destination%\%NamePattern%" /A-D /B /O-N 2^>nul') do (
"%ProgramFiles%\7-Zip\7z.exe" u -tzip -ssw -r0 "%Destination%\%%I" -u- -up0q3x2z0!"%Destination%\Diff_%CurrentDate%.zip" "%Source%"
goto Done
)
:Done
endlocal
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
dir /?
echo /?
endlocal /?
for /?
rem /?
set /?
setlocal /?

How to process 2 FOR loops after each other in batch?

My problem is that two FOR loops are working separately, but don't want to work one after another.
The goal is:
The first loop creates XML files and only when the creation has already been done the second loop starts and counts the size of created XML files and writes it into .txt file.
#echo off
Setlocal EnableDelayedExpansion
for /f %%a in ('dir /b /s C:\Users\NekhayenkoO\test\') do (
echo Verarbeite %%~na
jhove -m PDF-hul -h xml -o C:\Users\NekhayenkoO\outputxml\%%~na.xml %%a
)
for /f %%i in ('dir /b /s C:\Users\NekhayenkoO\outputxml\') do (
echo %%~ni %%~zi >> C:\Users\NekhayenkoO\outputxml\size.txt
)
pause
This question can be answered easily when knowing what jhove is.
So I searched in world wide web for jhove, found very quickly the homepage JHOVE | JSTOR/Harvard Object Validation Environment and downloaded also jhove-1_11.zip from SourceForge project page of JHOVE.
All this was done by me to find out that jhove is a Java application which is executed on Linux and perhaps also on Mac using the shell script jhove and on Windows the batch file jhove.bat for making it easier to use by users.
So Windows command interpreter searches in current directory and next in all directories specified in environment variable PATH for a file matching the file name pattern jhove.* having a file extension listed in environment variable PATHEXT because jhove.bat is specified without file extension and without path in the batch file.
But the execution of a batch file from within a batch file without usage of command CALL results in script execution of current batch file being continued in the other executed batch file without ever returning back to the current batch file.
For that reason Windows command interpreter runs into jhove.bat on first file found in directory C:\Users\NekhayenkoO\test and never comes back.
This behavior can be easily watched by using two simple batch files stored for example in C:\Temp.
Test1.bat:
#echo off
cd /D "%~dp0"
for %%I in (*.bat) do Test2.bat "%%I"
echo %~n0: Leaving %~f0
Test2.bat:
#echo %~n0: Arguments are: %*
#echo %~n0: Leaving %~f0
On running from within a command prompt window C:\Temp\Test1.bat the output is:
Test2: Arguments are: "Test1.bat"
Test2: Leaving C:\Temp\Test2.bat
The processing of Test1.bat was continued on Test2.bat without coming back to Test1.bat.
Now Test1.bat is modified to by inserting command CALL after do.
Test1.bat:
#echo off
cd /D "%~dp0"
for %%I in (*.bat) do call Test2.bat "%%I"
echo Leaving %~f0
The output on running Test1.bat from within command prompt window is now:
Test2: Arguments are: "Test1.bat"
Test2: Leaving C:\Temp\Test2.bat
Test2: Arguments are: "Test2.bat"
Test2: Leaving C:\Temp\Test2.bat
Test1: Leaving C:\Temp\Test1.bat
Batch file Test1.bat calls now batch file Test2.bat and therefore the FOR loop is really executed on all *.bat files found in directory of the two batch files.
Therefore the solution is using command CALL as suggested already by Squashman:
#echo off
setlocal EnableDelayedExpansion
for /f %%a in ('dir /b /s "%USERPROFILE%\test\" 2^>nul') do (
echo Verarbeite %%~na
call jhove.bat -m PDF-hul -h xml -o "%USERPROFILE%\outputxml\%%~na.xml" "%%a"
)
for /f %%i in ('dir /b /s "%USERPROFILE%\outputxml\" 2^>nul') do (
echo %%~ni %%~zi>>"%USERPROFILE%\outputxml\size.txt"
)
pause
endlocal
A reference to environment variable USERPROFILE is used instead of C:\Users\NekhayenkoO.
All file names are enclosed in double quotes in case of any file found in the directory contains a space character or any other special character which requires enclosing in double quotes.
And last 2>nul is added which redirects the error message output to handle STDERR by command DIR on not finding any file to device NUL to suppress it. The redirection operator > must be escaped here with ^ to be interpreted on execution of command DIR and not as wrong placed redirection operator on parsing already the command FOR.
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
call /?
cd /?
dir /?
echo /?
for /?
And read also the Microsoft article Using command redirection operators.
You need to use the START command with the /WAIT flag when you launch an external application.
I believe it would look something like this:
START /WAIT jhove -m PDF-hul -h xml -o C:\Users\NekhayenkoO\outputxml\%%~na.xml %%a
That should cause the batch file to pause and wait for the external application to finish before proceeding.

Execute command in Windows batch file

I have a file located on a share folder. I have to execute that file from the local PC. The name of the file changes every day, hence I should find the name first and then execute that .exe file.
Here is my Batch:
#echo off
set FILE =
FOR /F %%a IN ('dir /s/b') DO (
set FILE=%%a
)
start %FILE%
The last line does not execute the file. Why is that?
Does it have spaces in the path?
Try this:
START "" "%FILE%"
The "" signifies an empty window title. When you quote the filename you have to specify a title, otherwise START will treat your quoted file path as the title.

Unable to display the value of a variable in batch file

I have a batch file to count the number of specific files in a folder. The contents are given below:
set xx = %DATE:~10,4%%DATE:~4,2%%DATE:~7,2%
set count=dir C:\Archive\*%xx%.csv | find "File(s)"
echo %count%
But the output of the last command displays as
echo
ECHO is on
What am I doing wrong here?? Can anyone help please?
To execute a command an retrieve its output you need the for /f command (see for /? help)
set "xx=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%"
for /f %%a in ('dir /a-d /b "c:\Archive\*%xx%.csv" ^| find /c /v ""') do set "count=%%a"
echo %count%
This will execute a dir command for the required files without folders included in the list, in bare format (no header, summary and no aditional file info) and instead of search for the File(s) (in a different windows locale the text is different), it uses find to count (/c) the number of non empty lines (/v ""). The output is a number that is stored in the for replaceable parameter %%a, and then copied to the required variable

Access clipboard in Windows batch file

Any idea how to access the Windows clipboard using a batch file?
To set the contents of the clipboard, as Chris Thornton, klaatu, and bunches of others have said, use %windir%\system32\clip.exe.
Update 2:
For a quick one-liner, you could do something like this:
powershell -sta "add-type -as System.Windows.Forms; [windows.forms.clipboard]::GetText()"
Capture and parse with a for /F loop if needed. This will not execute as quickly as the JScript solution below, but it does have the advantage of simplicity.
Updated solution:
Thanks Jonathan for pointing to the capabilities of the mysterious htmlfile COM object for retrieving the clipboard. It is possible to invoke a batch + JScript hybrid to retrieve the contents of the clipboard. In fact, it only takes one line of JScript, and a cscript line to trigger it, and is much faster than the PowerShell / .NET solution offered earlier.
#if (#CodeSection == #Batch) #then
#echo off
setlocal
set "getclip=cscript /nologo /e:JScript "%~f0""
rem // If you want to process the contents of the clipboard line-by-line, use
rem // something like this to preserve blank lines:
for /f "delims=" %%I in ('%getclip% ^| findstr /n "^"') do (
setlocal enabledelayedexpansion
set "line=%%I" & set "line=!line:*:=!"
echo(!line!
endlocal
)
rem // If all you need is to output the clipboard text to the console without
rem // any processing, then remove the "for /f" loop above and uncomment the
rem // following line:
:: %getclip%
goto :EOF
#end // begin JScript hybrid chimera
WSH.Echo(WSH.CreateObject('htmlfile').parentWindow.clipboardData.getData('text'));
Old solution:
It is possible to retrieve clipboard text from the Windows console without any 3rd-party applications by using .NET. If you have powershell installed, you can retrieve the clipboard contents by creating an imaginary textbox and pasting into it. (Source)
Add-Type -AssemblyName System.Windows.Forms
$tb = New-Object System.Windows.Forms.TextBox
$tb.Multiline = $true
$tb.Paste()
$tb.Text
If you don't have powershell, you can still compile a simple .NET application to dump the clipboard text to the console. Here's a C# example. (Inspiration)
using System;
using System.Threading;
using System.Windows.Forms;
class dummy {
[STAThread]
public static void Main() {
if (Clipboard.ContainsText()) Console.Write(Clipboard.GetText());
}
}
Here's a batch script that combines both methods. If powershell exists within %PATH%, use it. Otherwise, find the C# compiler / linker and build a temporary .NET application. As you can see in the batch script comments, you can capture the clipboard contents using a for /f loop or simply dump them to the console.
:: clipboard.bat
:: retrieves contents of clipboard
#echo off
setlocal enabledelayedexpansion
:: Does powershell.exe exist within %PATH%?
for %%I in (powershell.exe) do if "%%~$PATH:I" neq "" (
set getclip=powershell "Add-Type -AssemblyName System.Windows.Forms;$tb=New-Object System.Windows.Forms.TextBox;$tb.Multiline=$true;$tb.Paste();$tb.Text"
) else (
rem :: If not, compose and link C# application to retrieve clipboard text
set getclip=%temp%\getclip.exe
>"%temp%\c.cs" echo using System;using System.Threading;using System.Windows.Forms;class dummy{[STAThread]
>>"%temp%\c.cs" echo public static void Main^(^){if^(Clipboard.ContainsText^(^)^) Console.Write^(Clipboard.GetText^(^)^);}}
for /f "delims=" %%I in ('dir /b /s "%windir%\microsoft.net\*csc.exe"') do (
if not exist "!getclip!" "%%I" /nologo /out:"!getclip!" "%temp%\c.cs" 2>NUL
)
del "%temp%\c.cs"
if not exist "!getclip!" (
echo Error: Please install .NET 2.0 or newer, or install PowerShell.
goto :EOF
)
)
:: If you want to process the contents of the clipboard line-by-line, use
:: something like this to preserve blank lines:
for /f "delims=" %%I in ('%getclip% ^| findstr /n "^"') do (
set "line=%%I" & set "line=!line:*:=!"
echo(!line!
)
:: If all you need is to output the clipboard text to the console without
:: any processing, then remove the above "for /f" loop and uncomment the
:: following line:
:: %getclip%
:: Clean up the mess
del "%temp%\getclip.exe" 2>NUL
goto :EOF
Slimming it down (on a new enough version of Windows):
set _getclip=powershell "Add-Type -Assembly PresentationCore;[Windows.Clipboard]::GetText()"
for /f "eol=; tokens=*" %I in ('%_getclip%') do set CLIPBOARD_TEXT=%I
First line declares a powershell commandlet.
Second line runs and captures the console output of this commandlet into the CLIPBOARD_TEXT enviroment variable (cmd.exe's closest way to do bash style backtick ` capture)
Update 2017-12-04:
Thanks to #Saintali for pointing out that PowerShell 5.0 adds Get-Clipboard as a top level cmdlets, so this now works as a one liner:
for /f "eol=; tokens=*" %I in ('powershell Get-Clipboard') do set CLIPBOARD_TEXT=%I
The clip command is good to pipe text to the clipboard, but it can't read from the clipboard. There is a way in vbscript / javascript to read / write the clipboard but it uses automation and an invisible instance if Internet Explorer to do it so its pretty fat.
The best tool I've found for working the clipboard from script is Nirsoft's free NirCmd tool.
http://www.nirsoft.net/utils/nircmd.html
Its like a swiss army knife of batch commands all in one small .exe file. For clipboard commands you would say someting like
nircmd clipboard [Action] [Parameter]
Plus you can directly refer to clipboard contents in any of its commands using its ~$clipboard$ variable as an argument. Nircmd also has commands in it to run other programs or commands from so it is possible to use it to pass the clipboard contents as an argument to other batch commands this way.
Clipboard actions:
set - set the specified text into the clipboard.
readfile - set the content of the specified text file into the clipboard.
clear - clear the clipboard.
writefile - write the content of the clipboard to a file. (text only)
addfile - add the content of the clipboard to a file. (text only)
saveimage - Save the current image in the clipboard into a file.
copyimage - Copy the content of the specified image file to the clipboard.
saveclp - Save the current clipboard data into Windows .clp file.
loadclp - Load Windows .clp file into the clipboard.
Note that most programs will always write a plain text copy to the clipboard even when they are writing a special RTF or HTML copy to the clipboard but those are written as content using a different clipboard format type so you may not be able to access those formats unless your program explicitly requests that type of data from the clipboard.
Best way I know, is by using a standalone tool called WINCLIP .
You can get it from here: Outwit
Usage:
Save clipboard to file: winclip -p file.txt
Copy stdout to clipboard: winclip -c Ex: Sed 's/find/replace/' file | winclip -c
Pipe clipboard to sed: winclip -p | Sed 's/find/replace/'
Use winclip output (clipboard) as an argument of another command:
FOR /F "tokens=* usebackq" %%G in ('winclip -p') Do (YOUR_Command %%G ) Note that if you have multiple lines in your clipboard, this command will parse them one by one.
You might also want to take a look at getclip & putclip tools: CygUtils for Windows but winclip is better in my opinion.
With Vista or higher, it's built in. Just pipe output to the "clip" program.
Here's a writeup (by me):
http://www.clipboardextender.com/general-clipboard-use/command-window-output-to-clipboard-in-vista
The article also contains a link to a free utility (written by Me, I think) called Dos2Clip, which can be used on XP.
EDIT: I see that I've gotten the question backwards, my solution OUTPUTS to the clipboard, doesn't read it. sorry!
Update: Along with Dos2Clip, is Clip2Dos (in the same zip), which will send the clipboard text to stdout. So this should work for you. Pascal source is included in the zip.
To retrive clipboard content from your batch script: there is no "pure" batch solution.
If you want an embed 100% batch solution, you will need to generate the other language file from your batch.
Here is a short and batch embed solution which generate a VB file (Usually installed on most windows)
Since all answers are confusing, here my code without delays or extra windows to open stream link copied from clipboard:
#ECHO OFF
//Name of TEMP TXT Files
SET TXTNAME=CLIP.TXT
//VBA SCRIPT
:: VBS SCRIPT
ECHO.Set Shell = CreateObject("WScript.Shell")>_TEMP.VBS
ECHO.Set HTML = CreateObject("htmlfile")>>_TEMP.VBS
ECHO.TXTPATH = "%TXTNAME%">>_TEMP.VBS
ECHO.Set FileSystem = CreateObject("Scripting.FileSystemObject")>>_TEMP.VBS
ECHO.Set File = FileSystem.OpenTextFile(TXTPATH, 2, true)>>_TEMP.VBS
ECHO.File.WriteLine HTML.ParentWindow.ClipboardData.GetData("text")>>_TEMP.VBS
ECHO.File.Close>>_TEMP.VBS
cscript//nologo _TEMP.VBS
:: VBS CLEAN UP
DEL _TEMP.VBS
SET /p streamURL=<%TXTNAME%
DEL %TXTNAME%
:: 1) The location of Player
SET mvpEXE="D:\Tools\Programs\MVP\mpv.com"
:: Open stream to video player
%mvpEXE% %streamURL%
#ECHO ON
Piping output to the clipboard is provided by clip, as others have said. To read input from the clipboard, use the pclip tool in this bundle. And there's tons of other good stuff in there.
So for example, you're going through an online tutorial and you want to create a file with the contents of the clipboard...
c:\>pclip > MyNewFile.txt
or you want to execute a copied command...
c:\>pclip | cmd
This might not be the exact answer, but it will be helpful for your Quest.
Original post:
Visit https://groups.google.com/d/msg/alt.msdos.batch/0n8icUar5AM/60uEZFn9IfAJ
Asked by Roger Hunt
Answered by William Allen
Much Cleaner Steps:
Step 1) create a 'bat' file named Copy.bat in desktop using any text editors and copy and past below code and save it.
#ECHO OFF
SET FN=%1
IF ()==(%1) SET FN=H:\CLIP.TXT
:: Open a blank new file
REM New file>%FN%
ECHO.set sh=WScript.CreateObject("WScript.Shell")>_TEMP.VBS
ECHO.sh.Run("Notepad.exe %FN%")>>_TEMP.VBS
ECHO.WScript.Sleep(200)>>_TEMP.VBS
ECHO.sh.SendKeys("^+{end}^{v}%%{F4}{enter}{enter}")>>_TEMP.VBS
cscript//nologo _TEMP.VBS
ECHO. The clipboard contents are:
TYPE %FN%
:: Clean up
DEL _TEMP.VBS
SET FN=
Step 2) create a Blank text file (in my case 'CLIP.txt' in H Drive) or anywhere, make sure you update the path in Copy.bat file under 'FN=H:\CLIP.txt' with your destination file path.
That's it.
So, basically when you copy any text from anywhere and run Copy.bat file from desktop, it updates CLIP.txt file with the Clipboard contents in it and saves it.
Uses:
I use it to transfer data from remotely connected machines where copy/paste is disabled between different connections; where shared drive (H:) is common to all Connections.
Multiple lines
The problem is resolved, but disappointment remains.
I was forced to split one command into two.
First of them well understands the text and service characters, but does not understand the backspace.
The second understands backspace, but does not understand many service characters.
Can anyone unite them?
Notepad ++, in the place where it should open, is commented out because sometimes the window does not get access to enter characters and therefore you need to make sure that it is active.
Of course, it is better to enter characters using the PID of the notebook process, but ...
The request from wmic opens for a long time, so do not close the notepad window until the bat file is closed.
#echo off
set "like=Microsoft Visual C++"
set "flag=0"
start /max C:\"Program Files\Notepad++\notepad++.exe" -nosession -multiInst
( set LF=^
%= NEWLINE =%
)
set ^"NL=^^^%LF%%LF%^%LF%%LF%^^"
::------------------
setlocal enabledelayedexpansion
for /f "usebackq delims=" %%i in ( `wmic /node:"papa" product where "Name like '%%%like%%%'" get * ^| findstr /r /v "^$"`) do (
for /f tokens^=1^ delims^=^" %%a in ("%%i") do set str=%%a
if "!flag!"=="0" (
::start /max C:\"Program Files\Notepad++\notepad++.exe" -nosession -multiInst& set "flag=1"
for /f "delims=" %%i in ('mshta "javascript:new ActiveXObject('WScript.Shell').SendKeys('{BS}{BS}{BS}{BS}');close(new ActiveXObject('Scripting.FileSystemObject'));"') do set
set flag=1
)
#set /P "_=%%str%%"<NUL|clip
for /f "delims=" %%i in ('mshta "javascript:new ActiveXObject('WScript.Shell').SendKeys('^v');close(new ActiveXObject('Scripting.FileSystemObject'));"') do set
(echo %%NL%%)|clip
for /f "delims=" %%i in ('mshta "javascript:new ActiveXObject('WScript.Shell').SendKeys('^v');close(new ActiveXObject('Scripting.FileSystemObject'));"') do set
)
setlocal disabledelayedexpansion
Here's one way with mshta:
#echo off
:printClip
for /f "usebackq tokens=* delims=" %%i in (
`mshta "javascript:Code(close(new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(clipboardData.getData('Text'))));"`
) do (
echo cntent of the clipboard:
echo %%i
)
the same thing for accessing it directly from console:
for /f "usebackq tokens=* delims=" %i in (`mshta "javascript:Code(close(new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(clipboardData.getData('Text'))));"`) do #echo %i

Resources