Trying to create a shortcut in batch for server - batch-file

Trying to create a shortcut in batch using a VBScript. I need to change the properties of the path to allow it to run in no-graphics mode.
set SCRIPT="%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs"
echo Set oWS = WScript.CreateObject("WScript.Shell") >> %SCRIPT%
echo Set shortcut = oWS.CreateShortcut("%USERPROFILE%\Desktop\unturned.exe -batchmode -nographics +secureserver/TheServer.lnk") >> %SCRIPT%
echo shortcut.TargetPath = "D:\SteamLibrary\SteamApps\common\Unturned\Unturned.exe" >> %SCRIPT%
echo shortcut.Save >> %SCRIPT%
cscript /nologo %SCRIPT%
del %SCRIPT%
It can't save.

This should did the trick :
#echo off
Set vbsfile=%TEMP%\%RANDOM%.vbs
Set MyFile=D:\SteamLibrary\SteamApps\common\Unturned\Unturned.exe
Set ShorcutName=Unturned
(
echo Call Shortcut("%MyFile%","%ShorcutName%"^)
echo ^'**********************************************************************************************^)
echo Sub Shortcut(CheminApplication,Nom^)
echo Dim objShell,DesktopPath,objShortCut,MyTab
echo Set objShell = CreateObject("WScript.Shell"^)
echo MyTab = Split(CheminApplication,"\"^)
echo If Nom = "" Then
echo Nom = MyTab(UBound(MyTab^)^)
echo End if
echo DesktopPath = objShell.SpecialFolders("Desktop"^)
echo Set objShortCut = objShell.CreateShortcut(DesktopPath ^& "\" ^& Nom ^& ".lnk"^)
echo objShortCut.TargetPath = Dblquote(CheminApplication^)
echo ObjShortCut.IconLocation = "Winver.exe,0"
echo objShortCut.Save
echo End Sub
echo ^'**********************************************************************************************
echo ^'Fonction pour ajouter les doubles quotes dans une variable
echo Function DblQuote(Str^)
echo DblQuote = Chr(34^) ^& Str ^& Chr(34^)
echo End Function
echo ^'**********************************************************************************************
) > %vbsfile%
Start /Wait %vbsfile%
Del %vbsfile%
::****************************************************************************************************

set SCRIPT="%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs"
echo Set oWS = WScript.CreateObject("WScript.Shell") >> %SCRIPT%
echo Set shortcut = oWS.CreateShortcut("%USERPROFILE%\Desktop\unturned.exe.lnk") >> %SCRIPT%
echo shortcut.TargetPath = "D:\SteamLibrary\SteamApps\common\Unturned\Unturned.exe -batchmode -nographics +secureserver/TheServer" >> %SCRIPT%
echo shortcut.Save >> %SCRIPT%
cscript /nologo %SCRIPT%
del %SCRIPT%

Related

Batch exe to shortcut

Currently, I am attempting to create a shortcut for a program, I was able to do so shown in the code below.
echo Set oWS = WScript.CreateObject("WScript.Shell") > CreateShortcut.vbs
echo sLinkFile = "%HOMEDRIVE%%HOMEPATH%\Desktop\Unturned Dedicated Server\Unturned - Server.lnk" >> CreateShortcut.vbs
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> CreateShortcut.vbs
echo oLink.TargetPath = "C:\Program Files (x86)\Steam\steamapps\common\Unturned\Unturned.exe" >> CreateShortcut.vbs
echo oLink.Save >> CreateShortcut.vbs
cscript CreateShortcut.vbs
del CreateShortcut.vbs
The issue is I need the target path to be, "C:\Program Files (x86)\Steam\steamapps\common\Unturned\Unturned.exe" -batchmode -nographics +secureserver/ahhh
How would I go about doing so?
To do this as a batch-file, which creates a vbscript, runs it, then deletes it, I'd suggest that you do it like this:
#( Echo Set WshShell = WScript.CreateObject("WScript.Shell"^)
Echo strDesktop = WshShell.SpecialFolders("Desktop"^)
Echo str32bitPF = WshShell.ExpandEnvironmentStrings("%%ProgramFiles(x86)%%"^)
Echo Set oFSO = CreateObject("Scripting.FileSystemObject"^)
Echo If Not (oFSO.FolderExists(strDesktop + "\Unturned Dedicated Server"^)^) Then
Echo oFSO.CreateFolder(strDesktop + "\Unturned Dedicated Server"^)
Echo End If
Echo Set oShellLink = WshShell.CreateShortcut(strDesktop + "\Unturned Dedicated Server\Unturned - Server.lnk"^)
Echo oShellLink.Arguments = "-batchmode -nographics +secureserver/ahhh"
Echo oShellLink.TargetPath = str32bitPF + "\Steam\steamapps\common\Unturned\Unturned.exe"
Echo oShellLink.WindowStyle = 1
Echo oShellLink.Hotkey = "CTRL+SHIFT+U"
Echo oShellLink.Description = "Launch Unturned"
Echo oShellLink.WorkingDirectory = strDesktop + "\Unturned Dedicated Server"
Echo oShellLink.Save) > "CreateShortcut.vbs"
#%__AppDir__%cscript.exe /NoLogo "CreateShortcut.vbs"
#Del "CreateShortcut.vbs"
However, you can also do it directly from your batch-file without writing to a file too.
<!-- :
#%__AppDir__%cscript.exe /NoLogo "%~f0?.wsf"
#GoTo :EOF
-->
<Job><Script Language="VBScript">
Set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
str32bitPF = WshShell.ExpandEnvironmentStrings("%ProgramFiles(x86)%")
Set oFSO = CreateObject("Scripting.FileSystemObject")
If Not (oFSO.FolderExists(strDesktop + "\Unturned Dedicated Server")) Then
oFSO.CreateFolder(strDesktop + "\Unturned Dedicated Server")
End If
Set oShellLink = WshShell.CreateShortcut(strDesktop + "\Unturned Dedicated Server\Unturned - Server.lnk")
oShellLink.Arguments = "-batchmode -nographics +secureserver/ahhh"
oShellLink.TargetPath = str32bitPF + "\Steam\steamapps\common\Unturned\Unturned.exe"
oShellLink.WindowStyle = 1
oShellLink.Hotkey = "CTRL+SHIFT+U"
oShellLink.Description = "Launch Unturned"
oShellLink.WorkingDirectory = strDesktop + "\Unturned Dedicated Server"
oShellLink.Save
</Script></Job>
If you wish to add your own batch-file code to this version it must be inserted just above the #GoTo :EOF line.
You should add another line where to put the arguments to be passed to your .exe target :
#echo off
Title Batch exe to shortcut
Set "VBS_Shortcut=%temp%\%~n0.vbs"
Set "ShortcutName=Unturned - Server"
Set "TargetPath=C:\Program Files (x86)\Steam\steamapps\common\Unturned\Unturned.exe"
Set "Arguments=-batchmode -nographics +secureserver/ahhh"
Call :Create_Shortcut "%ShortcutName%" "%TargetPath%" "%Arguments%"
Exit
REM ----------------------------------------------------------------------------------------------------
:Create_Shortcut
> "%VBS_Shortcut%" (
echo Call Create_Shortcut("%~1","%~2","%~3"^)
echo Sub Create_Shortcut(ShortcutName,TargetPath,Arguments^)
echo Dim objShell,DesktopPath,objShortCut
echo Set objShell = CreateObject("WScript.Shell"^)
echo DesktopPath = objShell.SpecialFolders("Desktop"^)
echo Set objShortCut = objShell.CreateShortcut(DesktopPath ^& "\" ^& ShortcutName ^& ".lnk"^)
echo objShortCut.TargetPath = chr(34^) ^& TargetPath ^& chr(34^)
echo objShortCut.Arguments = Arguments
echo objShortCut.Save
echo End Sub
)
cscript //nologo "%VBS_Shortcut%" "%~1" "%~2" "%~3"
If Exist "%VBS_Shortcut%" Del "%VBS_Shortcut%"
Exit /B
REM ----------------------------------------------------------------------------------------------------

using variables from VBScript in batch

I want to pass variables from VBScript to batch but it wouldn't work.
My VBScript:
Dim shell
Set shell = CreateObject("WScript.Shell")
strnaam = InputBox ("naam")
and my batch:
#echo off
cls
echo %strnaam%
pause
I want the variable strnaam from my VBScript to my batch.
The most obvious way would be to run the vbscript as a For /F command and save its returned output as a variable:
#Echo Off
:NaamBox
Set "naam="
(Echo WScript.Echo InputBox("Naam:"^))>"%TEMP%\naam.vbs"
For /F Delims^=^ EOL^= %%A In ('CScript //NoLogo "%TEMP%\naam.vbs"')Do Set "naam=%%A"
If Not Defined naam GoTo NaamBox
Del "%TEMP%\naam.vbs"
Echo Uw naam is %naam%
Pause
If you don't like the idea of writing, running, then deleting the file, you could also embed your VBScript within the batch file:
<!-- :
#Echo Off
Echo Typ gelieve uw naam in de popup doos en OK te selecteren
For /F Delims^=^ EOL^= %%A In ('CScript //NoLogo "%~f0?.wsf"')Do Set "naam=%%A"
If Defined naam Echo Uw naam is %naam%&Pause
Exit /B
-->
<Job><Script Language="VBScript">
WScript.Echo InputBox("Naam:")
</Script></Job>
You can pass the variables only via environment variables:
The create_variable.vbs file:
Dim WshShell, WshEnv
Set WshShell = CreateObject("WScript.Shell")
Set WshEnv = WshShell.Environment("USER") ' can be either SYSTEM, USER, VOLATILE OR PROCESS
' current value
WScript.Echo "Process: NAAM=" & WshEnv.Item("NAAM")
WshEnv("NAAM") = "This text will appear in batch"
WScript.Echo "Process: NAAM=" & WshEnv.Item("NAAM")
Set WshEnv = Nothing
Set WshShell = Nothing
Then the batch file show_vbs_variable.bat (you have to open a new cmd.exe to have the new variable there! If you need more infor here is a topic on SO that covers it.:
#echo off
cls
echo %naam%
pause
vbs script for clearing up the variable clearing_variable.vbs:
Dim WshShell, WshEnv
Set WshShell = CreateObject("WScript.Shell")
Set WshEnv = WshShell.Environment("USER") ' can be either SYSTEM, USER, VOLATILE OR PROCESS
' current value
WScript.Echo "Process: NAAM=" & WshEnv.Item("NAAM")
'Deleting the env variable
WshEnv.Remove("NAAM")
WScript.Echo "Process: NAAM=" & WshEnv.Item("NAAM")
Set WshEnv = Nothing
Set WshShell = Nothing

Read text content from docx file using batch script

I am able to read text from txt files in Windows batch script. But I can't find a way to read the data from docx files. How can I do it?
Put in same folder where are the File.docx that you want get txt:
docx2txt.cmd file.docx
or use:
Drag_and_Drop
result in a notepad txt opened with txt in file same name from .docx but in .txt
docx2txt.cmd updated
#echo off & setlocal enabledelayedexpansion
((
echo/"%~1"| findstr /lic:["\.docx\""$] >nul) && (
for /f "tokens=* delims= " %%i in ('echo/%~1') do (
set "_Docx2txt=%%~dpni.txt" && >nul copy /y "!_Docx2txt:~0,-4!.docx" "%temp%\Docx.zip")
if /i not exist "%temp%\Docx.zip" set "_Msg_Err=%~1 not valid^!" && goto :_error_:
set "_Docx_zDir_=%temp%\Docx_Zip"
set "_Docx_uZip_=%temp%\Docx.zip"
set "_replace_00=openxmlformats"
set "_replace_01=urn:schemas-microsoft-com:vml"
set "_replace_02=urn:schemas-microsoft-com:office:word"
set "_replace_03=urn:schemas-microsoft-com:office:office"
set _Run_CScript="%Windir%\System32\CScript.exe" //nologo
set _Break_line=!_Run_CScript! "%temp%\Break_line.vbs"
set _Replc_Qute=!_Run_CScript! "%temp%\Replc_Qute.vbs"
set _Replc_Dots=!_Run_CScript! "%temp%\Replc_Dots.vbs"
set _Replc_Tag1=!_Run_CScript! "%temp%\Replc_Tag1.vbs"
set _Replc_Tag2=!_Run_CScript! "%temp%\Replc_Tag2.vbs"
set _Find_Replc=!_Run_CScript! "%temp%\Find_Rep.vbs"
set _UnZip_Docx=!_Run_CScript! "%temp%\UnZip.vbs"
set _Drop_Lines=^
<nul & rem .:| This blank line is needed to do this job! So, do not remove it! |:.
) 2>nul || (
:_error_:
cls & echo/ & color F4 & set "_Arg_PS=New-Object -ComObject Wscript.Shell" & echo/
set "_Arg_Err=Valid: Some_Document.Docx" & set "_Err=E R R O R ^! Argument missing: "
if not defined _Msg_Err set _Msg_Err="%~0" [+ !_Arg_Err!]& echo/ Well, something is really wrong^^!
echo/ & powershell ^(!_Arg_PS!^).Popup^("""!_Msg_Err!""",0,"""!_Err!""",0x10^) 2>nul >nul
echo/ Use: !_Msg_Err! & timeout /t -1 2>nul >nul & color 0A & goto :eof
)) 2>nul
call :_write_vbs_files_: & type nul >"!_Docx2txt!"
(rmdir /q /s "!_Docx_zDir_!" & ping 127.1 -n 1 >nul && mkdir "!_Docx_zDir_!" || mkdir "!_Docx_zDir_!") 2>nul >nul
!_UnZip_Docx! && type nul >"!_Docx_zDir_!\Docx_Text.txt" & type nul >"!_Docx_zDir_!\Docx.tmp"
copy /y "!_Docx_zDir_!\word\document.xml" "!_Docx_zDir_!\Docx.tmp" >nul
for %%r in ("/^>^</","^<w:t xml:space^=","/^>","^</a:^","w:rPr^>","^<w:r","^</w:t^>","xmlns:","^<w:instrText", "^</w:instrText"^
) do !_Find_Replc! "!_Docx_zDir_!\Docx.tmp" %%r "!_Drop_Lines!"
for /l %%l in (0 1 3) do !_Find_Replc! "!_Docx_zDir_!\Docx.tmp" "!_replace_0%%l!" "!_Drop_Lines!"
!_Replc_Tag1! "!_Docx_zDir_!\Docx.tmp"
!_Replc_Tag2! "!_Docx_zDir_!\Docx.tmp"
!_Replc_Qute! "!_Docx_zDir_!\Docx.tmp"
!_Find_Replc! "!_Docx_zDir_!\Docx.tmp" chr^(47^)^&"schemas"^&chr^(46^)^&"microsoft"^&chr^(46^)^&"com"^&chr^(47^)^&^chr^(47^) "!_Drop_Lines!"
!_Find_Replc! "!_Docx_zDir_!\Docx.tmp" chr^(47^)^&"schemas"^&chr^(46^)^&"openxmlformats"^&chr^(46^) "!_Drop_Lines!"
!_Find_Replc! "!_Docx_zDir_!\Docx.tmp" chr^(46^)^&"org"^&^chr^(47^)^&^chr^(47^) "!_Drop_Lines!"
!_Find_Replc! "!_Docx_zDir_!\Docx.tmp" "^<w:t^>" "1#2##3#4#"
!_Find_Replc! "!_Docx_zDir_!\Docx.tmp" "^<a:t^>" "1#2##3#4#"
!_Find_Replc! "!_Docx_zDir_!\Docx.tmp" chr^(32^)^&"1#2##3#4#" "1#2##3#4#"
!_Find_Replc! "!_Docx_zDir_!\Docx.tmp" "1#2##3#4#"^&char^(32^) "1#2##3#4#"
!_Find_Replc! "!_Docx_zDir_!\Docx.tmp" "^>^<" "!_Drop_Lines!"
!_Replc_Dots! "!_Docx_zDir_!\Docx.tmp"
for %%r in (org/officeDocument,org/officeDocument/,org/,relationships,wordprocessingDrawing,http://schemas.,^
presentationml,spreadsheetDrawing,speadsheetDrawing,wordprocessingml,drawingml,wordprocessingShape^
) do !_Find_Replc! "!_Docx_zDir_!\Docx.tmp" %%r "!_Drop_Lines!"
for %%r in (chr^(60^)^&chr^(63^),chr^(63^)^&chr^(62^),chr^(9^)) do !_Find_Replc! "!_Docx_zDir_!\Docx.tmp" %%r "!_Drop_Lines!"
type "!_Docx_zDir_!\Docx.tmp"|findstr "1#2##3#4#">>"!_Docx_zDir_!\Docx_Text.txt"
!_Find_Replc! "!_Docx_zDir_!\Docx_Text.txt" "1#2##3#4#" "!_Drop_Lines!"
!_Break_line! "!_Docx_zDir_!\Docx_Text.txt"
!_Find_Replc! "!_Docx_zDir_!\Docx_Text.txt" chr^(32^)^&chr^(46^) "!_Drop_Lines!"
!_Find_Replc! "!_Docx_zDir_!\Docx_Text.txt" chr^(32^)^&chr^(32^)^&chr^(46^) "!_Drop_Lines!"
type "!_Docx_zDir_!\Docx_Text.txt"| more /e /s /p +3 | findstr /rc:"[\ ]" | findstr /vb "\ \." >>"!_Docx2txt!"
!_Find_Replc! "!_Docx_zDir_!\Docx_Text.txt" "xml"^&chr^(58^) "!_Droplines!
!_Find_Replc! "!_Docx_zDir_!\Docx_Text.txt" "space"^&chr^(61^) "!_Drop_Lines!"
start /b notepad.exe "!_Docx2txt!" && rmdir /q /s "!_Docx_zDir_!" 2>nul >nul
>nul (for %%D in (Find_Rep Replc_Tag1 Replc_Tag2 Replc_Qute Replc_Dots Break_Line UnZip) do del /q /f "%temp%\%%D.vbs"
del /q /f "%temp%\docx.zip") & goto :_end_of_file_:
:_write_vbs_files_:
>"%temp%\Find_Rep.vbs"^
(
echo/ Const ForReading = 1
echo/ Const ForWriting = 2
echo/ strFileName = WScript.Arguments^(0^)
echo/ strOldText = WScript.Arguments^(1^)
echo/ strNewText = WScript.Arguments^(2^)
echo/ Set objFSO = CreateObject^("Scripting.FileSystemObject"^)
echo/ Set objFile = objFSO.OpenTextFile^(strFileName, ForReading,ForReading^)
echo/ strText = objFile.ReadAll
echo/ strNewText = Replace^(strText, strOldText, strNewText^)
echo/ Set objFile = objFSO.OpenTextFile^(strFileName, ForWriting^)
echo/ objFile.Write strNewText 'WriteLine adds extra CR/LF
echo/ objFile.Close
)
>"%temp%\Replc_Tag1.vbs"^
(
echo/ Const ForReading = 1
echo/ Const ForWriting = 2
echo/ strFileName = Wscript.Arguments^(0^)
echo/ strOldText = ^(chr^(60^)^&chr^(87^)^&chr^(58^)^&chr^(84^)^&chr^(62^)^)
echo/ strNewText = ^(vbCr^&vbLf^&chr^(34^)^&preserv^&chr^(34^)^&chr^(62^)^)
echo/ Set objFSO = CreateObject^("Scripting.FileSystemObject"^)
echo/ Set objFile = objFSO.OpenTextFile^(strFileName, ForReading,ForReading^)
echo/ strText = objFile.ReadAll
echo/ objFile.Close
echo/ strNewText = Replace^(strText, strOldText, strNewText^)
echo/ Set objFile = objFSO.OpenTextFile^(strFileName, ForWriting^)
echo/ objFile.Write strNewText 'WriteLine adds extra CR/LF
echo/ objFile.Close
)
>"%temp%\Replc_Tag2.vbs"^
(
echo/ Const ForReading = 1
echo/ Const ForWriting = 2
echo/ strFileName = Wscript.Arguments^(0^)
echo/ strOldText = ^(chr^(34^)^&"preserve"^&chr^(34^)^&chr^(62^)^)
echo/ strNewText = ^("1"^&chr^(35^)^&"2"^&chr^(35^)^&chr^(64^)^&"3"^&chr^(35^)^&"4"^&chr^(35^)^)
echo/ Set objFSO = CreateObject^("Scripting.FileSystemObject"^)
echo/ Set objFile = objFSO.OpenTextFile^(strFileName, ForReading,ForReading^)
echo/ strText = objFile.ReadAll
echo/ objFile.Close
echo/ strNewText = Replace^(strText, strOldText, strNewText^)
echo/ Set objFile = objFSO.OpenTextFile^(strFileName, ForWriting^)
echo/ objFile.Write strNewText 'WriteLine adds extra CR/LF
echo/ objFile.Close
)
>"%temp%\Replc_Qute.vbs"^
(
echo/ Const ForReading = 1
echo/ Const ForWriting = 2
echo/ strFileName = Wscript.Arguments^(0^)
echo/ strOldText = ^(chr^(34^)^&"preserve"^&chr^(34^)^&chr^(62^)^)
echo/ strNewText = ^("1"^&chr^(35^)^&"2"^&chr^(35^)^&chr^(64^)^&"3"^&chr^(35^)^&"4"^&chr^(35^)^)
echo/ Set objFSO = CreateObject^("Scripting.FileSystemObject"^)
echo/ Set objFile = objFSO.OpenTextFile^(strFileName, ForReading,ForReading^)
echo/ strText = objFile.ReadAll
echo/ objFile.Close
echo/ strNewText = Replace^(strText, strOldText, strNewText^)
echo/ Set objFile = objFSO.OpenTextFile^(strFileName, ForWriting^)
echo/ objFile.Write strNewText 'WriteLine adds extra CR/LF
echo/ objFile.Close
)
>"%temp%\Replc_Dots.vbs"^
(
echo/ Const ForReading = 1
echo/ Const ForWriting = 2
echo/ strFileName = Wscript.Arguments^(0^)
echo/ strOldText = ^(chr^(46^)^&^chr^(0^)^)
echo/ strNewText = ^(chr^(46^)^&chr^(13^)^&"1"^&chr^(35^)^&"2"^&chr^(35^)^&chr^(64^)^&"3"^&chr^(35^)^&"4"^&chr^(35^)^)
echo/ Set objFSO = CreateObject^("Scripting.FileSystemObject"^)
echo/ Set objFile = objFSO.OpenTextFile^(strFileName, ForReading,ForReading^)
echo/ strText = objFile.ReadAll
echo/ objFile.Close
echo/ strNewText = Replace^(strText, strOldText, strNewText^)
echo/ Set objFile = objFSO.OpenTextFile^(strFileName, ForWriting^)
echo/ objFile.Write strNewText 'WriteLine adds extra CR/LF
echo/ objFile.Close
)
>"%temp%\Break_Line.vbs"^
(
echo/ Const ForReading = 1
echo/ Const ForWriting = 2
echo/ strFileName = Wscript.Arguments^(0^)
echo/ strOldText = ^(chr^(46^)^)
echo/ strNewText = ^(chr^(46^)^&vbCr^&vbLf^)
echo/ Set objFSO = CreateObject^("Scripting.FileSystemObject"^)
echo/ Set objFile = objFSO.OpenTextFile^(strFileName, ForReading,ForReading^)
echo/ strText = objFile.ReadAll
echo/ objFile.Close
echo/ strNewText = Replace^(strText, strOldText, strNewText^)
echo/ Set objFile = objFSO.OpenTextFile^(strFileName, ForWriting^)
echo/ objFile.Write strNewText 'WriteLine adds extra CR/LF
echo/ objFile.Close
)
>"%temp%\UnZip.vbs"^
(
echo/ ZipFile="!_Docx_uZip_!"
echo/ ExtractTo="!_Docx_zDir_!\"
echo/ set objShell = CreateObject^("Shell.Application"^)
echo/ set FilesInZip=objShell.NameSpace^(ZipFile^).items
echo/ Set fso = CreateObject^("Scripting.FileSystemObject"^)
echo/ objShell.NameSpace^(ExtractTo^).CopyHere^(FilesInZip^)
echo/ Set fso = Nothing
echo/ Set objShell = Nothing
)
exit /b
:_end_of_file_:

Batch commands and VB script commands in one file

I have created one batch file through which I am trying to create one .vbs file and place some command into that. But I am not able to transfer my all the command to the .vbs file.
#echo off
echo:
set /a i=1
:Loop
if %i% GTR 0 (
rem create temp vbs file
echo Dim IPAddress > temp.vbs
echo IPAddress="192.168.1.109" >> temp.vbs
echo SET WshShell = WScript.CreateObject("WScript.Shell"^) >> temp.vbs
echo WshShell.run("telnet.exe " &IPAddress) >> temp.vbs
echo WScript.Sleep 3000 >> temp.vbs
echo WshShell.SendKeys"qwert" >> temp.vbs
echo WshShell.SendKeys("{Enter}") >> temp.vbs
echo WScript.Sleep 3000 >> temp.vbs
echo WshShell.SendKeys"asdf123" >> temp.vbs
echo WshShell.SendKeys("{Enter}") >> temp.vbs
echo WScript.Sleep 1000 >> temp.vbs
echo ' Reboot Device >> temp.vbs
echo ' WshShell.SendKeys"reboot" >> temp.vbs
echo ' WshShell.SendKeys("{Enter}") >> temp.vbs
echo ' WScript.Sleep 1000 >> temp.vbs
echo strPath = WshShell.CurrentDirectory >> temp.vbs
echo ' Close telnet session >> temp.vbs
echo WshShell.Run "taskkill /im telnet.exe", , True >> temp.vbs
rem wscript C:\Users\guest\Desktop\temp.vbs
echo Reboot Count %i%
echo:
set /a i+=1
Timeout /t 90 >nul
GOTO Loop
) ELSE (
echo Out of if loop
)
Following is the Actual output of the temp.vbs file
WshShell.run("telnet.exe "
WScript.Sleep 3000
WshShell.SendKeys"qwert"
WshShell.SendKeys("{Enter}")
WScript.Sleep 3000
WshShell.SendKeys"asdf123"
WshShell.SendKeys("{Enter}")
WScript.Sleep 1000
' Reboot Device
' WshShell.SendKeys"reboot"
' WshShell.SendKeys("{Enter}")
' WScript.Sleep 1000
strPath = WshShell.CurrentDirectory
' Close telnet session
WshShell.Run "taskkill /im telnet.exe", , True
Expected output of temp.vbs file
Dim IPAddress
IPAddress="192.168.1.109"
SET WshShell = WScript.CreateObject("WScript.Shell"^)
WshShell.run("telnet.exe " &IPAddress)
WScript.Sleep 3000
WshShell.SendKeys"qwert"
WshShell.SendKeys("{Enter}")
WScript.Sleep 3000
WshShell.SendKeys"asdf123"
WshShell.SendKeys("{Enter}")
WScript.Sleep 1000
' Reboot Device
' WshShell.SendKeys"reboot"
' WshShell.SendKeys("{Enter}")
' WScript.Sleep 1000
strPath = WshShell.CurrentDirectory
' Close telnet session
WshShell.Run "taskkill /im telnet.exe", , True
Kindly help me on this to achieve this scenario.
Thank your very much in advance.
You can create a .vbs script with commands you walt to run in the same folder and hidden it. Next you can run it from batch file.

Sorting files by numerical order

I have a batch that create shortcut based on the order of files, the problem is that when it comes to numbers he presents the following problem when passing the number 100.
01.mp4
02.mp4
03.rmvb
04.mp4
05.rmvb
06.rmvb
07.rmvb
08.rmvb
09.rmvb
10.rmvb
100.mp4
101.mp4
102.mp4
103.mp4
104.mp4
105.mp4
106.mp4
107.mp4
108.mp4
109.mp4
11.rmvb
I searched here and found various methods however the script I use works with folders and files that sometimes use accents, & and/or !
Example: C:\Séries & Movies\Remix!.mkv (Brazil and use E place of and).
I wonder if there is any way to check the content and organize it can be properly before you save it in .ini or after saving the same in .ini.
Observations:
The folder path is loaded the first time the Set command.
After entering the path he saved in an .ini file and always loaded.
The Script list only files within the directory does not list subfolders and files and folders within it.
The script needs other files to work the download link is below:
https://www.mediafire.com/?zcoybkfo8k4nm1t
My Full Code:
#Echo off
Title Create shortcuts in alphabetical order
mode con:lines=3 cols=25
Color 1f
CD /D "%~dp0"
If Exist "Files\command.ini" For /f "usebackq delims=" %%x in ("Files\command.ini") do (set "%%x")
If Exist "Files\Config.ini" For /f "usebackq delims=" %%x in ("Files\Config.ini") do (set "%%x")
If Exist "Files\Files.ini" Goto shortcuts
If Exist "Files\command.ini" Goto shortcuts
If Exist "Files\Config.ini" Goto shortcuts
for %%F in (""%1"") do Set "location-of-files=%%~F"
for %%F in ("%location-of-files%") do IF "%%~F" NEQ """" Set "location-of-files=%location-of-files:"=%" & Set Number=1 & Goto LocationofFiles2
:LocationofFiles
mode con:lines=18 cols=78
Set "location-of-files=r1u4unoiwqa6">nul 2>&1
cls
echo Location of Files
Set /p location-of-files="¯ Location of Files: "
Set "location-of-files=%location-of-files:"=%"
Set Number=1
IF "%location-of-files%"=="r1u4unoiwqa6" Goto LocationofFiles
:LocationofFiles2
mode con:lines=18 cols=78
Set "Menu=">nul 2>&1
cls
for %%F in ("%location-of-files%") do Echo %%~F
echo 1(Yes) 2(No)
Set/p Menu="¯ Menu: "
IF "%Menu%"=="1" Goto Iniciar
IF "%Menu%"=="2" Goto LocationofFiles
Goto LocationofFiles2
:Iniciar
if not exist "%location-of-files%" Cls & Start /Wait Files\Error.vbs & Goto LocationofFiles
:Name-AnimeSerie1
Set "Serie_Anime=">nul 2>&1
cls
echo Name Serie
Set /p Serie_Anime="¯ Name: "
IF "%Serie_Anime%"=="" Goto Name-AnimeSerie1
:Name-AnimeSerie2
Set "Menu=">nul 2>&1
cls
for %%F in ("%Serie_Anime%") do Echo %%~F
echo 1(Yes) 2(No)
Set/p Menu="¯ Menu: "
IF "%Menu%"=="1" Goto shortcuts
IF "%Menu%"=="2" Goto Name-AnimeSerie1
Goto Name-AnimeSerie2
:shortcuts
If Exist "Files\Config.ini" For /f "usebackq delims=" %%x in ("Files\Config.ini") do (set "%%x")
If Not Exist "%location-of-files%" Del /q "C:\Users\%username%\Desktop\%ep2% - %Serie_Anime%.lnk">nul 2>&1 & Start /Min /Wait Files\DesktopRefresh.exe>nul 2>&1 & Goto end
Dir /a-d /b "%location-of-files%" >Files\Files.ini
Echo r1u4unoiwqa6.ending >>Files\Files.ini
Start "exclamation01" /Min /Wait "Files\exclamation01.vbs">nul 2>&1
Set location-of-files > Files\Config.ini
Set Serie_Anime >> Files\Config.ini
Set Number > Files\command.ini
If Exist "C:\Users\%username%\Desktop\%ep2% - %Serie_Anime%.lnk" Del /q "C:\Users\%username%\Desktop\%ep2% - %Serie_Anime%.lnk">nul 2>&1 & Start /Min /Wait Files\DesktopRefresh.exe>nul 2>&1
setlocal EnableDelayedExpansion
For /f "usebackq delims=" %%x in ("Files\command.ini") do (set "%%x")
For /f "usebackq delims=" %%x in ("Files\Config.ini") do (set "%%x")
set "cmd=findstr /R /N "^^" Files\Files.ini | find /C ":""
for /f %%a in ('!cmd!') do set Numbers=%%a
set lines=%Number%
set Atual=1
for /f "delims=" %%a in ('type Files\Files.ini') do (
for %%b in (!lines!) do (
if !Atual!==%%b Set "Ep1=%%a"
)
set /a "Atual = Atual + 1"
)
Set "Ep2=%Ep1%"
set "find=*."
call set delete=%%Ep2:!find!=%%
call set Ep2=%%Ep2:!delete!=%%
Set Ep2=%Ep2:.=%
Set Ep1 > Files\command.ini
Set Ep2 >> Files\command.ini
Set lines >> Files\command.ini
Set Number >> Files\command.ini
endlocal
Start "exclamation02" /Min /Wait "Files\exclamation02.vbs">nul 2>&1
For /f "usebackq delims=" %%x in ("Files\command.ini") do (set "%%x")
For /f "usebackq delims=" %%x in ("Files\Config.ini") do (set "%%x")
IF "%Ep2%"=="r1u4unoiwqa6" Goto end
Start /Min /Wait Files\Shortcut.exe /F:"C:\Users\%username%\Desktop\%ep2% - %Serie_Anime%.lnk" /A:C /t:"%location-of-files%\%Ep1%" /D:"Episode %Serie_Anime%">nul 2>&1
If Not Exist "C:\Users\%username%\Desktop\[ shortcuts ].lnk" Echo %Serie_Anime%>Files\shortcut.ini & Start /Min /Wait Files\shortcut.vbs>nul 2>&1
Set /A Number = %lines% + 1
:::::::::::::::::::::::::::::::::::::::::::::
Set location-of-files > Files\Config.ini
Set Serie_Anime >> Files\Config.ini
:::::::::::::::::::::::::::::::::::::::::::::
Set Ep1 > Files\command.ini
Set Ep2 >> Files\command.ini
Set Number >> Files\command.ini
:::::::::::::::::::::::::::::::::::::::::::::
Exit
:end
If Not Exist "%location-of-files%" Start /Wait Files\PDoM.vbs>nul 2>&1
If Exist "%location-of-files%" Start /Wait Files\ending.vbs>nul 2>&1
If Exist "%location-of-files%" Start "Anime" "%location-of-files%">nul 2>&1
Del /q "Files\Files.ini">nul 2>&1
Del /q "Files\shortcut.ini">nul 2>&1
Del /q "Files\command.ini">nul 2>&1
Del /q "Files\Config.ini">nul 2>&1
Set "location-of-files=">nul 2>&1
Set "Serie_Anime=">nul 2>&1
Set "lines=">nul 2>&1
Set "Ep1=">nul 2>&1
Set "Ep2=">nul 2>&1
Goto LocationofFiles
Part where you need to use the DIR:
:shortcuts
If Exist "Files\Config.ini" For /f "usebackq delims=" %%x in ("Files\Config.ini") do (set "%%x")
If Not Exist "%location-of-files%" Del /q "C:\Users\%username%\Desktop\%ep2% - %Serie_Anime%.lnk">nul 2>&1 & Start /Min /Wait Files\DesktopRefresh.exe>nul 2>&1 & Goto end
Dir /a-d /b "%location-of-files%" >Files\Files.ini
Echo r1u4unoiwqa6.ending >>Files\Files.ini
Start "exclamation01" /Min /Wait "Files\exclamation01.vbs">nul 2>&1
Set location-of-files > Files\Config.ini
Set Serie_Anime >> Files\Config.ini
Set Number > Files\command.ini
If Exist "C:\Users\%username%\Desktop\%ep2% - %Serie_Anime%.lnk" Del /q "C:\Users\%username%\Desktop\%ep2% - %Serie_Anime%.lnk">nul 2>&1 & Start /Min /Wait Files\DesktopRefresh.exe>nul 2>&1
setlocal EnableDelayedExpansion
For /f "usebackq delims=" %%x in ("Files\command.ini") do (set "%%x")
For /f "usebackq delims=" %%x in ("Files\Config.ini") do (set "%%x")
set "cmd=findstr /R /N "^^" Files\Files.ini | find /C ":""
for /f %%a in ('!cmd!') do set Numbers=%%a
set lines=%Number%
set Atual=1
for /f "delims=" %%a in ('type Files\Files.ini') do (
for %%b in (!lines!) do (
if !Atual!==%%b Set "Ep1=%%a"
)
set /a "Atual = Atual + 1"
)
Set "Ep2=%Ep1%"
set "find=*."
call set delete=%%Ep2:!find!=%%
call set Ep2=%%Ep2:!delete!=%%
Set Ep2=%Ep2:.=%
Set Ep1 > Files\command.ini
Set Ep2 >> Files\command.ini
Set lines >> Files\command.ini
Set Number >> Files\command.ini
endlocal
Thanks in advance.
Set Arg = WScript.Arguments
set WshShell = createObject("Wscript.Shell")
Set Inp = WScript.Stdin
Set Outp = Wscript.Stdout
Set rs = CreateObject("ADODB.Recordset")
If LCase(Arg(1)) = "n" then
With rs
.Fields.Append "SortKey", 4
.Fields.Append "Txt", 201, 5000
.Open
Do Until Inp.AtEndOfStream
Lne = Inp.readline
SortKey = Mid(Lne, LCase(Arg(3)), LCase(Arg(4)) - LCase(Arg(3)))
If IsNumeric(Sortkey) = False then
Set RE = new Regexp
re.Pattern = "[^0-9\.,]"
re.global = true
re.ignorecase = true
Sortkey = re.replace(Sortkey, "")
End If
If IsNumeric(Sortkey) = False then
Sortkey = 0
ElseIf Sortkey = "" then
Sortkey = 0
ElseIf IsNull(Sortkey) = true then
Sortkey = 0
End If
.AddNew
.Fields("SortKey").value = CSng(SortKey)
.Fields("Txt").value = Lne
.UpDate
Loop
If LCase(Arg(2)) = "a" then SortColumn = "SortKey ASC"
If LCase(Arg(2)) = "d" then SortColumn = "SortKey DESC"
.Sort = SortColumn
Do While not .EOF
Outp.writeline .Fields("Txt").Value
.MoveNext
Loop
End With
ElseIf LCase(Arg(1)) = "d" then
With rs
.Fields.Append "SortKey", 4
.Fields.Append "Txt", 201, 5000
.Open
Do Until Inp.AtEndOfStream
Lne = Inp.readline
SortKey = Mid(Lne, LCase(Arg(3)), LCase(Arg(4)) - LCase(Arg(3)))
If IsDate(Sortkey) = False then
Set RE = new Regexp
re.Pattern = "[^0-9\\\-:]"
re.global = true
re.ignorecase = true
Sortkey = re.replace(Sortkey, "")
End If
If IsDate(Sortkey) = False then
Sortkey = 0
ElseIf Sortkey = "" then
Sortkey = 0
ElseIf IsNull(Sortkey) = true then
Sortkey = 0
End If
.AddNew
.Fields("SortKey").value = CDate(SortKey)
.Fields("Txt").value = Lne
.UpDate
Loop
If LCase(Arg(2)) = "a" then SortColumn = "SortKey ASC"
If LCase(Arg(2)) = "d" then SortColumn = "SortKey DESC"
.Sort = SortColumn
Do While not .EOF
Outp.writeline .Fields("Txt").Value
.MoveNext
Loop
End With
ElseIf LCase(Arg(1)) = "t" then
With rs
.Fields.Append "SortKey", 201, 260
.Fields.Append "Txt", 201, 5000
.Open
Do Until Inp.AtEndOfStream
Lne = Inp.readline
SortKey = Mid(Lne, LCase(Arg(3)), LCase(Arg(4)) - LCase(Arg(3)))
.AddNew
.Fields("SortKey").value = SortKey
.Fields("Txt").value = Lne
.UpDate
Loop
If LCase(Arg(2)) = "a" then SortColumn = "SortKey ASC"
If LCase(Arg(2)) = "d" then SortColumn = "SortKey DESC"
.Sort = SortColumn
Do While not .EOF
Outp.writeline .Fields("Txt").Value
.MoveNext
Loop
End With
ElseIf LCase(Arg(1)) = "tt" then
With rs
.Fields.Append "SortKey", 201, 260
.Fields.Append "Txt", 201, 5000
.Open
Do Until Inp.AtEndOfStream
Lne = Inp.readline
SortKey = Trim(Mid(Lne, LCase(Arg(3)), LCase(Arg(4)) - LCase(Arg(3))))
.AddNew
.Fields("SortKey").value = SortKey
.Fields("Txt").value = Lne
.UpDate
Loop
If LCase(Arg(2)) = "a" then SortColumn = "SortKey ASC"
If LCase(Arg(2)) = "d" then SortColumn = "SortKey DESC"
.Sort = SortColumn
Do While not .EOF
Outp.writeline .Fields("Txt").Value
.MoveNext
Loop
End With
End If
To use
cscript //nologo script.vbs sort {n|d|t|tt} {a|d} startcolumn endcolumn < input.txt > output.txt
Options
n - extracts a number from the columns specified. Looks for the first number.
d - extracts a time or date from the columns specified. Looks for the first date.
t - extracts a text string including spaces from the columns specified.
tt - extracts a text string discarding leading and trailing spaces from the columns specified.
a - sorts acending
d - sorts decending
startcolumn - the starting column, the first character is column 1
endcolumn - the ending column
This is what command line synax means
The following table describes the notation used to indicate command-line syntax.
Notation Description
Text without brackets or braces
Items you must type as shown
<Text inside angle brackets>
Placeholder for which you must supply a value
[Text inside square brackets]
Optional items
{Text inside braces}
Set of required items; choose one
Vertical bar (|)
Separator for mutually exclusive items; choose one
Ellipsis (…)
Items that can be repeated
After much searching, I found the hybrid JScript/batch utility called REPL.BAT the dbenham and got what I wanted, based on my code the script is:
Del /q "Files\Files.ini">nul 2>&1
for /f "tokens=2 delims=:" %%F in (
'dir /b /a-d "%location-of-files%\*.*"^|Files\repl "^(\w+).*" "00000$1:$&" a^|Files\repl ".*(\d{5}:)" "$1"^|sort'
) do echo %%F >> Files\Files.ini

Resources